2015-03-30 08:20:24 -04:00
|
|
|
# Hamlit [![Build Status](https://travis-ci.org/k0kubun/hamlit.svg?branch=master)](https://travis-ci.org/k0kubun/hamlit)
|
2015-03-09 01:36:35 -04:00
|
|
|
|
2015-03-30 07:22:51 -04:00
|
|
|
Hamlit is a high performance [haml](https://github.com/haml/haml) implementation.
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
|
|
Add this line to your application's Gemfile:
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
gem 'hamlit'
|
|
|
|
```
|
|
|
|
|
|
|
|
or just replace `gem "haml"` with `gem "hamlit"`.
|
|
|
|
|
|
|
|
## Features
|
|
|
|
### Fast rendering
|
|
|
|
|
2015-03-30 08:24:25 -04:00
|
|
|
Hamlit's rendering is **8.47x times faster** than original haml.
|
2015-03-30 07:22:51 -04:00
|
|
|
|
2015-03-30 09:23:21 -04:00
|
|
|
![](http://i.gyazo.com/57b726102a4a169d4b85cc22fcbb3ff3.png)
|
|
|
|
|
2015-03-30 07:22:51 -04:00
|
|
|
```
|
2015-03-30 08:24:25 -04:00
|
|
|
hamlit: 133922.9 i/s
|
|
|
|
erubis: 123464.1 i/s - 1.08x slower
|
|
|
|
slim: 110404.3 i/s - 1.21x slower
|
|
|
|
faml: 92009.3 i/s - 1.46x slower
|
|
|
|
haml: 15810.4 i/s - 8.47x slower
|
2015-03-30 07:22:51 -04:00
|
|
|
```
|
|
|
|
|
2015-03-30 08:24:25 -04:00
|
|
|
[This benchmark](https://github.com/k0kubun/hamlit/blob/74ede1101f228828e343ceb1af481c45eaf0a1dd/benchmarks/benchmark.rb)
|
2015-03-30 07:22:51 -04:00
|
|
|
is the same as [slim-template/slim](https://github.com/slim-template/slim)'s one for fairness.
|
2015-03-30 08:24:25 -04:00
|
|
|
([The result on travis CI](https://travis-ci.org/k0kubun/hamlit/jobs/56403724))
|
2015-03-30 07:22:51 -04:00
|
|
|
|
|
|
|
### 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,
|
2015-03-30 09:23:21 -04:00
|
|
|
so it is able to parse such an attribute.
|
2015-03-30 07:22:51 -04:00
|
|
|
|
|
|
|
### Passing haml-spec
|
|
|
|
|
|
|
|
[haml/haml-spec](https://github.com/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).
|
2015-03-09 01:36:35 -04:00
|
|
|
|
2015-03-30 08:58:48 -04:00
|
|
|
Hamlit is used on [githubranking.com](http://githubranking.com/).
|
|
|
|
|
2015-03-30 09:23:21 -04:00
|
|
|
## Usage
|
|
|
|
|
|
|
|
Basically the same as [haml](https://github.com/haml/haml).
|
|
|
|
Check out the [reference documentation](http://haml.info/docs/yardoc/file.REFERENCE.html) for details.
|
|
|
|
|
2015-04-04 22:08:36 -04:00
|
|
|
### Rails
|
|
|
|
|
|
|
|
Just update Gemfile.
|
|
|
|
|
|
|
|
### Sinatra
|
|
|
|
|
|
|
|
For compatibility with Haml, Hamlit does not escape html automatically in sinatra.
|
|
|
|
You can enable html escaping manually:
|
|
|
|
|
|
|
|
```ruby
|
2015-04-05 20:35:25 -04:00
|
|
|
set :haml, { escape_html: true }
|
2015-04-04 22:08:36 -04:00
|
|
|
```
|
|
|
|
|
2015-03-30 08:58:48 -04:00
|
|
|
## 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](https://github.com/judofyr/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.
|
|
|
|
|
2015-03-09 01:40:11 -04:00
|
|
|
## License
|
2015-03-09 01:36:35 -04:00
|
|
|
|
2015-03-09 01:40:11 -04:00
|
|
|
MIT License
|