You can do a recursive bind, but you must make it explicit:

def mySnippet(xhtml: NodeSeq): NodeSeq = {
     def doBind(xhtml: NodeSeq): NodeSeq =
         bind("b", xhtml,
              "link" -> { (kids: NodeSeq) => SHtml.link("next", () =>  
clicked(b), doBind(kids)) },
              "name" -> "the name",
              "description" -> "the description")
     doBind(xhtml)
}

-Ross

On Nov 11, 2009, at 1:21 PM, aw wrote:

>
> OK, your suggestion definitely makes the snippet code more readable,
> but I fear I didn't make my point clear because the snippet code still
> is highly coupled with the view layout.
>
> Imagine that I want to change my view from this:
>
> <a href="next">
>    <span class="name">name</span>
>    <span class="comment">description</span>
>    <span class="arrow"/>
> </a>
>
> to this:
>
> <span class="name">name</span>
> <span class="comment">description</span>
> <a href="next">
>    <span class="arrow"/>
> </a>
>
> This would mean that I need to change my template from:
>
> <b1:link>
>    <span class="name"><b2:name/></span>
>    <span class="comment"><b2:description/></span>
>    <span class="arrow"/>
> </b1:link>
>
> to this:
>
> <span class="name"><b:name/></span>
> <span class="comment"><b:description/></span>
> <b:link>
>    <span class="arrow"/>
> </b:link>
>
> And then I need to update my code from:
>
> bind("b1", xhtml",
>   "link" -> kids => SHtml.link("next", () => clicked(b),
>   bind("b2", kids, "name" -> b.name.is, "description" ->
> b.description.is
> )))
>
> to something like this:
>
> bind("b", xhtml",
>   "name" -> b.name.is,
>   "description" -> b.description.is,
>   "link" -> kids => SHtml.link("next", () => clicked(b))
> )))
>
>
> My complaint is that reorganizing the view is tending to require code
> changes at the snippet level.  And that just doesn't seem right to me.
>
> At first, I thought that I could leverage the recursive nature of
> snippets.  In other words, I thought I could avoid the b1 and b2
> binding keys and simply use b, then when the first round contained
> more b variables to bind, it would recurse.  Alas, this didn't work
> (I'm sorry, but I don't recall the error message).  But this was what
> I was thinking:
>
> <b:link>
>    <span class="name"><b:name/></span>
>    <span class="comment"><b:description/></span>
>    <span class="arrow"/>
> </b:link>
>
> or this:
>
> <span class="name"><b:name/></span>
> <span class="comment"><b:description/></span>
> <b:link>
>    <span class="arrow"/>
> </b:link>
>
> and the code would remain this:
>
> bind("b", xhtml",
>   "name" -> b.name.is,
>   "description" -> b.description.is,
>   "link" -> kids => SHtml.link("next", () => clicked(b))
> )))
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
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