So, you want custom content with menus generated from the database...
well...

class BaseContentLoc(val name: String, _aspect: String) extends
Loc[CustomContent] {
  // the name of the page
  // def name = "Content"

  val BaseAspect = _aspect

  def defaultParams = Full(ContentLocStuff.NullCustomContent)

  override def forceParam = defaultParams

  // the default parameters (used for generating the menu listing)
  override def additionalKidParams =
CustomContent.findAll(By(CustomContent.aspect, BaseAspect),

OrderBy(CustomContent.displayOrder, Ascending))

  // no extra parameters
  def params = List(Loc.PlaceHolder, Loc.Template(myTemplate))

  def myTemplate() =
  <lift:surround with="default-final" at="content"><lift:display
/></lift:surround>


  /**
   * Generate a link based on the current page
   */
  val link =
  new Loc.Link[CustomContent](List(BaseAspect), false) {
    override def createLink(in: CustomContent) = {
      Full(Text("/"+urlEncode(BaseAspect)+"/"+urlEncode(in.page)))
    }
  }

  /**
   * What's the text of the link?
   */
  val text = new Loc.LinkText(calcLinkText _)

  def calcLinkText(in: CustomContent): NodeSeq = {
    if (in.page.length > 0) Text(in.page) else Text(name)
  }

  object Finder {
    def unapply(page: String): Option[CustomContent] =
    CustomContent.findContent(page, BaseAspect)
  }

  /**
   * Rewrite the request and emit the type-safe parameter
   */
  override val rewrite: LocRewrite =
  Full({
      case RewriteRequest(ParsePath(BaseAspect :: Finder(content) :: Nil,
                                    _, _, _), _, _) =>
        (RewriteResponse(BaseAspect :: Nil), content)
    })

  /**
   * Check for page-specific snippets and
   * do appropriate dispatching
   */
  override val snippets: SnippetTest = {
    case ("display", Full(v)) =>  display(v) _
  }

  def display(v: CustomContent)(in: NodeSeq) = v.content openOr in
}

This will autogenerate submenus based on a DB lookup of CustomeContent.

Does this help achieve your longer term goal?

Thanks,

David

On Fri, Jun 12, 2009 at 3:20 PM, glenn <gl...@exmbly.com> wrote:

>
> David,
>
> Here's my scenario. I've got about 30 menus organized into about 7 or
> 8 groups. Thanks to
> help from you and Derek and others in this discussion, I can display
> nested menus in
> groups as a horizontal superfish menu.
>
> Using URL Rewriting, as described in the master lift book, I created a
> method:
>
> def rewrite:LiftRules.RewritePF = {
>        //Services
>         case RewriteRequest(
>                ParsePath(List("services"),_,_,_),_,_) =>
>                        RewriteResponse("content" :: Nil, Map("tag" ->
> "services"))
>         case RewriteRequest(
>                ParsePath(List("services","coreguard"),_,_,_),_,_) =>
>                        RewriteResponse("content" :: Nil, Map("tag" ->
> "coreguard"))
>         case RewriteRequest(
>                ParsePath(List("services","estatePlanning"),_,_,_),_,_) =>
>                         RewriteResponse("content" :: Nil, Map("tag" ->
> "estatePlanning"))
>         case RewriteRequest( ....
>
>        ...
> }
>
> That sends all my requests to  a content.html template:
>
> <lift:surround with="default" at="content">
>      <span><h3><lift:MySnippets.content>
>        <c:title/>
>      </lift:MySnippets.content>
>       </h3></span>
> </lift:surround>
>
> The snippet is just as riduculously simple:
>
> def content(xhtml:NodeSeq):NodeSeq = {
>    val c = S.param("tag") openOr ""
>
>    bind("c", xhtml,
>        "title" -> S.?(c))
>  }
>
> This navigation works, though is repititious.
> It would be relatively easy to extend this idea to generate menus,
> complete with navigation, programatically (say, from an xml file or a
> data table) and allow
> site administrators and other users to drag-and-drop menus as desired.
>
> The point of all this, in my view, is to eventually populate
> content.html with data/documents/templates/atom feeds, whatever, with
> nothing
> more than the RewriteResponse Map parameter, and voila, you have a
> fledgling CMS built with relatively few lines of code.
>
> If  you have some alternative ideas for creating a programatic
> navigation system, I would be very interested.
>
> Glenn...
>
>
> On Jun 12, 2:39 pm, David Pollak <feeder.of.the.be...@gmail.com>
> wrote:
> > On Fri, Jun 12, 2009 at 10:44 AM, glenn <gl...@exmbly.com> wrote:
> >
> > > RewriteRequest isn't working in my app, so I must be doing something
> > > wrong, or leaving something important out.
> >
> > > I have a menu in my siteMap:
> >
> > > Menu(Loc("contact", List("info", "contact"), "Contact Us", LocGroup
> > > ("info")))
> >
> > > My boot.scala contains this:
> >
> > > LiftRules.rewrite.append {
> > >        case RewriteRequest(
> > >                ParsePath(List("info","contact"),_,_,_),_,_) =>
> > >                        RewriteResponse("content" :: Nil, Map("tag" ->
> > > "contact"))
> > >       ...
> > > }
> >
> > > And I have a content.html page in webapp.
> >
> > I think there's a better way to achieve what you want... lemme know
> together
> > some code for you.
> >
> >
> >
> > > Clicking on the "Contact Us" menu returns an HTTP 403 error, not
> > > content.html.
> >
> > > Any help would be appreciated.
> >
> > > Glenn...
> >
> > --
> > Lift, the simply functional web frameworkhttp://liftweb.net
> > Beginning Scalahttp://www.apress.com/book/view/1430219890
> > Follow me:http://twitter.com/dpp
> > Git some:http://github.com/dpp
>
> >
>


-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to