I’m looking into Scalate as the templating engine for my web site rewrite, and I’m doing this for several reasons.
- It natively supports Scala
- I like the Jade syntax for DRY (Don’t Repeat Yourself) HTML page creation
- Pages are generally compiled into bytecode for high performance execution
- It has the ability to perform CSS selector driven DOM manipulation similar to what a browser does, only on the server side
While playing around with this last night, I did encounter one detail I’m not too happy about: template inheritance. It would appear that inheritance in Scalate does not work as advertised in the Jade syntax spec. The block
and extends
key words look to be treated like regular tag generaters vs. keywords that serve a special compositional purpose. I may be missing something, but the more I think about it, the more it seems reasonable this is the case.
Scalate is designed as a templating engine that supports many different syntaxes. I imagine wiring all these different syntaxes together within the render pipeline of the template engine would yield a half baked and quirky solution. Instead, composition of pages can be accomplished via a more dependency injection approach. Instead of composing inheritance trees in the templating layer, each template should provide places where Scala variables are output into the page. The Scala variable can be, for example, simple text for output or another templated component. Composition is accomplished from the outside in using Scala code.
The trick to making this a successful and pleasurable solution is figuring out how to make this compositional approach concise and simple. The last thing I want to do is have some involved declaritive structure for every page.
UPDATE: I have confirmed Scalate’s Jade template system does not support block
and extends
, though not for the reason I originally thought. It just hasn’t been implemented yet. See [https://groups.google.com/forum/?fromgroups=#!topic/scalate/A-NOeZazjIQ]