framework
framework copied to clipboard
Changing labels with CssSelector
This ticket follows the discussion on the mailing list about rewrapping Elem: https://groups.google.com/d/topic/liftweb/uVW4xOPgnk8/discussion
For example:
<people version="1" otherProp="prop">
<name>foo</name>
<friends><name>bar</name></name><name>baz</name></friends>
</people>
Into:
<user version="2" otherProp="prop">
<login>foo</login>
<knows><name>bar</name></name><name>baz</name></knows>
</user>
Proposed solution:
"people" #> ((ns: NodeSeq) => <user version="2">{
val kids = ns.asInstanceOf[Elem].child
("name" #> ((ns: NodeSeq) => <login>{ns.asInstanceOf[Elem].child}</login>)).apply(kids)
}</user>)
But should be simpler.
The biggest question here is the syntax to be used. You can use "selector <*>" #> <div />, for example, to surround the children of the selected element with a div element. But, this does not get rid of the parent element.
Perhaps <> could be the symbolic abbreviation to use here. Or <label>, possibly. The parsing would have to occur somewhere in CssSelector.scala, perhaps parsing it to a ReplaceNodeLabel SubNode class. Then we'd want to add handling for that SubNode in applyRule in CssSel, which handling should be able to just do a realE.copy(label = <new label>). That's a bit hand-wavy though, and needs more investigation.