Hsoy Templates – client- and server side templating
Introducing “Hsoy Templates”, a templating library and a set of tools. It can be used on both server and client side. It have HAML syntax, and compiles into Java on server side and JavaScript on client side.
Actually it’s a version of Google Closure Templates (.soy templates) with HAML syntax.
Why you need this?
In modern web development it’s very common to update some parts of current page by data from server, there are lots of JavaScript MVC frameworks (like Backbone). But the problem that it’s annoying to write and support same HTML view two times – for JavaScript and for Server. It breaks DRY principle.
Hsoy Templates gives you a way to write such templates just once, and use it on client-side, and on backend.
Features:
- one template (a *.hsoy file)
- HAML syntax (accelerates and simplifies template creation – see http://haml.info/)
- fast
- compiled into Java (can be reused from any JVM based language)
- compiled into Javascript
- based on Google Closure Templates library
- Apache 2.0 licence
- hsoy-templates – a core library, for transforming .hsoy file into JavaScript and/or Java source
- maven-hsoy-templates – a Maven plugin
- compile into JS/Java on compile phase
- recompile into JS after each modification (watching for changes)
- grails-hsoy-templates – a Grails plugin, as a Resource Plugin extension (http://grails.org/plugin/hsoy-templates)
- test test test
- support all Google Closure Templates features
- JSP taglib
- native OS listener of sources modification (for Maven plugin)
- a Gradle plugin
Example:
Source template
Take a look at examples of Haml syntax at http://haml.info/tutorial.html (skip ERB parts)
and use it
from JavaScript:
from Java:
As a result you’ll get
Same HTML on server and client side, generated from same template file.
Components
Currently it consists of following parts: