JMacro was written by Gershom Bazerman, and was first released in July of 2009. Our contribution is the creation of two glue libraries:
- a thin wrapper which makes it easy to embed JMacro into HSX (independent of Happstack).
- another thin wrapper that makes it easy to generate and serve JMacro .js scripts using Happstack
The use of Happstack+HSX+JMacro has been documented in detail in this section of the Happstack Crash Course.
Here is a little example of what Happstack+HSX+JMacro looks like:
> helloJMacro :: JMacroPart Response > helloJMacro = > toResponse <$> defaultTemplate "Hello JMacro" () > <div> > <% [$jmacro| > var helloNode = document.createElement('h1'); > helloNode.appendChild(document.createTextNode("Hello, JMacro!")); > document.body.appendChild(helloNode); > |] %> > </div> >
hello str = <button onclick=("alert(" ++ str ++ ");")>click me</button>
You can write:
hello str = <button onclick=[$jmacro| alert(`(str)`); |]>click me</button>
The first version has a major bug -- it does not properly escape the
To learn more about using JMacro with Happstack and HSX, start reading here.
And a big thanks for Gershom Bazerman for creating JMacro. It's not part of Happstack or HSX, so you should have no problems using it with other web frameworks or templating libraries.