All Projects → k0kubun → Hamlit

k0kubun / Hamlit

Licence: other
High Performance Haml Implementation

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Hamlit

Carbone
Fast and simple report generator, from JSON to pdf, xslx, docx, odt...
Stars: ✭ 487 (-45.77%)
Mutual labels:  template-engine
Handlebars Rust
Rust templating with Handlebars
Stars: ✭ 632 (-29.62%)
Mutual labels:  template-engine
Jet
Jet template engine
Stars: ✭ 756 (-15.81%)
Mutual labels:  template-engine
Grmustache.swift
Flexible Mustache templates for Swift
Stars: ✭ 538 (-40.09%)
Mutual labels:  template-engine
Latte
☕ Latte: the intuitive and fast template engine for those who want the most secure PHP sites.
Stars: ✭ 616 (-31.4%)
Mutual labels:  template-engine
Blade
🚀 Lightning fast and elegant mvc framework for Java8
Stars: ✭ 5,569 (+520.16%)
Mutual labels:  template-engine
Microwebsrv
A micro HTTP Web server that supports WebSockets, html/python language templating and routing handlers, for MicroPython (used on Pycom modules & ESP32)
Stars: ✭ 420 (-53.23%)
Mutual labels:  template-engine
Selmer
A fast, Django inspired template system in Clojure.
Stars: ✭ 801 (-10.8%)
Mutual labels:  template-engine
Ejsexcel
nodejs excel template engine. node export excel
Stars: ✭ 621 (-30.85%)
Mutual labels:  template-engine
Handlebars.net
A real .NET Handlebars engine
Stars: ✭ 723 (-19.49%)
Mutual labels:  template-engine
Blade
🔪 A standalone version of Laravel's Blade templating engine for use outside of Laravel.
Stars: ✭ 542 (-39.64%)
Mutual labels:  template-engine
J2html
Java to HTML generator. Enjoy typesafe HTML generation.
Stars: ✭ 604 (-32.74%)
Mutual labels:  template-engine
Koa Views
Template rendering middleware for koa (hbs, swig, pug, anything! ✨)
Stars: ✭ 682 (-24.05%)
Mutual labels:  template-engine
Twirl
Twirl is Play's default template engine
Stars: ✭ 498 (-44.54%)
Mutual labels:  template-engine
Dot Dom
.dom is a tiny (512 byte) template engine that uses virtual DOM and some of react principles
Stars: ✭ 757 (-15.7%)
Mutual labels:  template-engine
Fenom
Template Engine for PHP
Stars: ✭ 426 (-52.56%)
Mutual labels:  template-engine
Liquidjs
A simple, expressive, safe and Shopify compatible template engine in pure JavaScript.
Stars: ✭ 638 (-28.95%)
Mutual labels:  template-engine
Bars
Bars is a lightweight high performance HTML aware templating engine. Bars emits DOM rather than DOM-strings, this means the DOM state is preserved even if data updates happen.
Stars: ✭ 5 (-99.44%)
Mutual labels:  template-engine
Gorazor
Razor view engine for go
Stars: ✭ 772 (-14.03%)
Mutual labels:  template-engine
Inja
A Template Engine for Modern C++
Stars: ✭ 715 (-20.38%)
Mutual labels:  template-engine

Hamlit

Gem Version test

Hamlit is a high performance Haml implementation.

Introduction

What is Hamlit?

Hamlit is another implementation of Haml. With some limitations by design for performance, Hamlit is 1.94x times faster than original haml gem in this benchmark, which is an HTML-escaped version of slim-template/slim's one for fairness. (Result on Travis)

Hamlit Benchmark
      hamlit v2.13.0:   247404.4 i/s
        erubi v1.9.0:   244356.4 i/s - 1.01x slower
         slim v4.1.0:   238254.3 i/s - 1.04x slower
         faml v0.8.1:   197293.2 i/s - 1.25x slower
         haml v5.2.0:   127834.4 i/s - 1.94x slower

Why is Hamlit faster?

Less string concatenation by design

As written in limitations, Hamlit drops some not-so-important features which require works on runtime. With the optimized language design, we can reduce the string concatenation to build attributes.

Static analyzer

Hamlit analyzes Ruby expressions with Ripper and render it on compilation if the expression is static. And Hamlit can also compile string literal with string interpolation to reduce string allocation and concatenation on runtime.

C extension to build attributes

While Hamlit has static analyzer and static attributes are rendered on compilation, dynamic attributes must be rendered on runtime. So Hamlit optimizes rendering on runtime with C extension.

Usage

Hamlit currently supports Ruby 2.1 and higher. See REFERENCE.md for detail features of Hamlit.

Rails

Add this line to your application's Gemfile or just replace gem "haml" with gem "hamlit". It enables rendering by Hamlit for *.haml automatically.

gem 'hamlit'

If you want to use view generator, consider using hamlit-rails.

Sinatra

Replace gem "haml" with gem "hamlit" in Gemfile, and require "hamlit".

While Haml disables escape_html option by default, Hamlit enables it for security. If you want to disable it, please write:

set :haml, { escape_html: false }

Command line interface

You can see compiled code or rendering result with "hamlit" command.

$ gem install hamlit
$ hamlit --help
Commands:
  hamlit compile HAML    # Show compile result
  hamlit help [COMMAND]  # Describe available commands or one specific command
  hamlit parse HAML      # Show parse result
  hamlit render HAML     # Render haml template
  hamlit temple HAML     # Show temple intermediate expression

$ cat in.haml
- user_id = 123
%a{ href: "/users/#{user_id}" }

# Show compiled code
$ hamlit compile in.haml
_buf = [];  user_id = 123;
; _buf << ("<a href='/users/".freeze); _buf << (::Hamlit::Utils.escape_html((user_id))); _buf << ("'></a>\n".freeze); _buf = _buf.join

# Render html
$ hamlit render in.haml
<a href='/users/123'></a>

Contributing

Test latest version

# Gemfile
gem 'hamlit', github: 'k0kubun/hamlit', submodules: true

Development

Contributions are welcomed. It'd be good to see Temple's EXPRESSIONS.md to learn Temple which is a template engine framework used in Hamlit.

$ git clone --recursive https://github.com/k0kubun/hamlit
$ cd hamlit
$ bundle install

# Run all tests
$ bundle exec rake test

# Run one test
$ bundle exec ruby -Ilib:test -rtest_helper test/hamlit/line_number_test.rb -l 12

# Show compiling/rendering result of some template
$ bundle exec exe/hamlit compile in.haml
$ bundle exec exe/hamlit render in.haml

# Use rails app to debug Hamlit
$ cd sample/rails
$ bundle install
$ bundle exec rails s

Reporting an issue

Please report an issue with following information:

  • Full error backtrace
  • Haml template
  • Ruby version
  • Hamlit version
  • Rails/Sinatra version

Coding styles

Please follow the existing coding styles and do not send patches including cosmetic changes.

License

Copyright (c) 2015 Takashi Kokubun

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].