diff --git a/chap-sitemap.lyx b/chap-sitemap.lyx index c395923..790ca6e 100644 --- a/chap-sitemap.lyx +++ b/chap-sitemap.lyx @@ -144,45 +144,55 @@ A help page \begin_layout Standard We'll assume that we have the corresponding pages, -\begin_inset Quotes eld -\end_inset +" + +\family typewriter homepage -\begin_inset Quotes erd -\end_inset +\family default + +" , -\begin_inset Quotes eld -\end_inset +" + +\family typewriter login -\begin_inset Quotes erd -\end_inset +\family default + +" , -\begin_inset Quotes eld -\end_inset +" + +\family typewriter logout -\begin_inset Quotes erd -\end_inset +\family default + +" , and -\begin_inset Quotes eld -\end_inset +" + +\family typewriter profile -\begin_inset Quotes erd -\end_inset +\family default + +" written and functional. We'll also assume that the help page(s) reside under the -\begin_inset Quotes eld -\end_inset +" + +\family typewriter help -\begin_inset Quotes erd -\end_inset +\family default + +" subdirectory to keep things neat, and that the entry to help is \family typewriter @@ -216,16 +226,22 @@ net.liftweb.sitemap.Loc.Link \end_inset is a fundamental part of Menu definitions. - The Link class contains two parameters: a List[String] of path components, - and a boolean value that controls whether prefix matching is enabled. + The +\family typewriter +Link +\family default +class contains two parameters: a +\family typewriter +List[String] +\family default + of path components, and a boolean value that controls whether prefix matching + is enabled. The path components represent the portion of the URI following your web context, split on the -\begin_inset Quotes eld -\end_inset +" / -\begin_inset Quotes erd -\end_inset +" character. Listing @@ -236,12 +252,10 @@ reference "lst:Link-Path-Components" \end_inset shows how you would use Link to represent the -\begin_inset Quotes eld -\end_inset +" /utils/index -\begin_inset Quotes erd -\end_inset +" page. @@ -274,23 +288,7 @@ name "lst:Link-Path-Components" \begin_layout Plain Layout -val myUtilsIndex = new Link( -\begin_inset Quotes eld -\end_inset - -utils -\begin_inset Quotes erd -\end_inset - - :: -\begin_inset Quotes eld -\end_inset - -index -\begin_inset Quotes erd -\end_inset - - :: Nil, false) +val myUtilsIndex = new Link("utils" :: "index" :: Nil, false) \end_layout \end_inset @@ -344,15 +342,7 @@ name "lst:Link-Prefix-Matching" \begin_layout Plain Layout -val allUtilPages = new Link( -\begin_inset Quotes eld -\end_inset - -utils -\begin_inset Quotes erd -\end_inset - - :: Nil, true) +val allUtilPages = new Link("utils" :: Nil, true) \end_layout \end_inset @@ -419,41 +409,17 @@ name "lst:Using-ExtLink" \begin_layout Plain Layout -val goodReference = Menu(Loc( -\begin_inset Quotes eld -\end_inset - -reference -\begin_inset Quotes erd -\end_inset - -, +val goodReference = Menu(Loc("reference", \end_layout \begin_layout Plain Layout - ExtLink( -\begin_inset Quotes eld -\end_inset - -http://www.liftweb.net/ -\begin_inset Quotes erd -\end_inset - -), + ExtLink("http://www.liftweb.net/"), \end_layout \begin_layout Plain Layout - -\begin_inset Quotes eld -\end_inset - -LiftWeb -\begin_inset Quotes erd -\end_inset - -)) + "LiftWeb")) \end_layout \end_inset @@ -644,15 +610,7 @@ val helpMenu = Menu(Loc("helpHome", \begin_layout Plain Layout - ("help" :: -\begin_inset Quotes eld -\end_inset - - -\begin_inset Quotes erd -\end_inset - - :: Nil) -> true, + ("help" :: "" :: Nil) -> true, \end_layout \begin_layout Plain Layout @@ -667,16 +625,17 @@ val helpMenu = Menu(Loc("helpHome", \begin_layout Standard For our example we've named this menu item -\begin_inset Quotes eld -\end_inset +" helpHome -\begin_inset Quotes erd -\end_inset +" . - The second parameter is a Pair[List[String],Boolean] which converts directly - to a Link class with the given parameters. + The second parameter is a +\family typewriter +Pair[List[String],Boolean] +\family default + which converts directly to a Link class with the given parameters. In our case, by passing in true, we're saying that anything under the help directory will also match. If you just use a List[String], the implicit conversion is to a Link with @@ -695,12 +654,10 @@ emphasize , so by doing this we're allowing full access to all of the help files without having to specify a menu entry for each. The final parameter, -\begin_inset Quotes eld -\end_inset +" Help -\begin_inset Quotes erd -\end_inset +" , is the text for the menu link. @@ -721,12 +678,10 @@ name "sub:Nested-Menus" The Menu class supports child menus simply by passing them in as final construct or parameters. For instance, if we wanted to have an -\begin_inset Quotes eld -\end_inset +" about -\begin_inset Quotes erd -\end_inset +" menu under Help, we could define the menu as shown in listing \begin_inset CommandInset ref @@ -765,39 +720,7 @@ name "lst:Nested-Menu-Definition" \begin_layout Plain Layout -val aboutMenu = Menu(Loc( -\begin_inset Quotes eld -\end_inset - -about -\begin_inset Quotes erd -\end_inset - -, -\begin_inset Quotes eld -\end_inset - -help -\begin_inset Quotes erd -\end_inset - - :: -\begin_inset Quotes eld -\end_inset - -about -\begin_inset Quotes erd -\end_inset - - :: Nil, -\begin_inset Quotes eld -\end_inset - -About -\begin_inset Quotes erd -\end_inset - -)) +val aboutMenu = Menu(Loc("about", "help" :: "about" :: Nil, "About")) \end_layout \begin_layout Plain Layout @@ -815,21 +738,23 @@ When the menu is rendered it will have a child menu for About. Child menus are only rendered by default when the current page matches their parent's Loc. That means that, for instance the following links would show an -\begin_inset Quotes eld -\end_inset +" About -\begin_inset Quotes erd -\end_inset +" child menu item: \end_layout \begin_layout Itemize + +\family typewriter /help/index \end_layout \begin_layout Itemize + +\family typewriter /help/usage \end_layout @@ -838,10 +763,14 @@ But the following would not: \end_layout \begin_layout Itemize + +\family typewriter /index \end_layout \begin_layout Itemize + +\family typewriter /site/example \end_layout @@ -944,31 +873,7 @@ Using List[Menu] for SiteMap \begin_layout Plain Layout -val menus = Menu(Loc( -\begin_inset Quotes eld -\end_inset - -HomePage -\begin_inset Quotes erd -\end_inset - -, -\begin_inset Quotes eld -\end_inset - - -\begin_inset Quotes erd -\end_inset - -, -\begin_inset Quotes eld -\end_inset - -Home -\begin_inset Quotes erd -\end_inset - -),...) :: +val menus = Menu(Loc("HomePage", "", "Home"),...) :: \end_layout \begin_layout Plain Layout @@ -994,12 +899,10 @@ LiftRules.setSiteMap(SiteMap(menus : _*)) \begin_layout Standard The key to using List for your menus is to explicitly define the type of the parameter as -\begin_inset Quotes eld -\end_inset +" _* -\begin_inset Quotes erd -\end_inset +" so that it's treated as a set of varargs instead of a single argument of type List[Menu]. @@ -1090,41 +993,17 @@ val receiptImages = \begin_layout Plain Layout - Menu(Loc( -\begin_inset Quotes eld -\end_inset - -receipts -\begin_inset Quotes erd -\end_inset - -, + Menu(Loc("receipts", \end_layout \begin_layout Plain Layout - ( -\begin_inset Quotes eld -\end_inset - -receipts -\begin_inset Quotes erd -\end_inset - - :: Nil) -> true, + ("receipts" :: Nil) -> true, \end_layout \begin_layout Plain Layout - -\begin_inset Quotes eld -\end_inset - -Receipts -\begin_inset Quotes erd -\end_inset - -, + "Receipts", \end_layout \begin_layout Plain Layout @@ -1138,14 +1017,23 @@ Receipts \end_layout \begin_layout Standard -Note that in this example we've used the implicit conversion from Pair[String,Bo -olean] to Link to make this Menu apply to everything under the -\begin_inset Quotes eld -\end_inset +Note that in this example we've used the implicit conversion from +\family typewriter +Pair[String,Boolean] +\family default + to +\family typewriter +Link +\family default + to make this Menu apply to everything under the +" + +\family typewriter receipts -\begin_inset Quotes erd -\end_inset +\family default + +" directory. \end_layout @@ -1162,24 +1050,37 @@ name "sub:menu-LinkText" \end_layout \begin_layout Standard -The LinkText class is what defines the function that will return the text - to display for a given menu item. +The +\family typewriter +LinkText +\family default + class is what defines the function that will return the text to display + for a given menu item. As we've shown, this can easily be set using the implicit conversion for string \begin_inset Formula $\rightarrow$ \end_inset -LinkText from Loc. - As an added bonus, the implicit conversion actually takes a by-name String + +\family typewriter +LinkText +\family default + from +\family typewriter +Loc +\family default +. + As an added bonus, the implicit conversion actually takes a by-name +\family typewriter +String +\family default for the parameter; that means you can just as easily pass in a function to generate the link text as a static string. For example, with our profile link we may want to make the link say -\begin_inset Quotes eld -\end_inset +" 's profile -\begin_inset Quotes erd -\end_inset +" . Listing @@ -1191,7 +1092,11 @@ reference "lst:Customizing-Link-Text" shows how we can do it by defining a helper method, assuming that there's another method that will return the current user's name (we use the ubiquitous - Foo object here). + +\family typewriter +Foo +\family default + object here). \end_layout \begin_layout Standard @@ -1221,41 +1126,17 @@ name "lst:Customizing-Link-Text" \begin_layout Plain Layout -def profileText = Foo.currentUser + -\begin_inset Quotes eld -\end_inset - -'s profile -\begin_inset Quotes erd -\end_inset - - +def profileText = Foo.currentUser + "'s profile" \end_layout \begin_layout Plain Layout -val profileMenu = Menu(Loc( -\begin_inset Quotes eld -\end_inset - -Profile -\begin_inset Quotes erd -\end_inset - -, +val profileMenu = Menu(Loc("Profile", \end_layout \begin_layout Plain Layout - -\begin_inset Quotes eld -\end_inset - -profile -\begin_inset Quotes erd -\end_inset - - :: Nil, + "profile" :: Nil, \end_layout \begin_layout Plain Layout @@ -1269,10 +1150,22 @@ profile \end_layout \begin_layout Standard -Of course, if you want you can construct the LinkText instance directly, - just passing in a constructor function that returns a NodeSeq. - The function that you use with LinkText takes a type-safe input parameter, - which we'll discuss in more detail in section +Of course, if you want you can construct the +\family typewriter +LinkText +\family default + instance directly, just passing in a constructor function that returns + a +\family typewriter +NodeSeq +\family default +. + The function that you use with +\family typewriter +LinkText +\family default + takes a type-safe input parameter, which we'll discuss in more detail in + section \begin_inset CommandInset ref LatexCommand ref reference "sub:Type-Safe-Params" @@ -1295,7 +1188,11 @@ name "sub:Using-lift-Menu" \begin_layout Standard So far we've covered the Scala side of things. - The other half of the magic is the special tag. + The other half of the magic is the special +\family typewriter + +\family default + tag. It's this tag that handles the rendering of your menus into XHTML. The Menu tag uses a built-in snippet \begin_inset Foot @@ -1308,8 +1205,15 @@ net.liftweb.builtin.snippet.Menu \end_inset to handle several rendering functions. - The most commonly used method is the Menu.builder snippet. - This snippet renders your entire menu structure as an unordered list (
    + The most commonly used method is the +\family typewriter +Menu.builder +\family default + snippet. + This snippet renders your entire menu structure as an unordered list ( +\family typewriter +
      +\family default in XHTML). Listing \begin_inset CommandInset ref @@ -1350,15 +1254,7 @@ name "lst:Rendering-with-Menu.title" \begin_layout Plain Layout -
      +