hamlit 2.10.1 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -0
  3. data/.github/workflows/bench.yml +46 -0
  4. data/.github/workflows/test.yml +40 -0
  5. data/.gitignore +2 -1
  6. data/CHANGELOG.md +164 -0
  7. data/Gemfile +1 -7
  8. data/LICENSE.txt +26 -23
  9. data/README.md +9 -9
  10. data/REFERENCE.md +13 -4
  11. data/bin/update-haml +125 -0
  12. data/ext/hamlit/hamlit.c +28 -46
  13. data/hamlit.gemspec +2 -3
  14. data/lib/hamlit/ambles.rb +20 -0
  15. data/lib/hamlit/attribute_builder.rb +5 -5
  16. data/lib/hamlit/attribute_compiler.rb +7 -4
  17. data/lib/hamlit/cli.rb +35 -10
  18. data/lib/hamlit/compiler/children_compiler.rb +18 -4
  19. data/lib/hamlit/compiler/comment_compiler.rb +8 -5
  20. data/lib/hamlit/compiler/script_compiler.rb +3 -2
  21. data/lib/hamlit/compiler.rb +1 -1
  22. data/lib/hamlit/engine.rb +4 -0
  23. data/lib/hamlit/filters/escaped.rb +1 -1
  24. data/lib/hamlit/filters/markdown.rb +1 -0
  25. data/lib/hamlit/filters/preserve.rb +1 -1
  26. data/lib/hamlit/filters/text_base.rb +1 -1
  27. data/lib/hamlit/filters/tilt_base.rb +1 -1
  28. data/lib/hamlit/html.rb +8 -0
  29. data/lib/hamlit/parser/haml_attribute_builder.rb +164 -0
  30. data/lib/hamlit/parser/haml_buffer.rb +20 -130
  31. data/lib/hamlit/parser/haml_compiler.rb +1 -553
  32. data/lib/hamlit/parser/haml_error.rb +29 -25
  33. data/lib/hamlit/parser/haml_escapable.rb +1 -0
  34. data/lib/hamlit/parser/haml_generator.rb +1 -0
  35. data/lib/hamlit/parser/{haml_xss_mods.rb → haml_helpers/xss_mods.rb} +20 -15
  36. data/lib/hamlit/parser/haml_helpers.rb +41 -59
  37. data/lib/hamlit/parser/haml_options.rb +53 -66
  38. data/lib/hamlit/parser/haml_parser.rb +133 -73
  39. data/lib/hamlit/parser/haml_temple_engine.rb +123 -0
  40. data/lib/hamlit/parser/haml_util.rb +10 -40
  41. data/lib/hamlit/parser.rb +8 -2
  42. data/lib/hamlit/rails_template.rb +9 -1
  43. data/lib/hamlit/railtie.rb +6 -1
  44. data/lib/hamlit/string_splitter.rb +1 -0
  45. data/lib/hamlit/temple_line_counter.rb +31 -0
  46. data/lib/hamlit/version.rb +1 -1
  47. data/lib/hamlit.rb +6 -4
  48. metadata +16 -55
  49. data/.travis.yml +0 -47
  50. data/benchmark/boolean_attribute.haml +0 -6
  51. data/benchmark/class_attribute.haml +0 -5
  52. data/benchmark/common_attribute.haml +0 -3
  53. data/benchmark/data_attribute.haml +0 -4
  54. data/benchmark/dynamic_attributes/boolean_attribute.haml +0 -4
  55. data/benchmark/dynamic_attributes/class_attribute.haml +0 -4
  56. data/benchmark/dynamic_attributes/common_attribute.haml +0 -2
  57. data/benchmark/dynamic_attributes/data_attribute.haml +0 -2
  58. data/benchmark/dynamic_attributes/id_attribute.haml +0 -2
  59. data/benchmark/dynamic_boolean_attribute.haml +0 -4
  60. data/benchmark/dynamic_merger/benchmark.rb +0 -25
  61. data/benchmark/dynamic_merger/hello.haml +0 -50
  62. data/benchmark/dynamic_merger/hello.string +0 -50
  63. data/benchmark/etc/attribute_builder.haml +0 -5
  64. data/benchmark/etc/real_sample.haml +0 -888
  65. data/benchmark/etc/real_sample.rb +0 -11
  66. data/benchmark/etc/static_analyzer.haml +0 -1
  67. data/benchmark/etc/string_interpolation.haml +0 -2
  68. data/benchmark/etc/tags.haml +0 -3
  69. data/benchmark/etc/tags_loop.haml +0 -2
  70. data/benchmark/ext/build_data.rb +0 -17
  71. data/benchmark/ext/build_id.rb +0 -13
  72. data/benchmark/id_attribute.haml +0 -3
  73. data/benchmark/plain.haml +0 -4
  74. data/benchmark/script.haml +0 -4
  75. data/benchmark/slim/LICENSE +0 -21
  76. data/benchmark/slim/context.rb +0 -11
  77. data/benchmark/slim/run-benchmarks.rb +0 -94
  78. data/benchmark/slim/view.erb +0 -23
  79. data/benchmark/slim/view.haml +0 -18
  80. data/benchmark/slim/view.slim +0 -17
  81. data/benchmark/utils/benchmark_ips_extension.rb +0 -43
  82. data/lib/hamlit/parser/MIT-LICENSE +0 -20
  83. data/lib/hamlit/parser/README.md +0 -30
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc231a76a98c6d527ca80a30385e3161a207814e9e1d3abe593929910e222795
4
- data.tar.gz: 21a57103fa4f6ac2df5ff712a8c1e2bc6f799cb59ec06d39769518b251d60139
3
+ metadata.gz: ff4644b3625c52ef89dd93a014324209d343055e7ff6d4be2bc928d701207d79
4
+ data.tar.gz: fa7e502f834887ca24edcceacb0e3ac179fc926446b54149ba31e41a87d59673
5
5
  SHA512:
6
- metadata.gz: 95b3596d2f44759d90c3c02065c0986cf107179513bf31a8bb1116d35064cf2049e2ad342c30b884e938fef1a2c228f11ce15c5f4350bb09143d5d19dcf753ff
7
- data.tar.gz: dd36a42a6aa53e8f2b3e45865d077dc459d91ec0388a784b3ed5e2420bcaebc3f9b6c01f020d3e68acc17a9e209e8e0f1ac7ab9915390717fbcba2348fdead16
6
+ metadata.gz: b6d19a0e3dd9be45782fc5770cb9e8e38ba7d3c82f8b98e4d9271607135628c9582d628e31745153a0a477a56445ffd31cbcff2e5f9ed9c887485f07db9e5cba
7
+ data.tar.gz: f61c4f0af81edd24249bf48315f773c4872ae8429f0c6640576185ec891fef8e0839be8555db8d7cb2d4be3397d64fd794c912f04136a3c070316176fcea82ca
@@ -0,0 +1 @@
1
+ github: k0kubun
@@ -0,0 +1,46 @@
1
+ name: bench
2
+ on:
3
+ push:
4
+ branches:
5
+ - master
6
+ pull_request:
7
+ types:
8
+ - opened
9
+ - synchronize
10
+ - reopened
11
+ schedule:
12
+ - cron: "00 15 * * *" # 7:00 PST (-8), 8:00 PDT (-7)
13
+ jobs:
14
+ bench:
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ include:
20
+ - slim: 1
21
+ - template: 'benchmark/boolean_attribute.haml,benchmark/class_attribute.haml,benchmark/id_attribute.haml,benchmark/data_attribute.haml,benchmark/common_attribute.haml'
22
+ - 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'
23
+ - template: 'benchmark/etc/attribute_builder.haml'
24
+ - template: 'benchmark/etc/static_analyzer.haml'
25
+ - template: 'benchmark/etc/string_interpolation.haml'
26
+ - template: 'test/haml/templates/standard.haml'
27
+ compile: 1
28
+ steps:
29
+ - uses: actions/checkout@v2
30
+ - name: Set up Ruby
31
+ uses: ruby/setup-ruby@v1
32
+ with:
33
+ ruby-version: '3.0'
34
+ - uses: actions/cache@v2
35
+ with:
36
+ path: vendor/bundle
37
+ key: ${{ runner.os }}-${{ matrix.ruby }}-gems-${{ hashFiles('**/Gemfile.lock') }}
38
+ restore-keys: ${{ runner.os }}-gems-
39
+ - run: sudo apt-get update && sudo apt-get install -y nodejs libxslt-dev # nodejs for execjs, libxslt for TruffleRuby nokogiri
40
+ - name: bundle install
41
+ run: bundle config path vendor/bundle && bundle install -j$(nproc) --retry 3
42
+ - run: bundle exec rake bench
43
+ env:
44
+ SLIM_BENCH: ${{ matrix.slim }}
45
+ TEMPLATE: ${{ matrix.template }}
46
+ COMPILE: ${{ matrix.compile }}
@@ -0,0 +1,40 @@
1
+ name: test
2
+ on:
3
+ push:
4
+ branches:
5
+ - master
6
+ pull_request:
7
+ types:
8
+ - opened
9
+ - synchronize
10
+ - reopened
11
+ schedule:
12
+ - cron: "00 15 * * *" # 7:00 PST (-8), 8:00 PDT (-7)
13
+ jobs:
14
+ test:
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ ruby:
20
+ - '2.5'
21
+ - '2.6'
22
+ - '2.7'
23
+ - '3.0'
24
+ - jruby
25
+ - truffleruby-head
26
+ steps:
27
+ - uses: actions/checkout@v2
28
+ - name: Set up Ruby
29
+ uses: ruby/setup-ruby@v1
30
+ with:
31
+ ruby-version: ${{ matrix.ruby }}
32
+ - uses: actions/cache@v2
33
+ with:
34
+ path: vendor/bundle
35
+ key: ${{ runner.os }}-${{ matrix.ruby }}-gems-${{ hashFiles('**/Gemfile.lock') }}
36
+ restore-keys: ${{ runner.os }}-gems-
37
+ - run: sudo apt-get update && sudo apt-get install -y nodejs libxslt-dev # nodejs for execjs, libxslt for TruffleRuby nokogiri
38
+ - name: bundle install
39
+ run: bundle config path vendor/bundle && bundle install -j$(nproc) --retry 3
40
+ - run: bundle exec rake test
data/.gitignore CHANGED
@@ -7,11 +7,12 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /haml/
10
11
  .sass-cache
11
12
  .ruby-version
12
13
  *.bundle
13
14
  *.so
14
15
  *.su
15
- *.o
16
16
  *.a
17
+ *.o
17
18
  *.swp
data/CHANGELOG.md CHANGED
@@ -4,6 +4,170 @@ 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
+ ## [3.0.1](https://github.com/k0kubun/hamlit/compare/v3.0.0...v3.0.1) - 2022-08-18
8
+
9
+ ### Changed
10
+
11
+ - coffee-script is removed from development dependency
12
+ - It's not runtime dependency, so it shouldn't impact your application
13
+ - `:coffee` filter still works if you explicitly install coffee-script,
14
+ however, it's no longer maintained and possibly removed in the future.
15
+
16
+ ## [3.0.0](https://github.com/k0kubun/hamlit/compare/v2.16.2...v3.0.0) - 2022-08-07
17
+
18
+ ### Changed
19
+
20
+ - [**breaking**] Use `disable_capture: false` for non-Rails environments
21
+ - `:disable_capture` is an option introduced in v2.16.1. See its release notes for details.
22
+ - If you use Rails, it continues to use `disable_capture: true`, so you're not impacted by this change.
23
+
24
+ ## [2.16.2](https://github.com/k0kubun/hamlit/compare/v2.16.1...v2.16.2) - 2022-08-07
25
+
26
+ ### Fixed
27
+
28
+ - Fix an issue when `disable_capture: false` is set and a Ruby comment is put after `do`
29
+
30
+ ## [2.16.1](https://github.com/k0kubun/hamlit/compare/v2.16.0...v2.16.1) - 2022-08-07
31
+
32
+ ### Added
33
+
34
+ - Introduce `:disable_capture` option to capture a block
35
+ - Default: `disable_capture: true` (backward-compatible)
36
+ - For Rails, this must be `true` anyway to use Rails-native capturing.
37
+ - If you override the option like `disable_capture: false` in Hamlit::Template,
38
+ scripts starting with `=` (e.g. `= render do`) capture a block content.
39
+ - Scripts starting with `-` (e.g. `- users.each do`) are not impacted.
40
+
41
+ ## [2.16.0](https://github.com/k0kubun/hamlit/compare/v2.15.2...v2.16.0) - 2022-02-03
42
+
43
+ ### Added
44
+
45
+ - Raise an exception on a Haml-level syntax error with `hamlit compile -c`
46
+ [#189](https://github.com/k0kubun/hamlit/issues/189)
47
+ *Thanks to @dlwr*
48
+
49
+ ## [2.15.2](https://github.com/k0kubun/hamlit/compare/v2.15.1...v2.15.2) - 2022-01-04
50
+
51
+ ### Fixed
52
+
53
+ - Consider `playsinline` a boolean attribute [#187](https://github.com/k0kubun/hamlit/issues/187)
54
+ *Thanks to @ghiculescu*
55
+
56
+ ## [2.15.1](https://github.com/k0kubun/hamlit/compare/v2.15.0...v2.15.1) - 2021-07-23
57
+
58
+ ### Fixed
59
+
60
+ - Remove `benchmark` from the gem package to reduce its size [#186](https://github.com/k0kubun/hamlit/issues/186)
61
+ *Thanks to @pocke*
62
+
63
+ ## [2.15.0](https://github.com/k0kubun/hamlit/compare/v2.14.6...v2.15.0) - 2021-04-12
64
+
65
+ ### Added
66
+
67
+ - Always use Hamlit when both haml.gem and hamlit.gem are installed in Rails
68
+ *Thanks to @igor-drozdov*
69
+
70
+ ## [2.14.6](https://github.com/k0kubun/hamlit/compare/v2.14.5...v2.14.6) - 2021-03-23
71
+
72
+ ### Fixed
73
+
74
+ - Optimize v2.14.5's implementation a little
75
+
76
+ ## [2.14.5](https://github.com/k0kubun/hamlit/compare/v2.14.4...v2.14.5) - 2021-03-23
77
+
78
+ ### Added
79
+
80
+ - Support `config.action_view.annotate_rendered_view_with_filenames = true` of Rails 6.1
81
+ *Thanks to @kirin121*
82
+
83
+ ## [2.14.4](https://github.com/k0kubun/hamlit/compare/v2.14.3...v2.14.4) - 2021-02-01
84
+
85
+ ### Fixed
86
+
87
+ - Prevent another SEGV in a C extension after `GC.compact` [#177](https://github.com/k0kubun/hamlit/issues/177)
88
+ *Thanks to @stanhu*
89
+
90
+ ## [2.14.3](https://github.com/k0kubun/hamlit/compare/v2.14.2...v2.14.3) - 2021-01-24
91
+
92
+ ### Fixed
93
+
94
+ - Ensure the Rails initializer is called before `:load_config_initializers` [#176](https://github.com/k0kubun/hamlit/issues/176)
95
+ *Thanks to @sunny*
96
+
97
+ ## [2.14.2](https://github.com/k0kubun/hamlit/compare/v2.14.1...v2.14.2) - 2021-01-21
98
+
99
+ ### Fixed
100
+
101
+ - Prevent SEGV in a C extension after `GC.compact` [#171](https://github.com/k0kubun/hamlit/issues/171)
102
+ *Thanks to @stanhu*
103
+
104
+ ## [2.14.1](https://github.com/k0kubun/hamlit/compare/v2.14.0...v2.14.1) - 2021-01-07
105
+
106
+ ### Added
107
+
108
+ - Add `-c` option to `hamlit compile` that works like `haml -c` [#166](https://github.com/k0kubun/hamlit/issues/166)
109
+ *Thanks to @knightq*
110
+
111
+ ## [2.14.0](https://github.com/k0kubun/hamlit/compare/v2.13.2...v2.14.0) - 2021-01-07
112
+
113
+ ### Changed
114
+
115
+ - CLI changes
116
+ - Remove `-c` shorthand of `--color`.
117
+ - Make `--color` default. Please use `--no-color` to disable it.
118
+ - `--color` uses IRB instead of Pry for syntax highlight.
119
+ - Syntax highlight of `hamlit compile` is enabled only with IRB of Ruby 2.7+.
120
+ - Syntax highlight of `hamlit parse` / `hamlit temple` is enabled only with IRB of Ruby 3.1+.
121
+
122
+ ## [2.13.2](https://github.com/k0kubun/hamlit/compare/v2.13.1...v2.13.2) - 2020-12-27
123
+
124
+ ### Added
125
+
126
+ - Speed up `hamlit` commands [#166](https://github.com/k0kubun/hamlit/issues/166)
127
+ *Thanks to @knightq*
128
+
129
+ ## [2.13.1](https://github.com/k0kubun/hamlit/compare/v2.13.0...v2.13.1) - 2020-12-27
130
+
131
+ ### Added
132
+
133
+ - Support [multiline attributes](https://github.com/haml/haml/pull/1043) of Haml 5.2.1.
134
+
135
+ ## [2.13.0](https://github.com/k0kubun/hamlit/compare/v2.12.0...v2.13.0) - 2020-10-02
136
+
137
+ ### Added
138
+
139
+ - Support `--enable-frozen-string-literal` [#162](https://github.com/k0kubun/hamlit/issues/162).
140
+ *Thanks to @aliismayilov*
141
+
142
+ ### Changed
143
+
144
+ - Upgrade the Haml parser from Haml 4.0 to 5.2 [#163](https://github.com/k0kubun/hamlit/issues/163).
145
+ - Allow `@` as tag's class name.
146
+ - Fix NameError on an `InvalidAttributeNameError` reference introduced at Hamlit v2.12.0.
147
+ - You can no longer specify `ugly` option, which has had no effect.
148
+
149
+ ## [2.12.0](https://github.com/k0kubun/hamlit/compare/v2.11.1...v2.12.0) - 2020-09-30
150
+
151
+ ### Changed
152
+
153
+ - Class names are no longer ordered alphabetically.
154
+ *Thanks to @aliismayilov*
155
+ - This is compatible with [Haml 5.2](https://github.com/haml/haml/blob/v5.2.0/CHANGELOG.md#52)
156
+
157
+ ## [2.11.1](https://github.com/k0kubun/hamlit/compare/v2.11.0...v2.11.1) - 2020-08-25
158
+
159
+ ### Fixed
160
+
161
+ - Fix a line number on an error after filters like preserve, plain, and ruby.
162
+ *Thanks to @rgisiger*
163
+
164
+ ## [2.11.0](https://github.com/k0kubun/hamlit/compare/v2.10.1...v2.11.0) - 2019-12-12
165
+
166
+ ### Added
167
+
168
+ - Support Haml's _revealed_ conditional comment feature on `/![if !IE]` [#153](https://github.com/k0kubun/hamlit/issues/153).
169
+ *Thanks to @esb*
170
+
7
171
  ## [2.10.1](https://github.com/k0kubun/hamlit/compare/v2.10.0...v2.10.1) - 2019-11-28
8
172
 
9
173
  ### Added
data/Gemfile CHANGED
@@ -8,10 +8,6 @@ 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'
17
13
  gem 'pry'
@@ -22,9 +18,7 @@ else
22
18
  gem 'redcarpet'
23
19
 
24
20
  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
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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Hamlit
2
2
 
3
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)
4
+ [![test](https://github.com/k0kubun/hamlit/workflows/test/badge.svg)](https://github.com/k0kubun/hamlit/actions?query=workflow%3Atest)
5
5
 
6
6
  Hamlit is a high performance [Haml](https://github.com/haml/haml) implementation.
7
7
 
@@ -10,17 +10,17 @@ Hamlit is a high performance [Haml](https://github.com/haml/haml) implementation
10
10
  ### What is Hamlit?
11
11
  Hamlit is another implementation of [Haml](https://github.com/haml/haml).
12
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))
13
+ Hamlit is **1.94x 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/4.1.0/benchmarks/run-benchmarks.rb) for fairness. ([Result on Travis](https://travis-ci.org/github/k0kubun/hamlit/jobs/732178446))
15
15
 
16
- <img src="https://i.gyazo.com/0f0c0362b6bd69f82715bec1d8caa191.png" width="600px" alt="Hamlit Benchmark"/>
16
+ <img src="https://raw.githubusercontent.com/k0kubun/hamlit/afcc2b36c4861c2f764baa09afd9530ca25eeafa/benchmark/graph/graph.png" width="600x" alt="Hamlit Benchmark" />
17
17
 
18
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
19
+ hamlit v2.13.0: 247404.4 i/s
20
+ erubi v1.9.0: 244356.4 i/s - 1.01x slower
21
+ slim v4.1.0: 238254.3 i/s - 1.04x slower
22
+ faml v0.8.1: 197293.2 i/s - 1.25x slower
23
+ haml v5.2.0: 127834.4 i/s - 1.94x slower
24
24
  ```
25
25
 
26
26
  ### Why is Hamlit faster?
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'></span>
125
- <div id='foo_bar'></span>
126
- <div id='foo_bar'></span>
127
- <div id=''></span>
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.
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 = '5.2.1'
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\n"
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