hamlit 2.15.0 → 2.16.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/bench.yml +46 -0
  3. data/CHANGELOG.md +38 -0
  4. data/hamlit.gemspec +1 -1
  5. data/lib/hamlit/attribute_builder.rb +1 -1
  6. data/lib/hamlit/cli.rb +1 -0
  7. data/lib/hamlit/compiler/script_compiler.rb +3 -2
  8. data/lib/hamlit/compiler.rb +1 -1
  9. data/lib/hamlit/engine.rb +2 -0
  10. data/lib/hamlit/parser.rb +2 -0
  11. data/lib/hamlit/rails_template.rb +5 -2
  12. data/lib/hamlit/version.rb +1 -1
  13. metadata +4 -37
  14. data/benchmark/boolean_attribute.haml +0 -6
  15. data/benchmark/class_attribute.haml +0 -5
  16. data/benchmark/common_attribute.haml +0 -3
  17. data/benchmark/data_attribute.haml +0 -4
  18. data/benchmark/dynamic_attributes/boolean_attribute.haml +0 -4
  19. data/benchmark/dynamic_attributes/class_attribute.haml +0 -4
  20. data/benchmark/dynamic_attributes/common_attribute.haml +0 -2
  21. data/benchmark/dynamic_attributes/data_attribute.haml +0 -2
  22. data/benchmark/dynamic_attributes/id_attribute.haml +0 -2
  23. data/benchmark/dynamic_boolean_attribute.haml +0 -4
  24. data/benchmark/dynamic_merger/benchmark.rb +0 -25
  25. data/benchmark/dynamic_merger/hello.haml +0 -50
  26. data/benchmark/dynamic_merger/hello.string +0 -50
  27. data/benchmark/etc/attribute_builder.haml +0 -5
  28. data/benchmark/etc/real_sample.haml +0 -888
  29. data/benchmark/etc/real_sample.rb +0 -11
  30. data/benchmark/etc/static_analyzer.haml +0 -1
  31. data/benchmark/etc/string_interpolation.haml +0 -2
  32. data/benchmark/etc/tags.haml +0 -3
  33. data/benchmark/etc/tags_loop.haml +0 -2
  34. data/benchmark/ext/build_data.rb +0 -17
  35. data/benchmark/ext/build_id.rb +0 -13
  36. data/benchmark/graph/graph.key +0 -0
  37. data/benchmark/graph/graph.png +0 -0
  38. data/benchmark/id_attribute.haml +0 -3
  39. data/benchmark/plain.haml +0 -4
  40. data/benchmark/script.haml +0 -4
  41. data/benchmark/slim/LICENSE +0 -21
  42. data/benchmark/slim/context.rb +0 -11
  43. data/benchmark/slim/run-benchmarks.rb +0 -94
  44. data/benchmark/slim/view.erb +0 -23
  45. data/benchmark/slim/view.haml +0 -18
  46. data/benchmark/slim/view.slim +0 -17
  47. data/benchmark/utils/benchmark_ips_extension.rb +0 -43
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46fb5b844211b5c8bc782ee88d23eca02b16f9285609e76447a493aa10ee442c
4
- data.tar.gz: b1069d514efd9b06b534ec82b3d524fbfde98e87b7b660af6041b60132b7324e
3
+ metadata.gz: fcce9bd99678dbe36651b82eff53e60d3c36e518f05e6a6dba18856ce6d16bc0
4
+ data.tar.gz: 3264ed62419fdf42e1fb05452c58e6b2cc5f6575f33b13b8322cbef650a70a9a
5
5
  SHA512:
6
- metadata.gz: 52c0df95e9916faa1abecd927019d4429e28607fc4096157f6386f981cb2f5e6249e8aaabab0693942f7f31c01d0babcaf4dabea1b4cc92ea0d40b2d2cdf531c
7
- data.tar.gz: 5241185ed6759415eaf9a263142a6b937fe316c550a59490964e6d10668e26529d730996fd3443d953216fe2a2d30e9af0f5ad241eea92c9e64cf68af55f82bb
6
+ metadata.gz: 9a78f921253b5512072adccb7ba02bd28987f9c9f84b7bd0dc468a040249bb567c0432bc994a763a1516d09a6fde04a5eb50dbbf3f0a0dd835a442bca05f5838
7
+ data.tar.gz: fba0599895195d4cb4c82c3a2d213d451d88bb5c82fa338093674c9416d57ad88436547d50131777fc7f0c1dc17f79f4c91d08a72a839d8d22e3f5d1b2f33507
@@ -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 }}
data/CHANGELOG.md CHANGED
@@ -4,6 +4,44 @@ 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.16.2](https://github.com/k0kubun/hamlit/compare/v2.16.1...v2.16.2) - 2022-08-07
8
+
9
+ ### Fixed
10
+
11
+ - Fix an issue when `disable_capture: false` is set and a Ruby comment is put after `do`
12
+
13
+ ## [2.16.1](https://github.com/k0kubun/hamlit/compare/v2.16.0...v2.16.1) - 2022-08-07
14
+
15
+ ### Added
16
+
17
+ - Introduce `:disable_capture` option to capture a block
18
+ - Default: `disable_capture: true` (backward-compatible)
19
+ - For Rails, this must be `true` anyway to use Rails-native capturing.
20
+ - If you override the option like `disable_capture: false` in Hamlit::Template,
21
+ you can capture a block content like `= render do ...`.
22
+
23
+ ## [2.16.0](https://github.com/k0kubun/hamlit/compare/v2.15.2...v2.16.0) - 2022-02-03
24
+
25
+ ### Added
26
+
27
+ - Raise an exception on a Haml-level syntax error with `hamlit compile -c`
28
+ [#189](https://github.com/k0kubun/hamlit/issues/189)
29
+ *Thanks to @dlwr*
30
+
31
+ ## [2.15.2](https://github.com/k0kubun/hamlit/compare/v2.15.1...v2.15.2) - 2022-01-04
32
+
33
+ ### Fixed
34
+
35
+ - Consider `playsinline` a boolean attribute [#187](https://github.com/k0kubun/hamlit/issues/187)
36
+ *Thanks to @ghiculescu*
37
+
38
+ ## [2.15.1](https://github.com/k0kubun/hamlit/compare/v2.15.0...v2.15.1) - 2021-07-23
39
+
40
+ ### Fixed
41
+
42
+ - Remove `benchmark` from the gem package to reduce its size [#186](https://github.com/k0kubun/hamlit/issues/186)
43
+ *Thanks to @pocke*
44
+
7
45
  ## [2.15.0](https://github.com/k0kubun/hamlit/compare/v2.14.6...v2.15.0) - 2021-04-12
8
46
 
9
47
  ### Added
data/hamlit.gemspec CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = 'https://github.com/k0kubun/hamlit'
15
15
  spec.license = 'MIT'
16
16
 
17
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|sample)/}) }
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|sample|benchmark)/}) }
18
18
  spec.bindir = 'exe'
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ['lib']
@@ -7,7 +7,7 @@ module Hamlit::AttributeBuilder
7
7
  defer reversed ismap seamless muted required
8
8
  autofocus novalidate formnovalidate open pubdate
9
9
  itemscope allowfullscreen default inert sortable
10
- truespeed typemustmatch download].freeze
10
+ truespeed typemustmatch download playsinline].freeze
11
11
 
12
12
  # Java extension is not implemented for JRuby yet.
13
13
  # TruffleRuby does not implement `rb_ary_sort_bang`, etc.
data/lib/hamlit/cli.rb CHANGED
@@ -106,6 +106,7 @@ module Hamlit
106
106
  Hamlit::Engine.options.to_h.merge(
107
107
  escape_attrs: options[:escape_attrs],
108
108
  escape_html: options[:escape_html],
109
+ check_syntax: options[:check],
109
110
  )
110
111
  end
111
112
 
@@ -6,8 +6,9 @@ require 'hamlit/string_splitter'
6
6
  module Hamlit
7
7
  class Compiler
8
8
  class ScriptCompiler
9
- def initialize(identity)
9
+ def initialize(identity, options)
10
10
  @identity = identity
11
+ @disable_capture = options[:disable_capture]
11
12
  end
12
13
 
13
14
  def compile(node, &block)
@@ -79,7 +80,7 @@ module Hamlit
79
80
  else
80
81
  [:multi,
81
82
  [:block, "#{var} = #{node.value[:text]}",
82
- [:multi, [:newline], yield(node)],
83
+ [:multi, [:newline], @disable_capture ? yield(node) : [:capture, Temple::Utils.unique_name, yield(node)]]
83
84
  ],
84
85
  ]
85
86
  end
@@ -16,7 +16,7 @@ module Hamlit
16
16
  @comment_compiler = CommentCompiler.new
17
17
  @doctype_compiler = DoctypeCompiler.new(options)
18
18
  @filter_compiler = Filters.new(options)
19
- @script_compiler = ScriptCompiler.new(identity)
19
+ @script_compiler = ScriptCompiler.new(identity, options)
20
20
  @silent_script_compiler = SilentScriptCompiler.new
21
21
  @tag_compiler = TagCompiler.new(identity, options)
22
22
  end
data/lib/hamlit/engine.rb CHANGED
@@ -21,6 +21,8 @@ module Hamlit
21
21
  hr img input isindex keygen link menuitem meta
22
22
  param source track wbr),
23
23
  filename: "",
24
+ check_syntax: false,
25
+ disable_capture: true,
24
26
  )
25
27
 
26
28
  use Parser
data/lib/hamlit/parser.rb CHANGED
@@ -20,6 +20,7 @@ module Hamlit
20
20
  autoclose
21
21
  escape_html
22
22
  escape_attrs
23
+ check_syntax
23
24
  ].freeze
24
25
 
25
26
  def initialize(options = {})
@@ -35,6 +36,7 @@ module Hamlit
35
36
  end
36
37
  HamlParser.new(HamlOptions.new(@options)).call(template)
37
38
  rescue ::Hamlit::HamlError => e
39
+ raise e if @options[:check_syntax]
38
40
  error_with_lineno(e)
39
41
  end
40
42
 
@@ -15,6 +15,7 @@ module Hamlit
15
15
  use_html_safe: true,
16
16
  streaming: true,
17
17
  buffer_class: 'ActionView::OutputBuffer',
18
+ disable_capture: true,
18
19
  }
19
20
  end
20
21
 
@@ -34,8 +35,10 @@ module Hamlit
34
35
  end
35
36
 
36
37
  if ActionView::Base.try(:annotate_rendered_view_with_filenames) && template.format == :html
37
- options[:preamble] = "<!-- BEGIN #{template.short_identifier} -->\n"
38
- options[:postamble] = "<!-- END #{template.short_identifier} -->\n"
38
+ options = options.merge(
39
+ preamble: "<!-- BEGIN #{template.short_identifier} -->\n",
40
+ postamble: "<!-- END #{template.short_identifier} -->\n",
41
+ )
39
42
  end
40
43
 
41
44
  Engine.new(options).call(source)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Hamlit
3
- VERSION = '2.15.0'
3
+ VERSION = '2.16.2'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hamlit
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.15.0
4
+ version: 2.16.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Kokubun
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-13 00:00:00.000000000 Z
11
+ date: 2022-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: temple
@@ -258,6 +258,7 @@ extensions:
258
258
  extra_rdoc_files: []
259
259
  files:
260
260
  - ".github/FUNDING.yml"
261
+ - ".github/workflows/bench.yml"
261
262
  - ".github/workflows/test.yml"
262
263
  - ".gitignore"
263
264
  - CHANGELOG.md
@@ -266,40 +267,6 @@ files:
266
267
  - README.md
267
268
  - REFERENCE.md
268
269
  - Rakefile
269
- - benchmark/boolean_attribute.haml
270
- - benchmark/class_attribute.haml
271
- - benchmark/common_attribute.haml
272
- - benchmark/data_attribute.haml
273
- - benchmark/dynamic_attributes/boolean_attribute.haml
274
- - benchmark/dynamic_attributes/class_attribute.haml
275
- - benchmark/dynamic_attributes/common_attribute.haml
276
- - benchmark/dynamic_attributes/data_attribute.haml
277
- - benchmark/dynamic_attributes/id_attribute.haml
278
- - benchmark/dynamic_boolean_attribute.haml
279
- - benchmark/dynamic_merger/benchmark.rb
280
- - benchmark/dynamic_merger/hello.haml
281
- - benchmark/dynamic_merger/hello.string
282
- - benchmark/etc/attribute_builder.haml
283
- - benchmark/etc/real_sample.haml
284
- - benchmark/etc/real_sample.rb
285
- - benchmark/etc/static_analyzer.haml
286
- - benchmark/etc/string_interpolation.haml
287
- - benchmark/etc/tags.haml
288
- - benchmark/etc/tags_loop.haml
289
- - benchmark/ext/build_data.rb
290
- - benchmark/ext/build_id.rb
291
- - benchmark/graph/graph.key
292
- - benchmark/graph/graph.png
293
- - benchmark/id_attribute.haml
294
- - benchmark/plain.haml
295
- - benchmark/script.haml
296
- - benchmark/slim/LICENSE
297
- - benchmark/slim/context.rb
298
- - benchmark/slim/run-benchmarks.rb
299
- - benchmark/slim/view.erb
300
- - benchmark/slim/view.haml
301
- - benchmark/slim/view.slim
302
- - benchmark/utils/benchmark_ips_extension.rb
303
270
  - bin/bench
304
271
  - bin/console
305
272
  - bin/ruby
@@ -393,7 +360,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
393
360
  - !ruby/object:Gem::Version
394
361
  version: '0'
395
362
  requirements: []
396
- rubygems_version: 3.2.3
363
+ rubygems_version: 3.3.7
397
364
  signing_key:
398
365
  specification_version: 4
399
366
  summary: High Performance Haml Implementation
@@ -1,6 +0,0 @@
1
- %input{ disabled: false }
2
- %input{ disabled: true }
3
- - disabled = false
4
- %input{ disabled: disabled }
5
- - disabled = true
6
- %input{ disabled: disabled }
@@ -1,5 +0,0 @@
1
- .book{ class: 'content active' }
2
- .book(class='content active')
3
-
4
- - klass = %w[content active]
5
- .book{ class: klass }
@@ -1,3 +0,0 @@
1
- %a{ href: '&"\'<>' }
2
- - href = '&"\'<>'
3
- %a{ href: href }
@@ -1,4 +0,0 @@
1
- %div{ data: { disabled: false } }
2
- %div{ data: { disabled: true } }
3
- - hash = { 'user' => { id: 1234, name: 'k0kubun' }, book_id: 5432 }
4
- %div{ data: hash } data
@@ -1,4 +0,0 @@
1
- - hash = { disabled: false }
2
- %input{ hash }
3
- - hash = { disabled: true }
4
- %input{ hash }
@@ -1,4 +0,0 @@
1
- - hash = { class: %w[content active] }
2
- .book{ hash }
3
- - arr = %w[foo bar]
4
- .book(class=arr){ hash }
@@ -1,2 +0,0 @@
1
- - hash = { href: '&"\'<>' }
2
- %a{ hash }
@@ -1,2 +0,0 @@
1
- - hash = { data: { 'user' => { id: 1234, name: 'k0kubun' }, book_id: 5432 } }
2
- %div{ hash } data
@@ -1,2 +0,0 @@
1
- - hash = { id: %w[content active] }
2
- #book{ hash }
@@ -1,4 +0,0 @@
1
- - disabled = false
2
- %input{ disabled: disabled }
3
- - disabled = true
4
- %input{ disabled: disabled }
@@ -1,25 +0,0 @@
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
@@ -1,50 +0,0 @@
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 }
@@ -1,50 +0,0 @@
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 }
@@ -1,5 +0,0 @@
1
- - h = { 'user' => { id: 1234, name: 'eagletmt' }, book_id: 5432 }
2
- - c = %w[content active]
3
-
4
- %span.book{data: h, class: c}
5
- Book