Enlive is a Clojure web templating library that combines vanilla HTML templates with backend logic. It’s a perfect separation of logic and frontend development in that it does not require frontend developers to know anything about the backend platform – only pure knowledge of HTML (maybe JS, CSS) is required.
I’m working with a Haskell web project based on Snap. Snap’s Heist template is logic-free, but somehow it still requires some domain specific knowledge of the Heist template. Moreover, the compiled version of Heist template requires some more tweaks, making collaboration a bit difficult.
I want to make a templating library that mimics Enlive in Haskell. It reads HTML document and transforms to Blaze-html, which is believed to be the fastest HTML generators available up till today. What I want to do is to allow developers to specify certain selectors and attach code snippets written in Blaze-html DSL, just like the following (pseudo-)Haskell code:
which does the following transformation:
What I have done so far, is creating the template library Piglet. Here is a quick look:
I like these >@< symbols. It’s like a cute pig looking at food!
The template is far from perfect. What I feel right now is that the syntax is not quite clean as it requires template Haskell quosiquotations. Also, the type signature is not quite nice – it’s a mere Q Exp. I plan to hide it under the hood. Also, currently, variables are referenced with string names, which might look a bit clutter (altough it does not affect any runtime efficiency).