Ok, I'm stuck now.  I can't figure out how to mixin the prefixed
attributes of <menu:bind> with the links.  Here's what I have so far
(mostly copied from BindHelpers.scala:

import scala.xml._

object Main {
    def group(template: NodeSeq): NodeSeq = {
        val active_attrs = <a class="selected" />.attributes //
S.prefixedAttrsToMetaData("active")

        val vals = Map("foo1" -> <a href="foo1">Link1</a>, "foo2" ->
<a href="foo2">Link2</a>) // from the SiteMap
        val names = template \\ "bind" filter(_.prefix == "menu")
flatMap(_.attributes.get("name"))

        val item = "foo1" // loc.name
        val default = "foo1" // S.attr("default")

        val currentPage = if (names.contains(item)) item else default

        def bind(xml: NodeSeq): NodeSeq = {
            xml.flatMap {
                node => node match {
                    case s : Elem if (node.prefix == "menu" &&
node.label == "bind") => {
                            node.attributes.get("name") match {
                                case None => bind(node.child)
                                case Some(ns) => {
                                        vals.get(ns.text) match {
                                            case None => bind
(node.child)
                                            case Some(nodes) =>
                                                if (ns == currentPage)
nodes % active_attrs else nodes  // NEED HELP HERE (how to just get
attributes prefixed with a to mixin)
                                        }
                                    }
                            }
                        }
                    case Group(nodes) => Group(bind(nodes))
                    case s : Elem => Elem(node.prefix, node.label,
node.attributes,node.scope, bind(node.child) : _*)
                    case n => node
                }
            }
        }

        bind(template)
    }

  def main(args: Array[String]) = {
    val template: NodeSeq = <li><menu:bind name="foo1" a:id="aid1"/></
li><li><menu:bind name="foo2" a:id="aid2"/></li>;
    println(template)
    println(group(template))
  }
}

On Mar 27, 9:02 pm, bradford <[email protected]> wrote:
> Derek, I saw the changes and noticed that it doesn't capture the a
> attributes anymore.  I just wanted to point it out, because I wasn't
> sure if that was intended or not.
>
> Ok, I finally came up with a design for what I'm looking for:
>
> <lift:MyMenu.group active:class="selected" default="home">
>   <li><menu:bind name="home" a:id="home" /></li>
>   <li><menu:bind name="archives" a:id="archives" /></li>
>   <li><menu:bind name="music" a:id="music" a:style="margin-left:
> 10px;" /></li>
> </lift:MyMenu.group>
>
> I originally was going to try <menu:home /> and <menu:archives />
> instead since I could probably just call bind straight up on them, but
> I couldn't figure out how to extract these sub-elements since they are
> prefixed.
>
> Regards,
> Bradford
>
> On Mar 27, 1:57 am, Derek Chen-Becker <[email protected]> wrote:
>
> > It's in trunk now. Add the "donthide" attribute to your Menu.item tags and
> > you'll get the same text as you would normally, just not in link form.
>
> > Derek
>
> > On Wed, Mar 25, 2009 at 4:31 PM, bradford <[email protected]> wrote:
>
> > > Derek, that'll work :)
>
> > > Thanks,
> > > Bradford
>
> > > On Mar 25, 6:13 pm, Derek Chen-Becker <[email protected]> wrote:
> > > > That seems reasonable to me. That's actually what the Menu.builder does,
> > > > essentially. I don't think we want to modify the default behavior, but I
> > > > could make it a "donthide" attribute instead of "always" to do what
> > > you're
> > > > saying. Bradford, would that work for you?
>
> > > > Derek
>
> > > > On Wed, Mar 25, 2009 at 3:54 PM, Charles F. Munat <[email protected]>
> > > wrote:
>
> > > > > Actually, my feeling on item is that if you're on that page, item
> > > should
> > > > > return placeholder text (i.e. the same text without the link). For me,
> > > > > at least, that's the most common scenario.
>
> > > > > Chas.
>
> > > > > bradford wrote:
> > > > > > David, you're right that needing to surround the element text of a
> > > > > > with span is a unique case and should be a custom snippet.  I've
> > > > > > removed the span now and think that Derek's addition of "always"
> > > would
> > > > > > be just what I need.  Adding group="foo" to Menu.builder would
> > > suffice
> > > > > > as well.
>
> > > > > > Thanks for the tips, Chas.
>
> > > > > > Derek, if you do add "always" can you please let me know so that I
> > > can
> > > > > > update my code.
>
> > > > > > Thanks,
> > > > > > Bradford
>
> > > > > > On Mar 24, 10:37 pm, Derek Chen-Becker <[email protected]>
> > > wrote:
> > > > > >> The general case is that a page won't link to itself, I think, 
> > > > > >> which
> > > is
> > > > > why
> > > > > >> the default isn't to show it when the page matches. Unless anyone
> > > has
> > > > > >> objections I can add an "always" attribute. As for #1, the 
> > > > > >> Menu.item
> > > > > makes a
> > > > > >> link using whatever the contents of the Menu.item tag are for the
> > > link
> > > > > text:
>
> > > > > >> <lift:Menu.item name="foo"><span>Go here</span></lift:Menu.item>
>
> > > > > >> should become
>
> > > > > >> <a href={foo location}><span>Go here</span></a>
>
> > > > > >> Am I misunderstanding what you're looking for there? As for #2, you
> > > > > should
> > > > > >> be able to add a class using the prefixed attribute:
>
> > > > > >> <lift:Menu.builder li_item:class="bar" />
>
> > > > > >> In this context, li_item is the menu item that matches the current
> > > page.
> > > > > >> With Menu.group, you can specify the binding template:
>
> > > > > >> <ul>
> > > > > >> <lift:Menu.group group="help">
> > > > > >>   <li class="bar"><menu:bind /></li>
> > > > > >> </lift:Menu.group>
> > > > > >> </ul>
>
> > > > > >> But there's no provision to do anything special for the current
> > > page.
>
> > > > > >> Let me know if that's not sufficient or if I'm misunderstanding 
> > > > > >> your
> > > > > >> requirement.
>
> > > > > >> Derek
>
> > > > > >> On Tue, Mar 24, 2009 at 3:50 PM, bradford <[email protected]>
> > > wrote:
>
> > > > > >>> Thanks for the clarification, David, and for your snippet, Derek.
> > > > > >>> I think adding an "always" attribute to Menu.item would be very
> > > > > >>> beneficial.  I still don't understand why that's not its default
> > > > > >>> behavior.
> > > > > >>> It looks like I will not be able to use any of lift's Menu tags at
> > > > > >>> this time, because 1) I need to surround the item text with span
> > > and
> > > > > >>> 2) I need a way to add class="active" to the li_item.  Both are 
> > > > > >>> not
> > > > > >>> possible with Menu.item, Menu.group, or Menu.builder.  Let me know
> > > if
> > > > > >>> I am mistaken.  If I am not not, may I put in a feature request 
> > > > > >>> for
> > > > > >>> these items.  For the time being I will just hard code it as
> > > follows
> > > > > >>> (which is not a big deal to me at this time):
> > > > > >>> <ul class="menu">
> > > > > >>> <li><a href="/foo1" class="active"><span>Foo1</span></foo>
> > > > > >>> <li><a href="/foo2"><span>Foo2</span></foo>
> > > > > >>> <li><a href="/foo3"><span>Foo3</span></foo>
> > > > > >>> </ul>
> > > > > >>> Thanks again for the great support :)
> > > > > >>> Bradford
> > > > > >>> On Mar 24, 12:08 pm, David Pollak <[email protected]>
> > > > > >>> wrote:
> > > > > >>>> On Tue, Mar 24, 2009 at 9:02 AM, Charles F. Munat <[email protected]
>
> > > > > >>> wrote:
> > > > > >>>>> David Pollak wrote:
> > > > > >>>>>>     What's the best practice:
> > > > > >>>>>>     For more information about <lift:Menu.item name="foo1" />.
> > >  For
> > > > > >>> more
> > > > > >>>>>>     information about <lift:Menu.item name="foo2" />.
> > > > > >>>>>>     Or
> > > > > >>>>>>     For more information about <a href="/foo1">foo1</a>.  For
> > > more
> > > > > >>>>>>     information about <a href="/foo2">foo2</a>.
> > > > > >>>>>> The latter.  This allows you to move the pages around on the
> > > > > >>> filesystem
> > > > > >>>>>> without having to grep through all you source files looking for
> > > what
> > > > > >>>>>> needs to be changed.
> > > > > >>>>> Am I missing something, or did you mean the former?
> > > > > >>>> D'oh!  That brain-finger connection is always getting messed up.
> > >  I
> > > > > meant
> > > > > >>>> the former.  Thanks for correcting me!
> > > > > >>>>> Chas.
> > > > > >>>> --
> > > > > >>>> 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

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

Reply via email to