hamlit 2.9.5-java → 2.13.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +17 -11
- data/CHANGELOG.md +52 -0
- data/Gemfile +2 -8
- data/LICENSE.txt +26 -23
- data/REFERENCE.md +13 -4
- data/benchmark/dynamic_merger/benchmark.rb +25 -0
- data/benchmark/dynamic_merger/hello.haml +50 -0
- data/benchmark/dynamic_merger/hello.string +50 -0
- data/bin/bench +3 -3
- data/bin/update-haml +125 -0
- data/ext/hamlit/hamlit.c +0 -1
- data/hamlit.gemspec +3 -1
- data/lib/hamlit/attribute_builder.rb +2 -2
- data/lib/hamlit/attribute_compiler.rb +3 -3
- data/lib/hamlit/compiler/children_compiler.rb +18 -4
- data/lib/hamlit/compiler/comment_compiler.rb +8 -5
- data/lib/hamlit/compiler/tag_compiler.rb +0 -4
- data/lib/hamlit/dynamic_merger.rb +67 -0
- data/lib/hamlit/engine.rb +5 -6
- data/lib/hamlit/filters/escaped.rb +1 -1
- data/lib/hamlit/filters/markdown.rb +1 -0
- data/lib/hamlit/filters/plain.rb +0 -4
- data/lib/hamlit/filters/preserve.rb +1 -1
- data/lib/hamlit/filters/text_base.rb +1 -1
- data/lib/hamlit/filters/tilt_base.rb +1 -1
- data/lib/hamlit/html.rb +8 -0
- data/lib/hamlit/parser.rb +6 -2
- data/lib/hamlit/parser/haml_attribute_builder.rb +164 -0
- data/lib/hamlit/parser/haml_buffer.rb +20 -130
- data/lib/hamlit/parser/haml_compiler.rb +1 -553
- data/lib/hamlit/parser/haml_error.rb +29 -25
- data/lib/hamlit/parser/haml_escapable.rb +1 -0
- data/lib/hamlit/parser/haml_generator.rb +1 -0
- data/lib/hamlit/parser/haml_helpers.rb +41 -59
- data/lib/hamlit/parser/{haml_xss_mods.rb → haml_helpers/xss_mods.rb} +20 -15
- data/lib/hamlit/parser/haml_options.rb +53 -66
- data/lib/hamlit/parser/haml_parser.rb +103 -71
- data/lib/hamlit/parser/haml_temple_engine.rb +123 -0
- data/lib/hamlit/parser/haml_util.rb +10 -40
- data/lib/hamlit/rails_template.rb +1 -1
- data/lib/hamlit/string_splitter.rb +10 -78
- data/lib/hamlit/template.rb +1 -1
- data/lib/hamlit/temple_line_counter.rb +31 -0
- data/lib/hamlit/version.rb +1 -1
- metadata +58 -24
- data/lib/hamlit/hamlit.su +0 -0
- data/lib/hamlit/parser/MIT-LICENSE +0 -20
- data/lib/hamlit/parser/README.md +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 167551d8ba270e6630258045d799582d642205cd5b8138a88d2354aa64e3ce32
|
4
|
+
data.tar.gz: d8bb77cbd98dbd61e32003cf91ace93157a6ad0143be35b29f5d4db8c54a5250
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f95304f59367a4000a54c78caafef529ce37640294f29c772f8c585a9a136746c4f599494a1f1de85c362b17fe2f3627996dc656902f48adcc90f54a2342a47e
|
7
|
+
data.tar.gz: 467b09b770eaf0ed9feae3709b772bf3eb23c17cd753c4b67aa32b26f59892ad8bc42100616bf888e794cf20da079a9f7f1f8115d1436e4c503d3d57787c7759
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -4,36 +4,42 @@ branches:
|
|
4
4
|
only:
|
5
5
|
- master
|
6
6
|
script:
|
7
|
-
-
|
7
|
+
- bundle exec rake $TASK
|
8
|
+
env:
|
9
|
+
- RUBYOPT='-w'
|
8
10
|
matrix:
|
9
11
|
include:
|
10
12
|
- rvm: 2.3.8
|
11
13
|
env: TASK=test
|
12
|
-
- rvm: 2.4.
|
14
|
+
- rvm: 2.4.9
|
13
15
|
env: TASK=test
|
14
|
-
- rvm: 2.5.
|
16
|
+
- rvm: 2.5.7
|
15
17
|
env: TASK=test
|
16
|
-
- rvm: 2.6.
|
18
|
+
- rvm: 2.6.5
|
17
19
|
env: TASK=test
|
20
|
+
- rvm: 2.7.0
|
21
|
+
env: TASK=test
|
22
|
+
- rvm: 2.7.0
|
23
|
+
env: TASK=test RUBYOPT='-w --enable-frozen-string-literal'
|
18
24
|
- rvm: ruby-head
|
19
25
|
env: TASK=test
|
20
26
|
- rvm: jruby-9.2.8.0
|
21
27
|
env: TASK=test
|
22
28
|
- rvm: truffleruby
|
23
29
|
env: TASK=test
|
24
|
-
- rvm: 2.
|
30
|
+
- rvm: 2.7.0
|
25
31
|
env: TASK=bench TEMPLATE=benchmark/boolean_attribute.haml,benchmark/class_attribute.haml,benchmark/id_attribute.haml,benchmark/data_attribute.haml,benchmark/common_attribute.haml
|
26
|
-
- rvm: 2.
|
32
|
+
- rvm: 2.7.0
|
27
33
|
env: TASK=bench TEMPLATE=benchmark/dynamic_attributes/boolean_attribute.haml,benchmark/dynamic_attributes/class_attribute.haml,benchmark/dynamic_attributes/id_attribute.haml,benchmark/dynamic_attributes/data_attribute.haml,benchmark/dynamic_attributes/common_attribute.haml
|
28
|
-
- rvm: 2.
|
34
|
+
- rvm: 2.7.0
|
29
35
|
env: TASK=bench SLIM_BENCH=1
|
30
|
-
- rvm: 2.
|
36
|
+
- rvm: 2.7.0
|
31
37
|
env: TASK=bench TEMPLATE=benchmark/etc/attribute_builder.haml
|
32
|
-
- rvm: 2.
|
38
|
+
- rvm: 2.7.0
|
33
39
|
env: TASK=bench TEMPLATE=benchmark/etc/static_analyzer.haml
|
34
|
-
- rvm: 2.
|
40
|
+
- rvm: 2.7.0
|
35
41
|
env: TASK=bench TEMPLATE=benchmark/etc/string_interpolation.haml
|
36
|
-
- rvm: 2.
|
42
|
+
- rvm: 2.7.0
|
37
43
|
env: TASK=bench TEMPLATE=test/haml/templates/standard.haml COMPILE=1
|
38
44
|
allow_failures:
|
39
45
|
- rvm: ruby-head
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,58 @@ All notable changes to this project will be documented in this file. This
|
|
4
4
|
project adheres to [Semantic Versioning](http://semver.org/). This change log is based upon
|
5
5
|
[keep-a-changelog](https://github.com/olivierlacan/keep-a-changelog).
|
6
6
|
|
7
|
+
## [2.13.0](https://github.com/k0kubun/hamlit/compare/v2.12.0...v2.13.0) - 2020-10-2
|
8
|
+
|
9
|
+
### Added
|
10
|
+
|
11
|
+
- Support `--enable-frozen-string-literal` [#162](https://github.com/k0kubun/hamlit/issues/162).
|
12
|
+
*Thanks to @aliismayilov*
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
|
16
|
+
- Upgrade the Haml parser from Haml 4.0 to 5.2 [#163](https://github.com/k0kubun/hamlit/issues/163).
|
17
|
+
- Allow `@` as tag's class name.
|
18
|
+
- Fix NameError on an `InvalidAttributeNameError` reference introduced at Hamlit v2.12.0.
|
19
|
+
|
20
|
+
## [2.12.0](https://github.com/k0kubun/hamlit/compare/v2.11.1...v2.12.0) - 2020-09-30
|
21
|
+
|
22
|
+
### Changed
|
23
|
+
|
24
|
+
- Class names are no longer ordered alphabetically.
|
25
|
+
*Thanks to @aliismayilov*
|
26
|
+
- This is compatible with [Haml 5.2](https://github.com/haml/haml/blob/v5.2.0/CHANGELOG.md#52)
|
27
|
+
|
28
|
+
## [2.11.1](https://github.com/k0kubun/hamlit/compare/v2.11.0...v2.11.1) - 2020-08-25
|
29
|
+
|
30
|
+
### Fixed
|
31
|
+
|
32
|
+
- Fix a line number on an error after filters like preserve, plain, and ruby.
|
33
|
+
*Thanks to @rgisiger*
|
34
|
+
|
35
|
+
## [2.11.0](https://github.com/k0kubun/hamlit/compare/v2.10.1...v2.11.0) - 2019-12-12
|
36
|
+
|
37
|
+
### Added
|
38
|
+
|
39
|
+
- Support Haml's _revealed_ conditional comment feature on `/![if !IE]` [#153](https://github.com/k0kubun/hamlit/issues/153).
|
40
|
+
*Thanks to @esb*
|
41
|
+
|
42
|
+
## [2.10.1](https://github.com/k0kubun/hamlit/compare/v2.10.0...v2.10.1) - 2019-11-28
|
43
|
+
|
44
|
+
### Added
|
45
|
+
|
46
|
+
- Register `Hamlit::Template` to Tilt as :hamlit as well, in addition to :haml
|
47
|
+
|
48
|
+
## [2.10.0](https://github.com/k0kubun/hamlit/compare/v2.9.5...v2.10.0) - 2019-09-15
|
49
|
+
|
50
|
+
### Added
|
51
|
+
|
52
|
+
- Optimize template rendering by string interpolation [#146](https://github.com/k0kubun/hamlit/issues/146)
|
53
|
+
- Exploiting pre-allocation of string interpolation introduced in Ruby 2.5 [ruby/ruby#1626](https://github.com/ruby/ruby/pull/1626)
|
54
|
+
|
55
|
+
### Changed
|
56
|
+
|
57
|
+
- Require temple.gem >= 0.8.2
|
58
|
+
|
7
59
|
## [2.9.5](https://github.com/k0kubun/hamlit/compare/v2.9.4...v2.9.5) - 2019-09-08
|
8
60
|
|
9
61
|
### Added
|
data/Gemfile
CHANGED
@@ -8,23 +8,17 @@ end
|
|
8
8
|
# Specify your gem's dependencies in hamlit.gemspec
|
9
9
|
gemspec
|
10
10
|
|
11
|
-
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2.2')
|
12
|
-
gem 'rack', '< 2'
|
13
|
-
end
|
14
|
-
|
15
11
|
gem 'benchmark-ips', '2.3.0'
|
16
12
|
gem 'maxitest'
|
13
|
+
gem 'pry'
|
17
14
|
|
18
15
|
if /java/ === RUBY_PLATFORM # JRuby
|
19
16
|
gem 'pandoc-ruby'
|
20
17
|
else
|
21
|
-
gem 'pry-byebug'
|
22
18
|
gem 'redcarpet'
|
23
19
|
|
24
20
|
if RUBY_PLATFORM !~ /mswin|mingw/ && RUBY_ENGINE != 'truffleruby'
|
25
|
-
|
26
|
-
gem 'faml'
|
27
|
-
end
|
21
|
+
gem 'faml'
|
28
22
|
gem 'stackprof'
|
29
23
|
end
|
30
24
|
end
|
data/LICENSE.txt
CHANGED
@@ -1,3 +1,29 @@
|
|
1
|
+
Copyright (c) 2006-2019 Hampton Catlin and Natalie Weizenbaum
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
===
|
23
|
+
|
24
|
+
The above license is applied to lib/hamlit/parser/*.rb and test/haml/*.
|
25
|
+
Everything else is licensed under:
|
26
|
+
|
1
27
|
The MIT License (MIT)
|
2
28
|
|
3
29
|
Copyright (c) 2015 Takashi Kokubun
|
@@ -19,26 +45,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
45
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
46
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
47
|
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.
|
data/REFERENCE.md
CHANGED
@@ -57,6 +57,7 @@ for full features in original implementation.
|
|
57
57
|
- [x] :plain
|
58
58
|
- [x] :preserve
|
59
59
|
- [x] :ruby
|
60
|
+
- `haml_io` API is not supported. Use [hamlit-haml\_io.gem](https://github.com/hamlit/hamlit-haml_io) if you need.
|
60
61
|
- [x] :sass
|
61
62
|
- [x] :scss
|
62
63
|
- [ ] :textile
|
@@ -121,10 +122,10 @@ and merging multiple ids results in concatenation by "\_".
|
|
121
122
|
%div{ id: false }
|
122
123
|
|
123
124
|
# Output
|
124
|
-
<div id='foo_bar'></
|
125
|
-
<div id='foo_bar'></
|
126
|
-
<div id='foo_bar'></
|
127
|
-
<div id=''></
|
125
|
+
<div id='foo_bar'></div>
|
126
|
+
<div id='foo_bar'></div>
|
127
|
+
<div id='foo_bar'></div>
|
128
|
+
<div id=''></div>
|
128
129
|
```
|
129
130
|
|
130
131
|
### class attribute
|
@@ -224,6 +225,14 @@ Hamlit::RailsTemplate.set_options attr_quote: '"'
|
|
224
225
|
set :haml, { attr_quote: '"' }
|
225
226
|
```
|
226
227
|
|
228
|
+
## Ruby module
|
229
|
+
|
230
|
+
`Hamlit::Template` is a module registered to `Tilt`. You can use it like:
|
231
|
+
|
232
|
+
```rb
|
233
|
+
Hamlit::Template.new { "%strong Yay for HAML!" }.render
|
234
|
+
```
|
235
|
+
|
227
236
|
## Creating a custom filter
|
228
237
|
|
229
238
|
Currently it doesn't have filter registering interface compatible with Haml.
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Original: https://github.com/amatsuda/string_template/blob/master/benchmark.rb
|
2
|
+
require 'benchmark_driver'
|
3
|
+
|
4
|
+
Benchmark.driver(repeat_count: 8) do |x|
|
5
|
+
x.prelude %{
|
6
|
+
require 'rails'
|
7
|
+
require 'action_view'
|
8
|
+
require 'string_template'
|
9
|
+
StringTemplate::Railtie.run_initializers
|
10
|
+
require 'hamlit'
|
11
|
+
Hamlit::Railtie.run_initializers
|
12
|
+
Hamlit::RailsTemplate.set_options(escape_html: false, generator: Temple::Generators::ArrayBuffer)
|
13
|
+
require 'action_view/base'
|
14
|
+
|
15
|
+
(view = Class.new(ActionView::Base).new(ActionView::LookupContext.new(''))).instance_variable_set(:@world, 'world!')
|
16
|
+
|
17
|
+
# compile template
|
18
|
+
hello = 'benchmark/dynamic_merger/hello'
|
19
|
+
view.render(template: hello, handlers: 'string')
|
20
|
+
view.render(template: hello, handlers: 'haml')
|
21
|
+
}
|
22
|
+
x.report 'string', %{ view.render(template: hello, handlers: 'string') }
|
23
|
+
x.report 'hamlit', %{ view.render(template: hello, handlers: 'haml') }
|
24
|
+
x.loop_count 100_000
|
25
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
hello, #{ @world }
|
2
|
+
hello, #{ @world }
|
3
|
+
hello, #{ @world }
|
4
|
+
hello, #{ @world }
|
5
|
+
hello, #{ @world }
|
6
|
+
hello, #{ @world }
|
7
|
+
hello, #{ @world }
|
8
|
+
hello, #{ @world }
|
9
|
+
hello, #{ @world }
|
10
|
+
hello, #{ @world }
|
11
|
+
hello, #{ @world }
|
12
|
+
hello, #{ @world }
|
13
|
+
hello, #{ @world }
|
14
|
+
hello, #{ @world }
|
15
|
+
hello, #{ @world }
|
16
|
+
hello, #{ @world }
|
17
|
+
hello, #{ @world }
|
18
|
+
hello, #{ @world }
|
19
|
+
hello, #{ @world }
|
20
|
+
hello, #{ @world }
|
21
|
+
hello, #{ @world }
|
22
|
+
hello, #{ @world }
|
23
|
+
hello, #{ @world }
|
24
|
+
hello, #{ @world }
|
25
|
+
hello, #{ @world }
|
26
|
+
hello, #{ @world }
|
27
|
+
hello, #{ @world }
|
28
|
+
hello, #{ @world }
|
29
|
+
hello, #{ @world }
|
30
|
+
hello, #{ @world }
|
31
|
+
hello, #{ @world }
|
32
|
+
hello, #{ @world }
|
33
|
+
hello, #{ @world }
|
34
|
+
hello, #{ @world }
|
35
|
+
hello, #{ @world }
|
36
|
+
hello, #{ @world }
|
37
|
+
hello, #{ @world }
|
38
|
+
hello, #{ @world }
|
39
|
+
hello, #{ @world }
|
40
|
+
hello, #{ @world }
|
41
|
+
hello, #{ @world }
|
42
|
+
hello, #{ @world }
|
43
|
+
hello, #{ @world }
|
44
|
+
hello, #{ @world }
|
45
|
+
hello, #{ @world }
|
46
|
+
hello, #{ @world }
|
47
|
+
hello, #{ @world }
|
48
|
+
hello, #{ @world }
|
49
|
+
hello, #{ @world }
|
50
|
+
hello, #{ @world }
|
@@ -0,0 +1,50 @@
|
|
1
|
+
hello, #{ @world }
|
2
|
+
hello, #{ @world }
|
3
|
+
hello, #{ @world }
|
4
|
+
hello, #{ @world }
|
5
|
+
hello, #{ @world }
|
6
|
+
hello, #{ @world }
|
7
|
+
hello, #{ @world }
|
8
|
+
hello, #{ @world }
|
9
|
+
hello, #{ @world }
|
10
|
+
hello, #{ @world }
|
11
|
+
hello, #{ @world }
|
12
|
+
hello, #{ @world }
|
13
|
+
hello, #{ @world }
|
14
|
+
hello, #{ @world }
|
15
|
+
hello, #{ @world }
|
16
|
+
hello, #{ @world }
|
17
|
+
hello, #{ @world }
|
18
|
+
hello, #{ @world }
|
19
|
+
hello, #{ @world }
|
20
|
+
hello, #{ @world }
|
21
|
+
hello, #{ @world }
|
22
|
+
hello, #{ @world }
|
23
|
+
hello, #{ @world }
|
24
|
+
hello, #{ @world }
|
25
|
+
hello, #{ @world }
|
26
|
+
hello, #{ @world }
|
27
|
+
hello, #{ @world }
|
28
|
+
hello, #{ @world }
|
29
|
+
hello, #{ @world }
|
30
|
+
hello, #{ @world }
|
31
|
+
hello, #{ @world }
|
32
|
+
hello, #{ @world }
|
33
|
+
hello, #{ @world }
|
34
|
+
hello, #{ @world }
|
35
|
+
hello, #{ @world }
|
36
|
+
hello, #{ @world }
|
37
|
+
hello, #{ @world }
|
38
|
+
hello, #{ @world }
|
39
|
+
hello, #{ @world }
|
40
|
+
hello, #{ @world }
|
41
|
+
hello, #{ @world }
|
42
|
+
hello, #{ @world }
|
43
|
+
hello, #{ @world }
|
44
|
+
hello, #{ @world }
|
45
|
+
hello, #{ @world }
|
46
|
+
hello, #{ @world }
|
47
|
+
hello, #{ @world }
|
48
|
+
hello, #{ @world }
|
49
|
+
hello, #{ @world }
|
50
|
+
hello, #{ @world }
|
data/bin/bench
CHANGED
@@ -25,7 +25,7 @@ class Bench < Thor
|
|
25
25
|
haml = File.read(file)
|
26
26
|
|
27
27
|
Benchmark.ips do |x|
|
28
|
-
x.report("haml v#{Haml::VERSION}") { Haml::Engine.new(haml, escape_html: true, escape_attrs: true
|
28
|
+
x.report("haml v#{Haml::VERSION}") { Haml::Engine.new(haml, escape_html: true, escape_attrs: true).precompiled }
|
29
29
|
x.report("faml v#{Faml::VERSION}") { Faml::Engine.new.call(haml) }
|
30
30
|
x.report("hamlit v#{Hamlit::VERSION}") { Hamlit::Engine.new.call(haml) }
|
31
31
|
x.compare!
|
@@ -43,7 +43,7 @@ class Bench < Thor
|
|
43
43
|
object.instance_eval(File.read(ruby_file))
|
44
44
|
end
|
45
45
|
|
46
|
-
Haml::Engine.new(haml, escape_html: true, escape_attrs: true
|
46
|
+
Haml::Engine.new(haml, escape_html: true, escape_attrs: true).def_method(object, :haml)
|
47
47
|
object.instance_eval "def faml; #{Faml::Engine.new.call(haml)}; end"
|
48
48
|
object.instance_eval "def hamlit; #{Hamlit::Engine.new.call(haml)}; end"
|
49
49
|
|
@@ -59,7 +59,7 @@ class Bench < Thor
|
|
59
59
|
def code(file)
|
60
60
|
haml = File.read(file)
|
61
61
|
puts "#{?= * 49}\n Haml Source: #{file}\n#{?= * 49}"
|
62
|
-
puts Haml::Engine.new(haml, escape_html: true, escape_attrs: true
|
62
|
+
puts Haml::Engine.new(haml, escape_html: true, escape_attrs: true).precompiled
|
63
63
|
puts "\n#{?= * 49}\n Faml Source: #{file}\n#{?= * 49}"
|
64
64
|
puts Faml::Engine.new.call(haml)
|
65
65
|
puts "\n#{?= * 49}\n Hamlit Source: #{file}\n#{?= * 49}"
|
data/bin/update-haml
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'fileutils'
|
3
|
+
require 'tmpdir'
|
4
|
+
|
5
|
+
HAML_REPO = 'haml/haml'
|
6
|
+
HAML_VERSION = 'v5.2.0'
|
7
|
+
|
8
|
+
module GitHubFetcher
|
9
|
+
def self.fetch(repo, tag:, path:)
|
10
|
+
Dir.mktmpdir do |dir|
|
11
|
+
Dir.chdir(dir) do
|
12
|
+
url = "https://github.com/#{repo}/archive/#{tag}.tar.gz"
|
13
|
+
system("curl -L --fail --retry 3 --retry-delay 1 #{url} -o - | tar zxf -")
|
14
|
+
FileUtils.mv("#{File.basename(repo)}-#{tag.sub(/\Av/, '')}", path)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class LicenseBuilder
|
21
|
+
DELIMITER = "\n==="
|
22
|
+
|
23
|
+
def initialize(haml_license:, hamlit_license:)
|
24
|
+
@haml_license = haml_license
|
25
|
+
@hamlit_license = hamlit_license
|
26
|
+
end
|
27
|
+
|
28
|
+
def build
|
29
|
+
license = [
|
30
|
+
File.read(@haml_license),
|
31
|
+
File.read(@hamlit_license).split(DELIMITER, 2).last,
|
32
|
+
].join(DELIMITER)
|
33
|
+
File.write(@hamlit_license, license)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Generate lib/hamlit/parser from haml
|
38
|
+
class HamlitParserBuilder
|
39
|
+
TARGET_FILES = [
|
40
|
+
'attribute_builder.rb',
|
41
|
+
'buffer.rb',
|
42
|
+
'error.rb',
|
43
|
+
'helpers.rb',
|
44
|
+
'options.rb',
|
45
|
+
'temple_engine.rb',
|
46
|
+
# TODO: make the upstream sharable first
|
47
|
+
# 'parser.rb',
|
48
|
+
'util.rb',
|
49
|
+
'helpers/xss_mods.rb',
|
50
|
+
]
|
51
|
+
|
52
|
+
# Classes which are just referenced by Options and not really used by the parser
|
53
|
+
DUMMY_CLASSES = {
|
54
|
+
'compiler.rb' => 'Compiler',
|
55
|
+
'escapable.rb' => 'Escapable',
|
56
|
+
'generator.rb' => 'Generator',
|
57
|
+
}
|
58
|
+
|
59
|
+
def initialize(haml:, hamlit_parser:)
|
60
|
+
@haml = haml
|
61
|
+
@hamlit_parser = hamlit_parser
|
62
|
+
end
|
63
|
+
|
64
|
+
def build
|
65
|
+
TARGET_FILES.each do |file|
|
66
|
+
src_path = File.join(@haml, file)
|
67
|
+
dest_path = File.join(@hamlit_parser, "haml_#{file}")
|
68
|
+
|
69
|
+
FileUtils.mkdir_p(File.dirname(dest_path))
|
70
|
+
FileUtils.cp(src_path, dest_path)
|
71
|
+
|
72
|
+
src = File.read(dest_path)
|
73
|
+
patch_source!(src, file: file)
|
74
|
+
File.write(dest_path, src)
|
75
|
+
end
|
76
|
+
|
77
|
+
DUMMY_CLASSES.each do |file, klass|
|
78
|
+
dest_path = File.join(@hamlit_parser, "haml_#{file}")
|
79
|
+
src = "class Hamlit::Haml#{klass}; end"
|
80
|
+
File.write(dest_path, src)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def patch_source!(src, file:)
|
87
|
+
# Use Hamlit::HamlFoo instead of Haml::Foo
|
88
|
+
src.gsub!(/^module Haml\n((?: #[^\n]+\n)*) (module|class) ([^ ]+)/, "module Hamlit\n\\1 \\2 Haml\\3")
|
89
|
+
src.gsub!(/\bHaml::/, 'Hamlit::Haml')
|
90
|
+
|
91
|
+
# Prefix Haml to references without Haml::
|
92
|
+
src.gsub!(/\b(AttributeBuilder|Error|InvalidAttributeNameError|Options|Parser|SyntaxError)\./, 'Haml\0')
|
93
|
+
src.gsub!(/\brescue SyntaxError /, 'rescue HamlSyntaxError ')
|
94
|
+
|
95
|
+
# Hamlit should not rely on Haml
|
96
|
+
src.gsub!(/^require 'haml\/([^']+)'/, "require 'hamlit/parser/haml_\\1'")
|
97
|
+
|
98
|
+
case file
|
99
|
+
when 'error.rb'
|
100
|
+
src.gsub!(/^ class ([^ ]+) < ([^ ]+);/, ' class Haml\1 < Haml\2;')
|
101
|
+
when 'helpers.rb'
|
102
|
+
src.gsub!(/^ def is_haml\?\n false\n end/m) { |str| str.gsub(/^ /, ' # ') } # not needed for the parser
|
103
|
+
when 'options.rb'
|
104
|
+
src.gsub!(/\.is_a\?\(Options\)/, '.is_a?(HamlOptions)')
|
105
|
+
when 'temple_engine.rb'
|
106
|
+
src.gsub!(/\buse (Generator|Escapable)$/, 'use Haml\1')
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
FileUtils.rm_rf(haml = File.expand_path('../haml', __dir__))
|
112
|
+
GitHubFetcher.fetch(HAML_REPO, tag: HAML_VERSION, path: haml)
|
113
|
+
|
114
|
+
hamlit = File.expand_path('..', __dir__)
|
115
|
+
LicenseBuilder.new(
|
116
|
+
haml_license: File.join(haml, 'MIT-LICENSE'),
|
117
|
+
hamlit_license: File.join(hamlit, 'LICENSE.txt'),
|
118
|
+
).build
|
119
|
+
|
120
|
+
hamlit_parser = File.join(hamlit, 'lib/hamlit/parser')
|
121
|
+
# TODO: FileUtils.rm_rf(hamlit_parser = File.join(hamlit, 'lib/hamlit/parser'))
|
122
|
+
HamlitParserBuilder.new(
|
123
|
+
haml: File.join(haml, 'lib/haml'),
|
124
|
+
hamlit_parser: hamlit_parser,
|
125
|
+
).build
|