Histone is a powerful and flexible template engine used to produce HTML code as well as any other text formats. Histone can be run on the client (JavaScript) as well as server (Java, PHP) side without modifying your templates. Its built-in extensions API allows you to add your own methods and attributes that are specific to your project. The resulting templates have clean and intuitive syntax, you can store them in either original or "optimized" form that will not require parsing, depending on whether or not you need an extra performance.
Histone is a powerful and flexible template engine that is suitable for producing HTML code and other text formats. To put it simple, it can convert JSON data into HTML on a wide array of platforms.
Before we started our own engine, we did a research on the existing products to understand their pros and cons. We considered only popular template engines with significant user base. We also focused on engines that were implemented in at least two out of three needed languages (Java, JavaScript, PHP).
Pros:
Cons:
Pros:
Cons:
After considering existing tools our team decided to write a new engine that will have the advantages of Closure and Mustache while fixing shortcomings that were critical for us. Histone had to meet the following requirements:
— Cross-platform templates. All Histone implementations should use the same syntax. That way, we can use the same templates on the server and the client side.
— Familiar and intuitive syntax. Every template instruction is delimited by {{ and }}. The rest is ignored by the parses and makes it into the resulting document as is.
— No embedded code in templates. Most template engines permit embedding code that will be executed directly from the template. Usually, only the language of the engine implementation is supported, so in order to use the same template with another implementation you will also have to rewrite the code. Because of that we did not enable code embedding in Histone.
— Template engine is easily expandable. Regardless of the engine’s implementation in use its API allows adding a new method or attribute.
— One source file to rule them all. JSON is the universal format for Histone. Histone supports all data types that are provided by the JSON format. It doesn’t matter what data types are supported by your project’s language, Histone’s template language provides you with all the necessary data types supported by JSON, making it a perfect tool to transform JSON documents.
— Templates are platform-aware. The template always considers the platform it is being used on. E.g., when run in the browser, the template adapts to the screen resolution and window size. When run on the server, the template may use request headers and adapts to the OS of the server.
— Cross-platform, easy to port. JavaScript, Java and PHP implementations are available out of the box. Histone doesn’t rely on external libraries and has well-structured code which makes it easy to write a C++, Ruby, Objective-C or ActionScript implementation of the engine.
— Fast. Unlike Google Closure Templates, Histone does not translate the template to the language that is used by the specific implementation. Instead, it has a tool that can recompile the template so that the actual parsing (the most time-consuming operation) will be avoided. Part of the template that does not rely on external functions, attributes and variables, is also executed at this point.