hamlit 2.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.travis.yml +47 -0
  4. data/CHANGELOG.md +702 -0
  5. data/Gemfile +30 -0
  6. data/LICENSE.txt +44 -0
  7. data/README.md +150 -0
  8. data/REFERENCE.md +272 -0
  9. data/Rakefile +117 -0
  10. data/benchmark/boolean_attribute.haml +6 -0
  11. data/benchmark/class_attribute.haml +5 -0
  12. data/benchmark/common_attribute.haml +3 -0
  13. data/benchmark/data_attribute.haml +4 -0
  14. data/benchmark/dynamic_attributes/boolean_attribute.haml +4 -0
  15. data/benchmark/dynamic_attributes/class_attribute.haml +4 -0
  16. data/benchmark/dynamic_attributes/common_attribute.haml +2 -0
  17. data/benchmark/dynamic_attributes/data_attribute.haml +2 -0
  18. data/benchmark/dynamic_attributes/id_attribute.haml +2 -0
  19. data/benchmark/dynamic_boolean_attribute.haml +4 -0
  20. data/benchmark/dynamic_merger/benchmark.rb +25 -0
  21. data/benchmark/dynamic_merger/hello.haml +50 -0
  22. data/benchmark/dynamic_merger/hello.string +50 -0
  23. data/benchmark/etc/attribute_builder.haml +5 -0
  24. data/benchmark/etc/real_sample.haml +888 -0
  25. data/benchmark/etc/real_sample.rb +11 -0
  26. data/benchmark/etc/static_analyzer.haml +1 -0
  27. data/benchmark/etc/string_interpolation.haml +2 -0
  28. data/benchmark/etc/tags.haml +3 -0
  29. data/benchmark/etc/tags_loop.haml +2 -0
  30. data/benchmark/ext/build_data.rb +17 -0
  31. data/benchmark/ext/build_id.rb +13 -0
  32. data/benchmark/id_attribute.haml +3 -0
  33. data/benchmark/plain.haml +4 -0
  34. data/benchmark/script.haml +4 -0
  35. data/benchmark/slim/LICENSE +21 -0
  36. data/benchmark/slim/context.rb +11 -0
  37. data/benchmark/slim/run-benchmarks.rb +94 -0
  38. data/benchmark/slim/view.erb +23 -0
  39. data/benchmark/slim/view.haml +18 -0
  40. data/benchmark/slim/view.slim +17 -0
  41. data/benchmark/utils/benchmark_ips_extension.rb +43 -0
  42. data/bin/bench +77 -0
  43. data/bin/console +11 -0
  44. data/bin/ruby +3 -0
  45. data/bin/setup +7 -0
  46. data/bin/stackprof +27 -0
  47. data/bin/test +24 -0
  48. data/exe/hamlit +6 -0
  49. data/ext/hamlit/extconf.rb +10 -0
  50. data/ext/hamlit/hamlit.c +555 -0
  51. data/ext/hamlit/hescape.c +108 -0
  52. data/ext/hamlit/hescape.h +20 -0
  53. data/hamlit.gemspec +47 -0
  54. data/lib/hamlit.rb +11 -0
  55. data/lib/hamlit/attribute_builder.rb +175 -0
  56. data/lib/hamlit/attribute_compiler.rb +125 -0
  57. data/lib/hamlit/attribute_parser.rb +110 -0
  58. data/lib/hamlit/cli.rb +130 -0
  59. data/lib/hamlit/compiler.rb +97 -0
  60. data/lib/hamlit/compiler/children_compiler.rb +112 -0
  61. data/lib/hamlit/compiler/comment_compiler.rb +36 -0
  62. data/lib/hamlit/compiler/doctype_compiler.rb +46 -0
  63. data/lib/hamlit/compiler/script_compiler.rb +106 -0
  64. data/lib/hamlit/compiler/silent_script_compiler.rb +24 -0
  65. data/lib/hamlit/compiler/tag_compiler.rb +76 -0
  66. data/lib/hamlit/dynamic_merger.rb +67 -0
  67. data/lib/hamlit/engine.rb +38 -0
  68. data/lib/hamlit/error.rb +15 -0
  69. data/lib/hamlit/escapable.rb +13 -0
  70. data/lib/hamlit/filters.rb +75 -0
  71. data/lib/hamlit/filters/base.rb +12 -0
  72. data/lib/hamlit/filters/cdata.rb +20 -0
  73. data/lib/hamlit/filters/coffee.rb +17 -0
  74. data/lib/hamlit/filters/css.rb +33 -0
  75. data/lib/hamlit/filters/erb.rb +10 -0
  76. data/lib/hamlit/filters/escaped.rb +22 -0
  77. data/lib/hamlit/filters/javascript.rb +33 -0
  78. data/lib/hamlit/filters/less.rb +20 -0
  79. data/lib/hamlit/filters/markdown.rb +10 -0
  80. data/lib/hamlit/filters/plain.rb +29 -0
  81. data/lib/hamlit/filters/preserve.rb +22 -0
  82. data/lib/hamlit/filters/ruby.rb +10 -0
  83. data/lib/hamlit/filters/sass.rb +15 -0
  84. data/lib/hamlit/filters/scss.rb +15 -0
  85. data/lib/hamlit/filters/text_base.rb +25 -0
  86. data/lib/hamlit/filters/tilt_base.rb +49 -0
  87. data/lib/hamlit/force_escapable.rb +29 -0
  88. data/lib/hamlit/helpers.rb +15 -0
  89. data/lib/hamlit/html.rb +14 -0
  90. data/lib/hamlit/identity.rb +13 -0
  91. data/lib/hamlit/object_ref.rb +30 -0
  92. data/lib/hamlit/parser.rb +49 -0
  93. data/lib/hamlit/parser/MIT-LICENSE +20 -0
  94. data/lib/hamlit/parser/README.md +30 -0
  95. data/lib/hamlit/parser/haml_buffer.rb +348 -0
  96. data/lib/hamlit/parser/haml_compiler.rb +553 -0
  97. data/lib/hamlit/parser/haml_error.rb +61 -0
  98. data/lib/hamlit/parser/haml_helpers.rb +727 -0
  99. data/lib/hamlit/parser/haml_options.rb +286 -0
  100. data/lib/hamlit/parser/haml_parser.rb +800 -0
  101. data/lib/hamlit/parser/haml_util.rb +288 -0
  102. data/lib/hamlit/parser/haml_xss_mods.rb +109 -0
  103. data/lib/hamlit/rails_helpers.rb +51 -0
  104. data/lib/hamlit/rails_template.rb +59 -0
  105. data/lib/hamlit/railtie.rb +10 -0
  106. data/lib/hamlit/ruby_expression.rb +32 -0
  107. data/lib/hamlit/string_splitter.rb +19 -0
  108. data/lib/hamlit/template.rb +28 -0
  109. data/lib/hamlit/utils.rb +20 -0
  110. data/lib/hamlit/version.rb +4 -0
  111. metadata +392 -0
data/Gemfile ADDED
@@ -0,0 +1,30 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) do |repo_name|
4
+ repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
5
+ "https://github.com/#{repo_name}.git"
6
+ end
7
+
8
+ # Specify your gem's dependencies in hamlit.gemspec
9
+ gemspec
10
+
11
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2.2')
12
+ gem 'rack', '< 2'
13
+ end
14
+
15
+ gem 'benchmark-ips', '2.3.0'
16
+ gem 'maxitest'
17
+ gem 'pry'
18
+
19
+ if /java/ === RUBY_PLATFORM # JRuby
20
+ gem 'pandoc-ruby'
21
+ else
22
+ gem 'redcarpet'
23
+
24
+ if RUBY_PLATFORM !~ /mswin|mingw/ && RUBY_ENGINE != 'truffleruby'
25
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.7.0') # Travis cannot compile ruby.h with C++
26
+ gem 'faml'
27
+ end
28
+ gem 'stackprof'
29
+ end
30
+ end
@@ -0,0 +1,44 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Takashi Kokubun
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
23
+ lib/hamlit/parser/*.rb and test/haml/* are:
24
+
25
+ Copyright (c) 2006-2009 Hampton Catlin and Natalie Weizenbaum
26
+
27
+ Permission is hereby granted, free of charge, to any person obtaining
28
+ a copy of this software and associated documentation files (the
29
+ "Software"), to deal in the Software without restriction, including
30
+ without limitation the rights to use, copy, modify, merge, publish,
31
+ distribute, sublicense, and/or sell copies of the Software, and to
32
+ permit persons to whom the Software is furnished to do so, subject to
33
+ the following conditions:
34
+
35
+ The above copyright notice and this permission notice shall be
36
+ included in all copies or substantial portions of the Software.
37
+
38
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
39
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
40
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
41
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
42
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
43
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
44
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,150 @@
1
+ # Hamlit
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/hamlit.svg)](http://badge.fury.io/rb/hamlit)
4
+ [![Build Status](https://travis-ci.org/k0kubun/hamlit.svg?branch=master)](https://travis-ci.org/k0kubun/hamlit)
5
+
6
+ Hamlit is a high performance [Haml](https://github.com/haml/haml) implementation.
7
+
8
+ ## Introduction
9
+
10
+ ### What is Hamlit?
11
+ Hamlit is another implementation of [Haml](https://github.com/haml/haml).
12
+ With some [limitations](REFERENCE.md#limitations) by design for performance,
13
+ Hamlit is **2.39x times faster** than original haml gem in [this benchmark](benchmark/slim/run-benchmarks.rb),
14
+ which is an HTML-escaped version of [slim-template/slim's one](https://github.com/slim-template/slim/blob/v3.0.8/benchmarks/run-benchmarks.rb) for fairness. ([Result on Travis](https://travis-ci.org/k0kubun/hamlit/jobs/236567391))
15
+
16
+ <img src="https://i.gyazo.com/0f0c0362b6bd69f82715bec1d8caa191.png" width="600px" alt="Hamlit Benchmark"/>
17
+
18
+ ```
19
+ hamlit v2.8.1: 131048.9 i/s
20
+ erubi v1.6.0: 125445.4 i/s - 1.04x slower
21
+ slim v3.0.8: 121390.4 i/s - 1.08x slower
22
+ faml v0.8.1: 100750.5 i/s - 1.30x slower
23
+ haml v5.0.1: 54882.6 i/s - 2.39x slower
24
+ ```
25
+
26
+ ### Why is Hamlit faster?
27
+
28
+ #### Less string concatenation by design
29
+ As written in [limitations](REFERENCE.md#limitations), Hamlit drops some not-so-important features which require
30
+ works on runtime. With the optimized language design, we can reduce the string concatenation
31
+ to build attributes.
32
+
33
+ #### Static analyzer
34
+ Hamlit analyzes Ruby expressions with Ripper and render it on compilation if the expression
35
+ is static. And Hamlit can also compile string literal with string interpolation to reduce
36
+ string allocation and concatenation on runtime.
37
+
38
+ #### C extension to build attributes
39
+ While Hamlit has static analyzer and static attributes are rendered on compilation,
40
+ dynamic attributes must be rendered on runtime. So Hamlit optimizes rendering on runtime
41
+ with C extension.
42
+
43
+ ## Usage
44
+
45
+ Hamlit currently supports Ruby 2.1 and higher. See [REFERENCE.md](REFERENCE.md) for detail features of Hamlit.
46
+
47
+ ### Rails
48
+
49
+ Add this line to your application's Gemfile or just replace `gem "haml"` with `gem "hamlit"`.
50
+ It enables rendering by Hamlit for \*.haml automatically.
51
+
52
+ ```rb
53
+ gem 'hamlit'
54
+ ```
55
+
56
+ If you want to use view generator, consider using [hamlit-rails](https://github.com/mfung/hamlit-rails).
57
+
58
+ ### Sinatra
59
+
60
+ Replace `gem "haml"` with `gem "hamlit"` in Gemfile, and require "hamlit".
61
+
62
+ While Haml disables `escape_html` option by default, Hamlit enables it for security.
63
+ If you want to disable it, please write:
64
+
65
+ ```rb
66
+ set :haml, { escape_html: false }
67
+ ```
68
+
69
+
70
+ ## Command line interface
71
+
72
+ You can see compiled code or rendering result with "hamlit" command.
73
+
74
+ ```bash
75
+ $ gem install hamlit
76
+ $ hamlit --help
77
+ Commands:
78
+ hamlit compile HAML # Show compile result
79
+ hamlit help [COMMAND] # Describe available commands or one specific command
80
+ hamlit parse HAML # Show parse result
81
+ hamlit render HAML # Render haml template
82
+ hamlit temple HAML # Show temple intermediate expression
83
+
84
+ $ cat in.haml
85
+ - user_id = 123
86
+ %a{ href: "/users/#{user_id}" }
87
+
88
+ # Show compiled code
89
+ $ hamlit compile in.haml
90
+ _buf = []; user_id = 123;
91
+ ; _buf << ("<a href='/users/".freeze); _buf << (::Hamlit::Utils.escape_html((user_id))); _buf << ("'></a>\n".freeze); _buf = _buf.join
92
+
93
+ # Render html
94
+ $ hamlit render in.haml
95
+ <a href='/users/123'></a>
96
+ ```
97
+
98
+ ## Contributing
99
+
100
+ ### Test latest version
101
+
102
+ ```rb
103
+ # Gemfile
104
+ gem 'hamlit', github: 'k0kubun/hamlit', submodules: true
105
+ ```
106
+
107
+ ### Development
108
+
109
+ Contributions are welcomed. It'd be good to see
110
+ [Temple's EXPRESSIONS.md](https://github.com/judofyr/temple/blob/v0.7.6/EXPRESSIONS.md)
111
+ to learn Temple which is a template engine framework used in Hamlit.
112
+
113
+ ```bash
114
+ $ git clone --recursive https://github.com/k0kubun/hamlit
115
+ $ cd hamlit
116
+ $ bundle install
117
+
118
+ # Run all tests
119
+ $ bundle exec rake test
120
+
121
+ # Run one test
122
+ $ bundle exec ruby -Ilib:test -rtest_helper test/hamlit/line_number_test.rb -l 12
123
+
124
+ # Show compiling/rendering result of some template
125
+ $ bundle exec exe/hamlit compile in.haml
126
+ $ bundle exec exe/hamlit render in.haml
127
+
128
+ # Use rails app to debug Hamlit
129
+ $ cd sample/rails
130
+ $ bundle install
131
+ $ bundle exec rails s
132
+ ```
133
+
134
+ ### Reporting an issue
135
+
136
+ Please report an issue with following information:
137
+
138
+ - Full error backtrace
139
+ - Haml template
140
+ - Ruby version
141
+ - Hamlit version
142
+ - Rails/Sinatra version
143
+
144
+ ### Coding styles
145
+
146
+ Please follow the existing coding styles and do not send patches including cosmetic changes.
147
+
148
+ ## License
149
+
150
+ Copyright (c) 2015 Takashi Kokubun
@@ -0,0 +1,272 @@
1
+ # Hamlit
2
+
3
+ Basically Hamlit is the same as Haml.
4
+ See [Haml's tutorial](http://haml.info/tutorial.html) if you are not familiar with Haml's syntax.
5
+
6
+ [REFERENCE - Haml Documentation](http://haml.info/docs/yardoc/file.REFERENCE.html)
7
+
8
+ ## Supported features
9
+
10
+ See [Haml's reference](http://haml.info/docs/yardoc/file.REFERENCE.html)
11
+ for full features in original implementation.
12
+
13
+ - [ ] Using Haml
14
+ - [x] Rails XSS Protection
15
+ - [x] Ruby Module
16
+ - [x] Options
17
+ - [ ] Encodings
18
+ - [x] Plain Text
19
+ - [x] Escaping: \
20
+ - [ ] HTML Elements
21
+ - [x] Element Name: %
22
+ - [ ] Attributes: `
23
+ - [x] :class and :id Attributes
24
+ - [x] HTML-style Attributes: ()
25
+ - [x] Ruby 1.9-style Hashes
26
+ - [ ] Attribute Methods
27
+ - [x] Boolean Attributes
28
+ - [x] HTML5 Custom Data Attributes
29
+ - [x] Class and ID: . and #
30
+ - Implicit Div Elements
31
+ - [x] Empty (void) Tags: /
32
+ - [x] Whitespace Removal: > and <
33
+ - [x] Object Reference: []
34
+ - [x] Doctype: !!!
35
+ - [x] Comments
36
+ - [x] HTML Comments: /
37
+ - [x] Conditional Comments: /[]
38
+ - [x] Haml Comments: -#
39
+ - [x] Ruby Evaluation
40
+ - [x] Inserting Ruby: =
41
+ - [x] Running Ruby: -
42
+ - [x] Ruby Blocks
43
+ - [x] Whitespace Preservation: ~
44
+ - [x] Ruby Interpolation: #{}
45
+ - [x] Escaping HTML: &=
46
+ - [x] Unescaping HTML: !=
47
+ - [ ] Filters
48
+ - [x] :cdata
49
+ - [x] :coffee
50
+ - [x] :css
51
+ - [x] :erb
52
+ - [x] :escaped
53
+ - [x] :javascript
54
+ - [x] :less
55
+ - [x] :markdown
56
+ - [ ] :maruku
57
+ - [x] :plain
58
+ - [x] :preserve
59
+ - [x] :ruby
60
+ - [x] :sass
61
+ - [x] :scss
62
+ - [ ] :textile
63
+ - [ ] Custom Filters
64
+ - [x] Helper Methods
65
+ - [x] preserve
66
+ - [x] surround
67
+ - [x] precede
68
+ - [x] succeed
69
+ - [x] Multiline: |
70
+ - [x] Whitespace Preservation
71
+ - [ ] Helpers
72
+
73
+
74
+ ## Limitations
75
+
76
+ ### No Haml buffer
77
+ Hamlit uses `Array` as buffer for performance. So you can't touch Haml::Buffer from template when using Hamlit.
78
+
79
+ ### Haml helpers are still in development
80
+ At the same time, because some methods in `Haml::Helpers` require `Haml::Buffer`, they are not supported now.
81
+ But some helpers are supported on Rails. Some of not-implemented methods are planned to be supported.
82
+
83
+ ### Limited attributes hyphenation
84
+ In Haml, `%a{ foo: { bar: 'baz' } }` is rendered as `<a foo-bar='baz'></a>`, whatever foo is.
85
+ In Hamlit, this feature is supported only for aria and data attribute. Hamlit renders `%a{ data: { foo: 'bar' } }`
86
+ as `<a data-foo='bar'></a>` because it's data attribute. This design allows us to reduce work on runtime
87
+ and the idea is originally in [Faml](https://github.com/eagletmt/faml).
88
+
89
+ ### Limited boolean attributes
90
+ In Haml, `%a{ foo: false }` is rendered as `<a></a>`, whatever `foo` is.
91
+ In Hamlit, this feature is supported for only boolean attributes, which are defined by
92
+ http://www.w3.org/TR/xhtml1/guidelines.html or https://html.spec.whatwg.org/.
93
+ The list is the same as `ActionView::Helpers::TagHelper::BOOLEAN_ATTRIBUTES`.
94
+ In addition, aria-\* and data-\* is also regarded as boolean.
95
+
96
+ Since `foo` is not boolean attribute, `%a{ foo: false }` is rendered as `<a foo='false'></a>`
97
+ This is the same behavior as Rails helpers. Also for `%a{ foo: nil }`,
98
+ Hamlit does not remove non-boolean attributes and render `<a foo=''></a>`
99
+ (`foo` is not removed). This design allows us to reduce string concatenation and
100
+ is the only difference between Faml and Hamlit.
101
+
102
+ You may be also interested in
103
+ [hamlit/hamlit-boolean\_attributes](https://github.com/hamlit/hamlit-boolean_attributes).
104
+
105
+ ## 5 Types of Attributes
106
+
107
+ Haml has 3 types of attributes: id, class and others.
108
+ In addition, Hamlit treats aria/data and boolean attributes specially.
109
+ So there are 5 types of attributes in Hamlit.
110
+
111
+ ### id attribute
112
+ Almost the same behavior as Haml, except no hyphenation and boolean support.
113
+ Arrays are flattened, falsey values are removed (but attribute itself is not removed)
114
+ and merging multiple ids results in concatenation by "\_".
115
+
116
+ ```rb
117
+ # Input
118
+ #foo{ id: 'bar' }
119
+ %div{ id: %w[foo bar] }
120
+ %div{ id: ['foo', false, ['bar', nil]] }
121
+ %div{ id: false }
122
+
123
+ # Output
124
+ <div id='foo_bar'></span>
125
+ <div id='foo_bar'></span>
126
+ <div id='foo_bar'></span>
127
+ <div id=''></span>
128
+ ```
129
+
130
+ ### class attribute
131
+ Almost the same behavior as Haml, except no hyphenation and boolean support.
132
+ Arrays are flattened, falsey values are removed (but attribute itself is not removed)
133
+ and merging multiple classes results in unique alphabetical sort.
134
+
135
+ ```rb
136
+ # Input
137
+ .d.a(class='b c'){ class: 'c a' }
138
+ %div{ class: 'd c b a' }
139
+ %div{ class: ['d', nil, 'c', [false, 'b', 'a']] }
140
+ %div{ class: false }
141
+
142
+ # Output
143
+ <div class='a b c d'></div>
144
+ <div class='d c b a'></div>
145
+ <div class='d c b a'></div>
146
+ <div class=''></div>
147
+ ```
148
+
149
+ ### aria / data attribute
150
+ Completely compatible with Haml, hyphenation and boolean are supported.
151
+
152
+ ```rb
153
+ # Input
154
+ %div{ data: { disabled: true } }
155
+ %div{ data: { foo: 'bar' } }
156
+
157
+ # Output
158
+ <div data-disabled></div>
159
+ <div data-foo='bar'></div>
160
+ ```
161
+
162
+ aria attribute works in the same way as data attribute.
163
+
164
+ ### boolean attributes
165
+ No hyphenation but complete boolean support.
166
+
167
+ ```rb
168
+ # Input
169
+ %div{ disabled: 'foo' }
170
+ %div{ disabled: true }
171
+ %div{ disabled: false }
172
+
173
+ # Output
174
+ <div disabled='foo'></div>
175
+ <div disabled></div>
176
+ <div></div>
177
+ ```
178
+
179
+ List of boolean attributes is:
180
+
181
+ ```
182
+ disabled readonly multiple checked autobuffer autoplay controls loop selected hidden scoped async
183
+ defer reversed ismap seamless muted required autofocus novalidate formnovalidate open pubdate
184
+ itemscope allowfullscreen default inert sortable truespeed typemustmatch
185
+ ```
186
+
187
+ If you want to customize the list of boolean attributes, you can use
188
+ [hamlit/hamlit-boolean\_attributes](https://github.com/hamlit/hamlit-boolean_attributes).
189
+
190
+ "aria-\*" and "data-\*" are also regarded as boolean.
191
+
192
+ ### other attributes
193
+ No hyphenation and boolean support. `false` is rendered as "false" (like Rails helpers).
194
+
195
+ ```rb
196
+ # Input
197
+ %input{ value: true }
198
+ %input{ value: false }
199
+
200
+ # Output
201
+ <input value='true'>
202
+ <input value='false'>
203
+ ```
204
+
205
+ ## Engine options
206
+
207
+ | Option | Default | Feature |
208
+ |:-------|:--------|:--------|
209
+ | escape\_html | true | HTML-escape for Ruby script and interpolation. This is false in Haml. |
210
+ | escape\_attrs | true | HTML-escape for Html attributes. |
211
+ | format | :html | You can set :xhtml to change boolean attribute's format. |
212
+ | attr\_quote | `'` | You can change attribute's wrapper to `"` or something. |
213
+
214
+ ### Set options for Rails
215
+
216
+ ```rb
217
+ # config/initializers/hamlit.rb or somewhere
218
+ Hamlit::RailsTemplate.set_options attr_quote: '"'
219
+ ```
220
+
221
+ ### Set options for Sinatra
222
+
223
+ ```rb
224
+ set :haml, { attr_quote: '"' }
225
+ ```
226
+
227
+ ## Creating a custom filter
228
+
229
+ Currently it doesn't have filter registering interface compatible with Haml.
230
+ But you can easily define and register a filter using Tilt like this.
231
+
232
+ ```rb
233
+ module Hamlit
234
+ class Filters
235
+ class Es6 < TiltBase
236
+ def compile(node)
237
+ # branch with `@format` here if you want
238
+ compile_html(node)
239
+ end
240
+
241
+ private
242
+
243
+ def compile_html(node)
244
+ temple = [:multi]
245
+ temple << [:static, "<script>\n"]
246
+ temple << compile_with_tilt(node, 'es6', indent_width: 2)
247
+ temple << [:static, "\n</script>"]
248
+ temple
249
+ end
250
+ end
251
+
252
+ register :es6, Es6
253
+ end
254
+ end
255
+ ```
256
+
257
+ After requiring the script, you can do:
258
+
259
+ ```haml
260
+ :es6
261
+ const a = 1;
262
+ ```
263
+
264
+ and it's rendered as:
265
+
266
+ ```html
267
+ <script>
268
+ "use strict";
269
+
270
+ var a = 1;
271
+ </script>
272
+ ```