Small change to sitemap

20 views
Skip to first unread message

Diego Medina

unread,
Nov 10, 2012, 11:20:06 PM11/10/12
to dbsc...@googlegroups.com
Hi,

Something I started doing a few months ago is to declare Sitemaps a
bit different than what you normally see.

For example, now we have:

def sitemap = SiteMap(
Menu.i("Home" ) / "index",
Menu.i("Log In" ) / "logIn" >> notLoggedIn,
Menu.i("Students" ) / "students" >> loggedIn,
Menu.i("Instruments") / "instruments" / "list" >> loggedIn,
Menu.i("New Instrument") / "instruments" / "create" >>
loggedIn >> Hidden,
Menu.i("Edit Instrument") / "instruments" / "edit" >>
loggedIn >> Hidden,
Menu.i("View Instrument") / "instruments" / "view" >>
loggedIn >> Hidden,
Menu.i("Delete Instrument") / "instruments" / "delete" >>
loggedIn >> Hidden,
Menu.i("No Groups" ) / "noGroups" >> loggedIn,
Menu.i("Details" ) / "studentDetails" >> loggedIn >> Hidden,
Menu.i("Problems" ) / "problems" >> loggedIn,
Menu.i("Statistics") / "stats" >> loggedIn,
Menu.i("Log Out" ) / "logOut" >> loggedIn
)



and if you want to link to the list pagem you hardcode the text path
in your code (this is taken from Carlos fork).

The one issue I have run to in the past is that if you decide to
change the path, let's say for instruments/edit to some other path,
you will have to do a search/replace on several places.

One alternative is to have all sitemap information in a separate
object, something like:

object Paths {
val home = Menu.i("home") / "index"
...
val newInstruments = Menu.i("new.instruments") / "instruments" / "create"

def sitemap = SiteMap(
home,
newInstrument >> loggedIn >> Hidden ,
...
)
}


and then, if you want to add a link to the create page, you can do
this from any snippet:

SHtml.link(Paths.newInstrument.loc.calcDefaultHref, ...)

I find this way a lot easier to maintain.

P.S. I got this tip from Tim Nelson

Regards,

Diego


--
Diego Medina
Lift/Scala Developer
di...@fmpwizard.com
http://www.fmpwizard.com

carlos.montemuino

unread,
Nov 11, 2012, 4:37:14 AM11/11/12
to dbsc...@googlegroups.com
Exactly that's one think I'm going to do before a final commit.
I don't like the way SiteMap is constructed. Indeed, I don't like hardcode URLs here and there.
This reminds me of "handler mappings" when doing MVC with JSP 10 years ago!!

Put the sitemap info in an Object is definitively a better approach.

Thanks again Diego!

Best,
Carlos.

Diego Medina

unread,
Nov 11, 2012, 7:22:33 AM11/11/12
to carlos.montemuino, dbsc...@googlegroups.com

I'm glad you like the idea.

Diego
Sent from my android cell

--
 
 

Peter Petersson

unread,
Nov 11, 2012, 7:24:41 AM11/11/12
to dbsc...@googlegroups.com
^^ should of cores be "The Diego gangnam style" :)

On 11/11/2012 01:22 PM, Peter Petersson wrote:
> In my FlexMenyLab proj where I am evaluating and testing out some
> bootstrap menu stuff using the FlexMenu trait (stuff that eventually
> will make it in to the FoBo API) I have adopted this style and named
> it "The Diego gngnam style" ;)
>
> I have the following comment in the code
>
> //we are going to build the menu "The Diego gngnam style" and use a
> Paths object
> object Paths {
> :

Peter Petersson

unread,
Nov 11, 2012, 7:22:10 AM11/11/12
to dbsc...@googlegroups.com
In my FlexMenyLab proj where I am evaluating and testing out some
bootstrap menu stuff using the FlexMenu trait (stuff that eventually
will make it in to the FoBo API) I have adopted this style and named it
"The Diego gngnam style" ;)

I have the following comment in the code

//we are going to build the menu "The Diego gngnam style" and use a
Paths object
object Paths {
:

On 11/11/2012 05:20 AM, Diego Medina wrote:

Diego Medina

unread,
Nov 11, 2012, 10:32:14 AM11/11/12
to Peter Petersson, dbsc...@googlegroups.com

I'm famous!!

Diego
Sent from my android cell

--


Dave Briccetti

unread,
Nov 11, 2012, 11:04:12 AM11/11/12
to dbsc...@googlegroups.com
I have hard-coded several paths in the work for my current major client (and of course felt miserable about it). But no more!

Dave Briccetti

unread,
Nov 13, 2012, 7:31:59 PM11/13/12
to dbsc...@googlegroups.com
Ray Muller and I just implemented this. Thanks Diego and Tim.

carlos.montemuino

unread,
Nov 13, 2012, 8:02:52 PM11/13/12
to dbsc...@googlegroups.com
I was doing the same but while defining all paths like:

  val instruments       = Menu.i("Instruments")       / "instruments" / "list"
  val createInstrument  = Menu.i("Create Instrument") / "instruments" / "create"
and so on... well, writing so much Menu.i("something"), and the / "here" / "there" started to bother me a bit. This solution is better by far, but (IMHO) it's sub-optimal (in terms of readiness and maintainability) as long as we add more and more URLs.

Therefore I created a class to encapsulate all such boilerplate Menu.i and to write URLs in a more readable (and copy/paste "friendly") way: "instruments/list", "instruments/create", etc.
This resulted in something like: 

class Path (name: String, path: String)
which gives us the "menu" and "href" values.

Then we have an object ApplicationPath to have all paths at hand. For instance:

lazy val instrumentsList = new Path("instruments", "instruments/list")
Now we could create the sitemap as:

  def sitemap = SiteMap(
       ApplicationPaths.instrumentsList.menu)
Do you think it makes sense? or just we can do it as initially suggested by Diego (https://fmpwizard.telegr.am/blog/lift_sitemap)

Best,
Carlos.

carlos.montemuino

unread,
Nov 13, 2012, 8:15:42 PM11/13/12
to dbsc...@googlegroups.com
I forgot to address the changes in one of my branches: https://github.com/cmontemuino/dbschools/commit/6fa9862bf965ef76b571e1290b6e95d7eae75eef

Dave Briccetti

unread,
Nov 13, 2012, 8:25:46 PM11/13/12
to dbsc...@googlegroups.com
Funny that I didn’t notice the noise of the repeated “Menu.i” myself. Now that you mention it I agree. I like your plan.

Reply all
Reply to author
Forward
0 new messages