[Lift] Re: Template help

2009-11-11 Thread David Pollak
On Wed, Nov 11, 2009 at 12:35 AM, aw anth...@whitford.com wrote:


 I need to create a snippet sequence that looks something like this:

 a href=next
span class=namename/span
span class=commentdescription/span
span class=arrow/
 /a

 The anchor needs to be generated using SHtml.link, and name 
 description need to be bound.  As a result, I end up with a template
 sequence like this:

 b1:link
span class=nameb2:name//span
span class=commentb2:description//span
span class=arrow/
 /b1:link

 Then, I need snippet code that does something like:

 bind(b1, xhtml,
  link - SHtml.link(S.contextPath, () = clicked(b), bind(b2,
 chooseTemplate(b1, link, xhtml), name - Text(b.name),
 description - Text(b.description) ))


Why are you using S.contextPath?  But:

bind(b1, xhtml,
   link - kids = SHtml.link(/, () = clicked(b),
   bind(b2, kids, name - b.name.is, description - b.description.is
)))




 Yuk...  I'm just not happy with this.  Sure, I could make it a little
 more readable, but this still seems unnecessarily complex and
 verbose.  I also really don't like how the view logic is dictating my
 binding logic.  In other words, if I wanted to change my view
 organization, there is a high chance that I also need to change my
 binding logic -- and that just isn't right...

 Is there a better strategy?
 



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

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



[Lift] Re: Template help

2009-11-11 Thread Naftoli Gugenheim

You might need to surround the kids = ... function with parenthesis.

-
David Pollakfeeder.of.the.be...@gmail.com wrote:

On Wed, Nov 11, 2009 at 12:35 AM, aw anth...@whitford.com wrote:


 I need to create a snippet sequence that looks something like this:

 a href=next
span class=namename/span
span class=commentdescription/span
span class=arrow/
 /a

 The anchor needs to be generated using SHtml.link, and name 
 description need to be bound.  As a result, I end up with a template
 sequence like this:

 b1:link
span class=nameb2:name//span
span class=commentb2:description//span
span class=arrow/
 /b1:link

 Then, I need snippet code that does something like:

 bind(b1, xhtml,
  link - SHtml.link(S.contextPath, () = clicked(b), bind(b2,
 chooseTemplate(b1, link, xhtml), name - Text(b.name),
 description - Text(b.description) ))


Why are you using S.contextPath?  But:

bind(b1, xhtml,
   link - kids = SHtml.link(/, () = clicked(b),
   bind(b2, kids, name - b.name.is, description - b.description.is
)))




 Yuk...  I'm just not happy with this.  Sure, I could make it a little
 more readable, but this still seems unnecessarily complex and
 verbose.  I also really don't like how the view logic is dictating my
 binding logic.  In other words, if I wanted to change my view
 organization, there is a high chance that I also need to change my
 binding logic -- and that just isn't right...

 Is there a better strategy?
 



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



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



[Lift] Re: Template help

2009-11-11 Thread aw

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=namename/span
span class=commentdescription/span
span class=arrow/
/a

to this:

span class=namename/span
span class=commentdescription/span
a href=next
span class=arrow/
/a

This would mean that I need to change my template from:

b1:link
span class=nameb2:name//span
span class=commentb2:description//span
span class=arrow/
/b1:link

to this:

span class=nameb:name//span
span class=commentb: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=nameb:name//span
span class=commentb:description//span
span class=arrow/
/b:link

or this:

span class=nameb:name//span
span class=commentb: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
-~--~~~~--~~--~--~---



[Lift] Re: Template help

2009-11-11 Thread Ross Mellgren

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=namename/span
span class=commentdescription/span
span class=arrow/
 /a

 to this:

 span class=namename/span
 span class=commentdescription/span
 a href=next
span class=arrow/
 /a

 This would mean that I need to change my template from:

 b1:link
span class=nameb2:name//span
span class=commentb2:description//span
span class=arrow/
 /b1:link

 to this:

 span class=nameb:name//span
 span class=commentb: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=nameb:name//span
span class=commentb:description//span
span class=arrow/
 /b:link

 or this:

 span class=nameb:name//span
 span class=commentb: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
-~--~~~~--~~--~--~---



[Lift] Re: Template help

2009-11-11 Thread Jim Barrows
On Wed, Nov 11, 2009 at 11:21 AM, aw anth...@whitford.com 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.


If this was a MVC type framework, I think you're point would be valid.  But
it isn't a MVC framework.  The snippet is tightly coupled to the xhtml,
because it's the dynamic part of the xhtml.

The best way to mitigate these kinds of changes is to design the UI first,
then build the snippets.   That way, you're not rearranging as often.
See this article for a better understanding:
http://wiki.liftweb.net/index.php?title=Lift_View_First


 Imagine that I want to change my view from this:

 a href=next
span class=namename/span
span class=commentdescription/span
span class=arrow/
 /a

 to this:

 span class=namename/span
 span class=commentdescription/span
 a href=next
 span class=arrow/
 /a

 This would mean that I need to change my template from:

 b1:link
span class=nameb2:name//span
span class=commentb2:description//span
span class=arrow/
 /b1:link

 to this:

 span class=nameb:name//span
 span class=commentb: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=nameb:name//span
span class=commentb:description//span
span class=arrow/
 /b:link

 or this:

 span class=nameb:name//span
 span class=commentb: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))
 )))


 



-- 
James A Barrows

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



[Lift] Re: Template help

2009-11-11 Thread Naftoli Gugenheim

I didn't see Tim's blog post, but another option is to bind in two passes. 
First bind the outer level: b1:link should become an SHtml.link, preserving the 
same set of child elements. So here use a NodeSeq function: kids = 
SHtml.link(..., kids). Then pass the resulting NodeSeq to a bind invocation 
that transforms your other elements.
You can place this in one statement, by using one call to bind as the NodeSeq 
argument to the other call. And you can use the implicit in BindPlus to chain 
bind calls:
xhtml.bind(prefix, bindParams ... ).bind(pre2, ...)
That said, I think there is a fundamental, inevitable tension between 
separation of view and logic, and repetition (not really your point). I tried 
to address this, as it applies to Mapper fields, to a small extent in 
ModelView. However if anyone has better ideas of how to do things I'm very 
interested to hear!



-
Timothy Perretttimo...@getintheloop.eu wrote:


Take a look at:

http://logji.blogspot.com/2009/09/composable-bindings-in-lift.html

and then:

http://logji.blogspot.com/2009/10/composable-bindings-in-lift-part-ii.html

Sounds like this could provide a more flexible implementation pattern for your 
use case.

Cheers, Tim


On 11 Nov 2009, at 18:21, 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=namename/span
span class=commentdescription/span
span class=arrow/
 /a
 
 to this:
 
 span class=namename/span
 span class=commentdescription/span
 a href=next
span class=arrow/
 /a
 
 This would mean that I need to change my template from:
 
 b1:link
span class=nameb2:name//span
span class=commentb2:description//span
span class=arrow/
 /b1:link
 
 to this:
 
 span class=nameb:name//span
 span class=commentb: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=nameb:name//span
span class=commentb:description//span
span class=arrow/
 /b:link
 
 or this:
 
 span class=nameb:name//span
 span class=commentb: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
-~--~~~~--~~--~--~---