css selectors: multiple selectors for the same id

29 views
Skip to first unread message

Graham Tackley

unread,
Nov 10, 2010, 4:58:10 AM11/10/10
to Lift
I was trying to update an anchor tag with an href and the link text
like this:

val xml = <a class="link" href="#">link text</a>
val func =
".link [href]" #> "http://example.org" &
".link *" #> "example"

println(func.apply(xml))

This doesn't work as only the first selector applies:

// output is <a href="http://example.org" class="link">link text</
a>

I can see why from the constructor (and fundamental design) of
SelectorMap - it builds a map keyed on the id (and not the subNodes),
and in fact specifically throws away selectors that bind to the same
id.

This is fair enough and a reasonable decision, but should be mentioned
on the wiki page: both myself and two of my colleages independently
attempted to write selectors like this yesterday and got confused as
to why it didn't work. I'm a bit of a lift noob: is it ok for me to
just add this information to the wiki page?

It would have helped to get a warning or error when this happens (just
a log would be fine), and perhaps the catchall "case _ =>" in the
SelectorMap constructor would be a good place to do this?

It looks like the right way to do this is bind a entire replacement
node:

val xml = <a class="link" href="#">link text</a>
val func = ".link" #> <a href={"http://example.org"}>{"example"}</
a>

println(func.apply(xml))
// output is <a class="link" href="http://example.org">example</a>

I suspect the main reason for us attempting to write it the first way
is that we haven't quite groked templating that is far more powerful
than the traditional dumb string replacement. The magic of attribute
slurping means we haven't taken any power away from the template
author by taking the second approach, because attributes written in
the template carry through.

g

David Pollak

unread,
Nov 10, 2010, 2:26:22 PM11/10/10
to lif...@googlegroups.com
Graham,

The CSS Selector Transforms are works in progress.

I think the use case outlined here is wicked cool.  Please open a ticket and I'll do what I can to implement these changes.


--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
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
Blog: http://goodstuff.im
Surf the harmonics

Graham Tackley

unread,
Nov 12, 2010, 5:10:14 AM11/12/10
to Lift
On Nov 10, 7:26 pm, David Pollak <feeder.of.the.be...@gmail.com>
wrote:
> Graham,
>
> The CSS Selector Transforms are works in progress.

I'll be more forward at asking for changes next time then ;)

> I think the use case outlined here is wicked cool.  Please open a ticket and
> I'll do what I can to implement these changes.

https://www.assembla.com/spaces/liftweb/tickets/726-allow-multiple-css-selectors-for-the-same-id

Thanks
g
Reply all
Reply to author
Forward
0 new messages