This is my Blog.

It's full of opinions on a wide range of stuff.

Running SproutCore from within Lift

If you want to run "SproutCore": from within your Lift application there are a couple of configurations you need to ensure you apply within your Boot.scala in order to actually make it work as you might anticipate.

Firstly you need to ensure you set the HTML parser to use HTML5 and not XHTML, otherwise your templates will explode in extraordinary fashion when using the built template file as created by SproutCore build tools:

<code>LiftRules.htmlProperties.default.set((r: Req) => 
  new Html5Properties(r.userAgent))

With that in place you need to do the equivalent of implementing a symlink for those setups that use the filesystem (a la PHP, Rails etc). Within Lift this is accomplished by using a stateless rewrite:

<code>LiftRules.statelessRewrite.append {
  case RewriteRequest(ParsePath("index" :: Nil, "", true, false),_,_) => {
       RewriteResponse("static" :: "todos" :: "en" :: "1.0" :: "index" :: Nil)

This code tells Lift to rewrite the root path (/) to /static/todos/en//index template. Also be sure to implement your SiteMap so that only / is accessible and not the full (direct) SproutCore template path. If I do much more stuff with SproutCore I may well end up making an SBT plugin that automatically builds the updated JS files and copies them to your src/main/webapp path... not sure yet, we'll see. Eitherway, the rewriting is certainly a good candidate for stuffing into a LocParam and making it reusable based upon some project configuration. For example:

<code>Menu("Home") / "index" << UsesSproutCore </code>

For more information like this checkout my book on Lift launching this quarter on Manning Publications.

blog comments powered by Disqus