Hardcode Haml
Target
The target of this project is to provide Haml templates to more programming languages, including C and C++. The templates are pre-compiled to achieve portability to many languages and runtime performance. It targets embedded projects and/or hardcore coders.
Motivation
Most template engines for compiled and statically typed languages (like C and C++) are only able to do simple search and replace jobs for given values. Having used template engines in script languages like Ruby, Python or Java Script makes returning to those template engines hard. This is where Hardcode Haml comes into play.
Haml
Haml was first implemented in ruby and got ported to multiple other languages. It combines the ability to replace parts of your markup with values calculated at runtime (even allowing evaluation of code directly from the markup) and additionally replaces XML with more writeable and readable markup.
For more information on Haml visit the Wikipedia page or the homepage of the original implementation.
Concept
This project turns Haml markup into program code. Therefore the markup gets parsed and processed before runtime and maybe even optimized by your compiler. Therefore execution time, memory footprint and file size on the target device should be superior to other approaches. The drawback is, that your templates are compiled in your binary and you can't edit them on the target system.
The language modules will generate a function which, when executed, will output the generated XML markup into a stream. The parameters of the function can be referenced directly from within the template. Haml contains syntax elements which let you print out evaluated code and even pass code directly to the generated code. Loops and other control flow elements can be used to repeat blocks or conditionally display them.
To fullfill the needs of the target languages, Haml syntax has to be extended. We need a way to specify the name and type of the parameters given to the template. Additionally most languages need a way to execute code before the function declaration (e.g. to include headers).
Test it!
The repository is located at github.
The code might not be ready for production use by everyone. I use it in a production project and am constantly improving it as a result of this experience. If you do not know whether you should use Hardcode Haml or have any other question about it feel free to contact me. Feedback would also improves my motivation to work on this project.
Bug reports and feature requests are welcome at github.