• Stars
    star
    979
  • Rank 44,919 (Top 1.0 %)
  • Language
    Ruby
  • License
    Other
  • Created about 9 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

High Performance Haml Implementation

Hamlit

Gem Version test

Hamlit is a high performance Haml implementation.

Project status

Hamlit's implementation was copied to Haml 6. From Haml 6, you don't need to switch to Hamlit.

Both Haml 6 and Hamlit are still maintained by k0kubun. While you don't need to immediately deprecate Hamlit, Haml 6 has more maintainers and you'd better start a new project with Haml rather than Hamlit, given no performance difference between them.

Introduction

What is Hamlit?

Hamlit is another implementation of Haml. With some Hamlit's characteristics for performance, Hamlit is 1.94x times faster than the original Haml 5 in this benchmark, which is an HTML-escaped version of slim-template/slim's one for fairness.

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 fast?

Less string concatenation by design

As written in Hamlit's characteristics, 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

See REFERENCE.md for details.

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

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

More Repositories

1

pp

Colored pretty printer for Go language
Go
1,679
star
2

md2key

Convert markdown to keynote
Ruby
977
star
3

xremap

Key remapper for X11 and Wayland
Rust
770
star
4

Nocturn

Multi-platform Twitter Client built with React, Redux and Electron
JavaScript
714
star
5

gitstar-ranking

GitHub star ranking for users, organizations and repositories
Kotlin
700
star
6

llrb

LLVM-based JIT Compiler for Ruby
C
303
star
7

rack-user_agent

Rack::Request extension for handling User-Agent
Ruby
187
star
8

activerecord-precount

N+1 count query killer for ActiveRecord
Ruby
154
star
9

activerecord-precounter

Yet Another N+1 COUNT Query Killer for ActiveRecord
Ruby
102
star
10

go-ansi

Windows-portable ANSI escape sequence utility for Go language
Go
85
star
11

tetris

TETRIS for your terminal
Go
76
star
12

yarv-mjit

MRI method JIT compiler based on original stack-based YARV instructions (Development Repository of ruby/ruby#1782, already merged)
Ruby
65
star
13

itamae-plugin-recipe-rbenv

Itamae/MItamae plugin to install ruby with rbenv
Ruby
56
star
14

jjvm

JVM implementation written in Java
Java
53
star
15

karabiner-ruby

Lightweight keyremap configuration DSL for Karabiner
Ruby
53
star
16

ruby-jit-challenge

Tutorial to write a Ruby JIT
Ruby
51
star
17

itamae-go

Go implementation of itamae embedding mruby
Go
50
star
18

dotfiles

Bootstrap development environment
Shell
49
star
19

hescape

C library for fast HTML escape using SSE instructions
C
48
star
20

railsbench

Rails 6.1 version of headius/pgrailsbench with database seeds
Ruby
43
star
21

gem-default

Change a non-default gem to a default gem in your local environment
Ruby
37
star
22

rebuild

Development environment bootstrap automation toolkit for OSX
Ruby
31
star
23

vim-open-github

Quickly open your current buffer in GitHub.
Ruby
29
star
24

graphql-query-builder

GraphQL query builder for Java
Java
23
star
25

perf-profile

Profiling C code with Linux perf made easy
Python
19
star
26

wrap-bootstrap-rails

Rails plugin generator for Wrap Bootstrap design templates
Ruby
18
star
27

gosick

Scheme implementation by Go language
Go
18
star
28

hescape-ruby

HTML escape utility for Ruby
Ruby
17
star
29

twitter-auth

Twitter access token generator for CLI
Go
14
star
30

fluent-logger-go

A structured logger for Fluentd in Golang
Go
13
star
31

thunderbolt

Twitter client using Streaming API in Go language
Go
13
star
32

lineprof

Easy-to-use line profiler for Ruby
Ruby
13
star
33

itamae-template

Itamae template generator for roles and cookbooks
Ruby
11
star
34

stackflame

Stackflame provides a simple API to deal with Flamegraph of stackprof
Ruby
9
star
35

itamae-plugin-recipe-docker

Itamae recipe to install docker
Ruby
9
star
36

ghq-cache

Show frequently used repositories first in ghq list
Ruby
9
star
37

github_api-v4-client

A very thin GitHub GraphQL API v4 client
Ruby
7
star
38

go-keybind

Multi-platform terminal key input reader for Go language
Go
7
star
39

clannad

C language compiler
C
7
star
40

action-slack

Notify Slack with incoming webhook for GitHub Actions
TypeScript
6
star
41

tomodachi

Automatic follow back tool with Twitter streaming API
Ruby
5
star
42

twitter

Tiny twitter client library for Go language
Go
5
star
43

dwarftree

A wrapper of objdump --dwarf=info to visualize an object's structure and show code size
Ruby
5
star
44

legacy-dotfiles

Configuration for my client machines
Common Lisp
4
star
45

rack-stackprof

Periodically dump StackProf profile result to `tmp` with easy-to-understand filenames
Ruby
4
star
46

go-termios

Go bindings for termios
Go
4
star
47

misc

Miscellaneous scripts and stuff
JavaScript
4
star
48

github-stream

GitHub Events API v3 client for Go language
Go
3
star
49

ajax_render

Rails plugin to simplify your ajax implementation
Ruby
3
star
50

isucon4-qualifier

My answer for ISUCON4 qualifier
Go
3
star
51

sandal

Fault-aware model checker for message passing systems
Go
3
star
52

perf

Use Linux perf for some region of Ruby code easily
Ruby
3
star
53

rockstar

Colorful GitHub user summarizer
Go
3
star
54

mitamae-plugin-resource-deploy_directory

Fork of mitamae-plugin-resource-deploy_revision to deploy directory instead of git repository
Ruby
3
star
55

itamae-plugin-resource-ghq

Itamae resource plugin to manage repositories with ghq
Ruby
3
star
56

itamae-plugin-resource-cask

Itamae resource plugin for homebrew cask
Ruby
2
star
57

chrome-response-time

Chrome extension to show response time on badge
JavaScript
2
star
58

ruby-color

ruby-color foo.rb
Ruby
2
star
59

mitamae-plugin-resource-cron

MItamae plugin to reproduce the behavior of cron resource in Chef
Ruby
2
star
60

ruboty

My Ruboty configuration
Ruby
2
star
61

sigcdump

Sigdump for C backtrace
Ruby
2
star
62

userstream

Twitter UserStream client with OAuth for Go language
Go
2
star
63

xraise

Fast X Window Raiser
Rust
2
star
64

libx11-ruby

Ruby binding of libx11 mostly for xlib
Ruby
2
star
65

mjit-disable

Unofficial gem to disable MJIT dynamically
Ruby
1
star
66

itamae-sandbox

Ruby
1
star
67

erb-trim

An ERB extension that supports <%-=
Ruby
1
star
68

PKGBUILDs

PKGBUILDs for Arch Linux
Shell
1
star
69

GomokuAI

Artificial Intelligence for Gomoku
C++
1
star
70

picturesque

Personal web server for image distribution
Go
1
star
71

changelogger

Local file change logger
Go
1
star
72

ruby-prehistory

A repository generated by https://github.com/yhara/ruby-prehistory
C
1
star
73

ruby-cvs

cvs2git from https://github.com/takahashim/rhg-repository
C
1
star
74

isucon2-ruby

My answer for ISUCON2
Ruby
1
star
75

mitamae-plugin-recipe-rvm

MItamae plugin similar to sous-chefs/rvm
Ruby
1
star
76

ruboty-ghibli

A Ruboty plugin
Ruby
1
star
77

mitamae-plugin-recipe-buildpack

MItamae plugin to run heroku-buildpack
Ruby
1
star
78

submarine

Ruby
1
star
79

erb-indent

ERB with de-indentation
Ruby
1
star
80

vagrant-box-arch

Arch Linux Vagrant box for VirtualBox provider
1
star
81

lambda-gyazo-s3

Gyazo server clone implemented with AWS Lambda and API Gateway
Java
1
star
82

each_with_rank

Rank iterator for Enumerable
Ruby
1
star
83

pr_viewer

Pull requests viewer
Go
1
star