On Thu, Feb 4, 2010 at 7:32 AM, Ross Mellgren <[email protected]> wrote:
> I think this new version will be slower than your original one, as each
> call to bind will visit the entire input XHTML. Why not use your original
> formulation but instead of TheBindParam, use FuncBindParam (which is the
> sugar-free version of body => ... that David describes)?
>
Yeah... the bind operation is O(n log m) where 'n' is the number of element
nodes and m is the number of things to be bound. Using foldLeft, you're
making that O(n m) Then again, if the code is understandable for you, then
a couple of nanoseconds here and there are not overly important.
>
> -Ross
>
> On Feb 4, 2010, at 10:28 AM, Tim Maxwell wrote:
>
> > Hi David,
> >
> > There really are a lot of paths available with scala/lift, aren't
> > there?
> >
> > After looking at what you wrote, here's what I came up with that works
> > well/is functional and compact, in case anyone else is wondering about
> > it.
> >
> > def links(html:NodeSeq): NodeSeq={
> >
> > Product.findActive.foldLeft(html) {
> > (html, prod) => bind("links",html,
> > "force_"+prod.product ->{x:NodeSeq => {<a href={"/forced?
> > product="+prod.product}>{x}</a>}}
> > )
> > }
> > }
> >
> > Product is a JPA entity class, findactive returns a list of products.
> >
> > If anyone has suggestions, please share.
> >
> > Cheers,
> > Tim
> >
> > On Feb 3, 5:08 pm, David Pollak <[email protected]> wrote:
> >> On Wed, Feb 3, 2010 at 12:44 PM, Tim Maxwell <[email protected]>
> wrote:
> >>> Hi folks,
> >>
> >>> I am trying to do binds based on a list of products. The point is to
> >>> create links that can be wrapped around existing text or images.
> >>> Something like this:
> >>
> >>> <signup:links.force_PROD>This is the link text our marketing dept.
> >>> creates</signup:link>
> >>
> >>> Here's what I have so far in the snippet related to it:
> >>
> >>> def links(html:NodeSeq): NodeSeq={
> >>
> >>> val productBinds:Seq[BindParam] = Product.findActive.flatMap{
> >>> prod => List[BindParam] ( TheBindParam( "force_"+prod.product,
> >>> SHtml.link("/forced?product="+prod.product, ()=>() , _ ) ) )
> >>> }
> >>> bind("links" , html, productBinds: _*)
> >>
> >> It's so cool to see how people stuff in Lift...
> >>
> >> Within your function, you can get the element that's being bound with:
> >>
> >> BindHelpers.currentNode: Box[Elem]
> >>
> >> On the other hand, if you're looking to get the children of the node
> >> currently being bound:
> >>
> >> FuncBindParam("force_"+prod.product, body => <a
> >> href={"/forced?product="+Helpers.urlEncode(prod.product)}>{body}</a>)
> >>
> >> Hope this helps.
> >>
> >> Thanks,
> >>
> >> David
> >>
> >>
> >>
> >>
> >>
> >>> }
> >>
> >>> Cheers,
> >>> Tim
> >>
> >>> --
> >>> 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]<liftweb%[email protected]>
> <liftweb%[email protected]<liftweb%[email protected]>>
> >>> .
> >>> For more options, visit this group at
> >>> http://groups.google.com/group/liftweb?hl=en.
> >>
> >> --
> >> Lift, the simply functional web frameworkhttp://liftweb.net
> >> Beginning Scalahttp://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 [email protected].
> > To unsubscribe from this group, send email to
> [email protected]<liftweb%[email protected]>
> .
> > For more options, visit this group at
> http://groups.google.com/group/liftweb?hl=en.
> >
>
> --
> 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]<liftweb%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/liftweb?hl=en.
>
>
--
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 [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.