becad5af68
Fixes #10. NOTE: this commit has performance regression. |
||
---|---|---|
benchmarks | ||
bin | ||
lib | ||
spec | ||
.gitignore | ||
.rspec | ||
.travis.yml | ||
CHANGELOG.md | ||
Gemfile | ||
hamlit.gemspec | ||
LICENSE.txt | ||
Rakefile | ||
README.md |
Hamlit
Hamlit is a high performance haml implementation.
Installation
Add this line to your application's Gemfile:
gem 'hamlit'
or just replace gem "haml"
with gem "hamlit"
.
Features
Fast rendering
Hamlit's rendering is 7.24x times faster than original haml.
erubis: 114417.8 i/s
hamlit: 107367.5 i/s - 1.07x slower
slim: 104728.0 i/s - 1.09x slower
faml: 87624.2 i/s - 1.31x slower
haml: 15796.0 i/s - 7.24x slower
This benchmark is the same as slim-template/slim's one for fairness. (The result on travis CI)
Note that there are some incompatibilities related to performance. You may want faml for a better compatibility.
Better parser
Haml's attribute parser is not so good. For example, raises syntax error for %a{ b: '}' }
.
Hamlit's attribute parser is implemented with Ripper, which is an official lexer for Ruby,
so it is able to parse such an attribute.
Passing haml-spec
haml/haml-spec is a basic suite of tests for Haml interpreters. For all test cases in haml-spec, Hamlit behaves the same as Haml (ugly mode only, which is used on production).
Hamlit is used on githubranking.com.
Usage
Basically the same as haml. Check out the reference documentation for details.
Rails
Just update Gemfile.
Sinatra
For compatibility with Haml, Hamlit does not escape html automatically in sinatra. You can enable html escaping manually:
set :haml, { escape_html: true }
Why high performance?
Less work on runtime
Haml's rendering is very slow because generated code by haml runs many operations on runtime. For example, Haml::Util is extended on view, attribute rendering runs even if it is a static value and the values in attribute is sorted. All of them is achieved on runtime.
Hamlit extends ActionView beforehand, attribute rendering is done when compiled if it is a static hash and no unnecessary operation is done on runtime.
Temple optimizers
Hamlit is implemented with temple, which is a template engine framework for Ruby. Temple has some great optimizers for generated code. Thus generated code by Hamlit is very fast.
Not only relying on temple optimizers, but also Hamlit's compiler cares about many cases to optimize performance such as string interpolation.
TODO
Currently there are some important incompatibilities that should be fixed.
License
MIT License