My little world

Welcome to my own little world. Here I am going to post random stuff that you might like or enjoy to read.

I will try to post some funny stuff, so you definitely won’t get too bored while reading some technical things or other interesting ones I got the spirit to write. Maybe I am going to create some minigames I can put up here, so that you actually get something more than reading (^_^).

If you want to know more about me follow this link.


Newest blog entry:

liftweb: Extracting NodeSeq with CssSel

03 September, 2012 by droppy

So I have written a programm for one of my sites with the liftweb framework and ran into an interesting problem. I am having a table where i want to update the content without having any XML in my code, so that i can adjust the HTML easily in my .html files without recompiling.

I want to be able to update the content when an ajax button was pressed. So i have to store the XML in my Snippet. Because i wanted to have everything in HTML5 i am using the designer friendly templates with the CSS-Selectors. After some research in the Assembla Space i came up with the following code to extract NodeSeq with an CssSel

val xml = <a class="foo"><b class="bar"><c></c></b></a>
val sel1 = ".bar ^^" #> (n => n)
val sel2 = ".bar ^*" #> (n => n)

sel1.apply(xml) // <b class="bar"><c></c></b>
sel2.apply(xml) // <c></c>

A little example for a snippet function

def render(in: NodeSeq): NodeSeq = {
  val template = (".bar ^^" #> (n => n)).apply(in)
  // use template where you want in here
  // and return your normal selectors like this:
  (".foo" #> "hello world").apply(in)
}

Saved here so that i won’t forget it again :)