hamlit 2.9.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.travis.yml +45 -0
  4. data/CHANGELOG.md +666 -0
  5. data/Gemfile +28 -0
  6. data/LICENSE.txt +44 -0
  7. data/README.md +146 -0
  8. data/REFERENCE.md +266 -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/etc/attribute_builder.haml +5 -0
  21. data/benchmark/etc/real_sample.haml +888 -0
  22. data/benchmark/etc/real_sample.rb +11 -0
  23. data/benchmark/etc/static_analyzer.haml +1 -0
  24. data/benchmark/etc/string_interpolation.haml +2 -0
  25. data/benchmark/etc/tags.haml +3 -0
  26. data/benchmark/etc/tags_loop.haml +2 -0
  27. data/benchmark/ext/build_data.rb +17 -0
  28. data/benchmark/ext/build_id.rb +13 -0
  29. data/benchmark/id_attribute.haml +3 -0
  30. data/benchmark/plain.haml +4 -0
  31. data/benchmark/script.haml +4 -0
  32. data/benchmark/slim/LICENSE +21 -0
  33. data/benchmark/slim/context.rb +11 -0
  34. data/benchmark/slim/run-benchmarks.rb +94 -0
  35. data/benchmark/slim/view.erb +23 -0
  36. data/benchmark/slim/view.haml +18 -0
  37. data/benchmark/slim/view.slim +17 -0
  38. data/benchmark/utils/benchmark_ips_extension.rb +43 -0
  39. data/bin/bench +77 -0
  40. data/bin/console +11 -0
  41. data/bin/ruby +3 -0
  42. data/bin/setup +7 -0
  43. data/bin/stackprof +27 -0
  44. data/bin/test +24 -0
  45. data/exe/hamlit +6 -0
  46. data/ext/hamlit/extconf.rb +10 -0
  47. data/ext/hamlit/hamlit.c +553 -0
  48. data/ext/hamlit/hescape.c +108 -0
  49. data/ext/hamlit/hescape.h +20 -0
  50. data/hamlit.gemspec +45 -0
  51. data/lib/hamlit.rb +11 -0
  52. data/lib/hamlit/attribute_builder.rb +173 -0
  53. data/lib/hamlit/attribute_compiler.rb +123 -0
  54. data/lib/hamlit/attribute_parser.rb +110 -0
  55. data/lib/hamlit/cli.rb +130 -0
  56. data/lib/hamlit/compiler.rb +97 -0
  57. data/lib/hamlit/compiler/children_compiler.rb +112 -0
  58. data/lib/hamlit/compiler/comment_compiler.rb +36 -0
  59. data/lib/hamlit/compiler/doctype_compiler.rb +46 -0
  60. data/lib/hamlit/compiler/script_compiler.rb +101 -0
  61. data/lib/hamlit/compiler/silent_script_compiler.rb +24 -0
  62. data/lib/hamlit/compiler/tag_compiler.rb +74 -0
  63. data/lib/hamlit/engine.rb +37 -0
  64. data/lib/hamlit/error.rb +15 -0
  65. data/lib/hamlit/escapable.rb +13 -0
  66. data/lib/hamlit/filters.rb +75 -0
  67. data/lib/hamlit/filters/base.rb +12 -0
  68. data/lib/hamlit/filters/cdata.rb +20 -0
  69. data/lib/hamlit/filters/coffee.rb +17 -0
  70. data/lib/hamlit/filters/css.rb +33 -0
  71. data/lib/hamlit/filters/erb.rb +10 -0
  72. data/lib/hamlit/filters/escaped.rb +22 -0
  73. data/lib/hamlit/filters/javascript.rb +33 -0
  74. data/lib/hamlit/filters/less.rb +20 -0
  75. data/lib/hamlit/filters/markdown.rb +10 -0
  76. data/lib/hamlit/filters/plain.rb +29 -0
  77. data/lib/hamlit/filters/preserve.rb +22 -0
  78. data/lib/hamlit/filters/ruby.rb +10 -0
  79. data/lib/hamlit/filters/sass.rb +15 -0
  80. data/lib/hamlit/filters/scss.rb +15 -0
  81. data/lib/hamlit/filters/text_base.rb +25 -0
  82. data/lib/hamlit/filters/tilt_base.rb +49 -0
  83. data/lib/hamlit/force_escapable.rb +29 -0
  84. data/lib/hamlit/helpers.rb +15 -0
  85. data/lib/hamlit/html.rb +14 -0
  86. data/lib/hamlit/identity.rb +13 -0
  87. data/lib/hamlit/object_ref.rb +30 -0
  88. data/lib/hamlit/parser.rb +49 -0
  89. data/lib/hamlit/parser/MIT-LICENSE +20 -0
  90. data/lib/hamlit/parser/README.md +30 -0
  91. data/lib/hamlit/parser/haml_buffer.rb +348 -0
  92. data/lib/hamlit/parser/haml_compiler.rb +553 -0
  93. data/lib/hamlit/parser/haml_error.rb +61 -0
  94. data/lib/hamlit/parser/haml_helpers.rb +727 -0
  95. data/lib/hamlit/parser/haml_options.rb +286 -0
  96. data/lib/hamlit/parser/haml_parser.rb +800 -0
  97. data/lib/hamlit/parser/haml_util.rb +288 -0
  98. data/lib/hamlit/parser/haml_xss_mods.rb +109 -0
  99. data/lib/hamlit/rails_helpers.rb +51 -0
  100. data/lib/hamlit/rails_template.rb +58 -0
  101. data/lib/hamlit/railtie.rb +10 -0
  102. data/lib/hamlit/ruby_expression.rb +32 -0
  103. data/lib/hamlit/string_splitter.rb +88 -0
  104. data/lib/hamlit/template.rb +28 -0
  105. data/lib/hamlit/utils.rb +18 -0
  106. data/lib/hamlit/version.rb +4 -0
  107. metadata +360 -0
data/Gemfile ADDED
@@ -0,0 +1,28 @@
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
+
18
+ if /java/ === RUBY_PLATFORM # JRuby
19
+ gem 'pandoc-ruby'
20
+ else
21
+ gem 'pry-byebug'
22
+ gem 'redcarpet', github: 'vmg/redcarpet' # To resolve circular require warning
23
+
24
+ if RUBY_PLATFORM !~ /mswin|mingw/
25
+ gem 'faml'
26
+ gem 'stackprof'
27
+ end
28
+ 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,146 @@
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
+ ## License
145
+
146
+ Copyright (c) 2015 Takashi Kokubun
@@ -0,0 +1,266 @@
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
+ ## 5 Types of Attributes
103
+
104
+ Haml has 3 types of attributes: id, class and others.
105
+ In addition, Hamlit treats aria/data and boolean attributes specially.
106
+ So there are 5 types of attributes in Hamlit.
107
+
108
+ ### id attribute
109
+ Almost the same behavior as Haml, except no hyphenation and boolean support.
110
+ Arrays are flattened, falsey values are removed (but attribute itself is not removed)
111
+ and merging multiple ids results in concatenation by "\_".
112
+
113
+ ```rb
114
+ # Input
115
+ #foo{ id: 'bar' }
116
+ %div{ id: %w[foo bar] }
117
+ %div{ id: ['foo', false, ['bar', nil]] }
118
+ %div{ id: false }
119
+
120
+ # Output
121
+ <div id='foo_bar'></span>
122
+ <div id='foo_bar'></span>
123
+ <div id='foo_bar'></span>
124
+ <div id=''></span>
125
+ ```
126
+
127
+ ### class attribute
128
+ Almost the same behavior as Haml, except no hyphenation and boolean support.
129
+ Arrays are flattened, falsey values are removed (but attribute itself is not removed)
130
+ and merging multiple classes results in unique alphabetical sort.
131
+
132
+ ```rb
133
+ # Input
134
+ .d.a(class='b c'){ class: 'c a' }
135
+ %div{ class: 'd c b a' }
136
+ %div{ class: ['d', nil, 'c', [false, 'b', 'a']] }
137
+ %div{ class: false }
138
+
139
+ # Output
140
+ <div class='a b c d'></div>
141
+ <div class='d c b a'></div>
142
+ <div class='d c b a'></div>
143
+ <div class=''></div>
144
+ ```
145
+
146
+ ### aria / data attribute
147
+ Completely compatible with Haml, hyphenation and boolean are supported.
148
+
149
+ ```rb
150
+ # Input
151
+ %div{ data: { disabled: true } }
152
+ %div{ data: { foo: 'bar' } }
153
+
154
+ # Output
155
+ <div data-disabled></div>
156
+ <div data-foo='bar'></div>
157
+ ```
158
+
159
+ aria attribute works in the same way as data attribute.
160
+
161
+ ### boolean attributes
162
+ No hyphenation but complete boolean support.
163
+
164
+ ```rb
165
+ # Input
166
+ %div{ disabled: 'foo' }
167
+ %div{ disabled: true }
168
+ %div{ disabled: false }
169
+
170
+ # Output
171
+ <div disabled='foo'></div>
172
+ <div disabled></div>
173
+ <div></div>
174
+ ```
175
+
176
+ List of boolean attributes is:
177
+
178
+ ```
179
+ disabled readonly multiple checked autobuffer autoplay controls loop selected hidden scoped async
180
+ defer reversed ismap seamless muted required autofocus novalidate formnovalidate open pubdate
181
+ itemscope allowfullscreen default inert sortable truespeed typemustmatch
182
+ ```
183
+
184
+ "data-\*" is also regarded as boolean.
185
+
186
+ ### other attributes
187
+ No hyphenation and boolean support. `false` is rendered as "false" (like Rails helpers).
188
+
189
+ ```rb
190
+ # Input
191
+ %input{ value: true }
192
+ %input{ value: false }
193
+
194
+ # Output
195
+ <input value='true'>
196
+ <input value='false'>
197
+ ```
198
+
199
+ ## Engine options
200
+
201
+ | Option | Default | Feature |
202
+ |:-------|:--------|:--------|
203
+ | escape\_html | true | HTML-escape for Ruby script and interpolation. This is false in Haml. |
204
+ | escape\_attrs | true | HTML-escape for Html attributes. |
205
+ | format | :html | You can set :xhtml to change boolean attribute's format. |
206
+ | attr\_quote | `'` | You can change attribute's wrapper to `"` or something. |
207
+
208
+ ### Set options for Rails
209
+
210
+ ```rb
211
+ # config/initializers/hamlit.rb or somewhere
212
+ Hamlit::RailsTemplate.set_options attr_quote: '"'
213
+ ```
214
+
215
+ ### Set options for Sinatra
216
+
217
+ ```rb
218
+ set :haml, { attr_quote: '"' }
219
+ ```
220
+
221
+ ## Creating a custom filter
222
+
223
+ Currently it doesn't have filter registering interface compatible with Haml.
224
+ But you can easily define and register a filter using Tilt like this.
225
+
226
+ ```rb
227
+ module Hamlit
228
+ class Filters
229
+ class Es6 < TiltBase
230
+ def compile(node)
231
+ # branch with `@format` here if you want
232
+ compile_html(node)
233
+ end
234
+
235
+ private
236
+
237
+ def compile_html(node)
238
+ temple = [:multi]
239
+ temple << [:static, "<script>\n"]
240
+ temple << compile_with_tilt(node, 'es6', indent_width: 2)
241
+ temple << [:static, "\n</script>"]
242
+ temple
243
+ end
244
+ end
245
+
246
+ register :es6, Es6
247
+ end
248
+ end
249
+ ```
250
+
251
+ After requiring the script, you can do:
252
+
253
+ ```haml
254
+ :es6
255
+ const a = 1;
256
+ ```
257
+
258
+ and it's rendered as:
259
+
260
+ ```html
261
+ <script>
262
+ "use strict";
263
+
264
+ var a = 1;
265
+ </script>
266
+ ```