hamlit 2.13.0 → 2.13.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b080bac2aef1f473d967c016e0610d319cd43b89fbaea3a113949ed6dacfd04
4
- data.tar.gz: be1115f4778772e95102c2ab995abd7ff7f3f6c9e86ab8eefac26a38b1a20bd2
3
+ metadata.gz: 49336d834649a0b858580664e658063bdc7286d2a1daac3f669da539fff775a1
4
+ data.tar.gz: 7606a4faf12c5ef04146fe336c827c518277fb4db9391167fba38a16b33ebfc5
5
5
  SHA512:
6
- metadata.gz: 2b5a640a456b34d551d4e65df868d59c027f4566ff357643f2b42458417356599f6d2cb3a9413ff17e431c69d782f2b9e5a603de147e1a6947f646910d8c3bf4
7
- data.tar.gz: d13cb779bc02e9914f754054a7b8ab6b2ff6721259b15c87638fbbb2b6a528323b407e22ce4fcdd0a1e91ab1c7f05c5cd7d26e19b96016efaf91b1a188ac6579
6
+ metadata.gz: 5f69bcd2ded91a2dd610fb0ec270a623a8abd4ffcec5c5df94b9779cacbec10228bceb71fbf480aa076261b5b2d5448d52b38adf6df203a1a5661aea8ff640c0
7
+ data.tar.gz: fbd9a6ee757236f8b02b670ca781669fc24f1d81644210bfa40a7d611a2b4b040cdd7694a8a6fb8c711409f2ff42fada31c6693d60de9c246b5d2ffd74c34d9d
@@ -0,0 +1,30 @@
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
+ container: ${{ matrix.ruby }}
17
+ strategy:
18
+ fail-fast: false
19
+ matrix:
20
+ ruby:
21
+ - ruby:2.5
22
+ - ruby:2.6
23
+ - ruby:2.7
24
+ # TODO: add jruby and truffleruby
25
+ steps:
26
+ - uses: actions/checkout@v2
27
+ - run: apt-get update && apt-get install -y nodejs # For execjs
28
+ - name: bundle install
29
+ run: bundle install -j$(nproc) --retry 3
30
+ - run: bundle exec rake test
@@ -4,7 +4,13 @@ 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
7
+ ## [2.13.1](https://github.com/k0kubun/hamlit/compare/v2.13.0...v2.13.1) - 2020-12-27
8
+
9
+ ### Added
10
+
11
+ - Support [multiline attributes](https://github.com/haml/haml/pull/1043) of Haml 5.2.1.
12
+
13
+ ## [2.13.0](https://github.com/k0kubun/hamlit/compare/v2.12.0...v2.13.0) - 2020-10-02
8
14
 
9
15
  ### Added
10
16
 
@@ -16,6 +22,7 @@ project adheres to [Semantic Versioning](http://semver.org/). This change log is
16
22
  - Upgrade the Haml parser from Haml 4.0 to 5.2 [#163](https://github.com/k0kubun/hamlit/issues/163).
17
23
  - Allow `@` as tag's class name.
18
24
  - Fix NameError on an `InvalidAttributeNameError` reference introduced at Hamlit v2.12.0.
25
+ - You can no longer specify `ugly` option, which has had no effect.
19
26
 
20
27
  ## [2.12.0](https://github.com/k0kubun/hamlit/compare/v2.11.1...v2.12.0) - 2020-09-30
21
28
 
data/README.md CHANGED
@@ -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?
Binary file
Binary file
@@ -3,7 +3,7 @@ require 'fileutils'
3
3
  require 'tmpdir'
4
4
 
5
5
  HAML_REPO = 'haml/haml'
6
- HAML_VERSION = 'v5.2.0'
6
+ HAML_VERSION = '5.2.1'
7
7
 
8
8
  module GitHubFetcher
9
9
  def self.fetch(repo, tag:, path:)
@@ -76,7 +76,7 @@ class HamlitParserBuilder
76
76
 
77
77
  DUMMY_CLASSES.each do |file, klass|
78
78
  dest_path = File.join(@hamlit_parser, "haml_#{file}")
79
- src = "class Hamlit::Haml#{klass}; end"
79
+ src = "class Hamlit::Haml#{klass}; end\n"
80
80
  File.write(dest_path, src)
81
81
  end
82
82
  end
@@ -37,7 +37,7 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency 'haml', '>= 5'
38
38
  spec.add_development_dependency 'less'
39
39
  spec.add_development_dependency 'minitest-reporters', '~> 1.1'
40
- spec.add_development_dependency 'rails', '>= 4.0.0'
40
+ spec.add_development_dependency 'rails', '>= 4.0'
41
41
  spec.add_development_dependency 'rake'
42
42
  spec.add_development_dependency 'rake-compiler'
43
43
  spec.add_development_dependency 'sass'
@@ -1 +1 @@
1
- class Hamlit::HamlCompiler; end
1
+ class Hamlit::HamlCompiler; end
@@ -1 +1 @@
1
- class Hamlit::HamlEscapable; end
1
+ class Hamlit::HamlEscapable; end
@@ -1 +1 @@
1
- class Hamlit::HamlGenerator; end
1
+ class Hamlit::HamlGenerator; end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'ripper'
3
4
  require 'strscan'
4
5
 
5
6
  module Hamlit
@@ -90,6 +91,9 @@ module Hamlit
90
91
  ID_KEY = 'id'.freeze
91
92
  CLASS_KEY = 'class'.freeze
92
93
 
94
+ # Used for scanning old attributes, substituting the first '{'
95
+ METHOD_CALL_PREFIX = 'a('
96
+
93
97
  def initialize(options)
94
98
  @options = HamlOptions.wrap(options)
95
99
  # Record the indent levels of "if" statements to validate the subsequent
@@ -655,13 +659,18 @@ module Hamlit
655
659
  # @return [String] rest
656
660
  # @return [Integer] last_line
657
661
  def parse_old_attributes(text)
658
- text = text.dup
659
662
  last_line = @line.index + 1
660
663
 
661
664
  begin
662
- attributes_hash, rest = balance(text, ?{, ?})
665
+ # Old attributes often look like a valid Hash literal, but it sometimes allow code like
666
+ # `{ hash, foo: bar }`, which is compiled to `_hamlout.attributes({}, nil, hash, foo: bar)`.
667
+ #
668
+ # To scan such code correctly, this scans `a( hash, foo: bar }` instead, stops when there is
669
+ # 1 more :on_embexpr_end (the last '}') than :on_embexpr_beg, and resurrects '{' afterwards.
670
+ balanced, rest = balance_tokens(text.sub(?{, METHOD_CALL_PREFIX), :on_embexpr_beg, :on_embexpr_end, count: 1)
671
+ attributes_hash = balanced.sub(METHOD_CALL_PREFIX, ?{)
663
672
  rescue HamlSyntaxError => e
664
- if text.strip[-1] == ?, && e.message == HamlError.message(:unbalanced_brackets)
673
+ if e.message == HamlError.message(:unbalanced_brackets) && !@template.empty?
665
674
  text << "\n#{@next_line.text}"
666
675
  last_line += 1
667
676
  next_line
@@ -815,6 +824,25 @@ module Hamlit
815
824
  Hamlit::HamlUtil.balance(*args) or raise(HamlSyntaxError.new(HamlError.message(:unbalanced_brackets)))
816
825
  end
817
826
 
827
+ # Unlike #balance, this balances Ripper tokens to balance something like `{ a: "}" }` correctly.
828
+ def balance_tokens(buf, start, finish, count: 0)
829
+ text = ''.dup
830
+ Ripper.lex(buf).each do |_, token, str|
831
+ text << str
832
+ case token
833
+ when start
834
+ count += 1
835
+ when finish
836
+ count -= 1
837
+ end
838
+
839
+ if count == 0
840
+ return text, buf.sub(text, '')
841
+ end
842
+ end
843
+ raise HamlSyntaxError.new(HamlError.message(:unbalanced_brackets))
844
+ end
845
+
818
846
  def block_opened?
819
847
  @next_line.tabs > @line.tabs
820
848
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Hamlit
3
- VERSION = '2.13.0'
3
+ VERSION = '2.13.1'
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.13.0
4
+ version: 2.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Kokubun
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-02 00:00:00.000000000 Z
11
+ date: 2020-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: temple
@@ -156,14 +156,14 @@ dependencies:
156
156
  requirements:
157
157
  - - ">="
158
158
  - !ruby/object:Gem::Version
159
- version: 4.0.0
159
+ version: '4.0'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
- version: 4.0.0
166
+ version: '4.0'
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: rake
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -257,8 +257,8 @@ extensions:
257
257
  - ext/hamlit/extconf.rb
258
258
  extra_rdoc_files: []
259
259
  files:
260
+ - ".github/workflows/test.yml"
260
261
  - ".gitignore"
261
- - ".travis.yml"
262
262
  - CHANGELOG.md
263
263
  - Gemfile
264
264
  - LICENSE.txt
@@ -287,6 +287,8 @@ files:
287
287
  - benchmark/etc/tags_loop.haml
288
288
  - benchmark/ext/build_data.rb
289
289
  - benchmark/ext/build_id.rb
290
+ - benchmark/graph/graph.key
291
+ - benchmark/graph/graph.png
290
292
  - benchmark/id_attribute.haml
291
293
  - benchmark/plain.haml
292
294
  - benchmark/script.haml
@@ -389,7 +391,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
389
391
  - !ruby/object:Gem::Version
390
392
  version: '0'
391
393
  requirements: []
392
- rubygems_version: 3.1.2
394
+ rubygems_version: 3.1.4
393
395
  signing_key:
394
396
  specification_version: 4
395
397
  summary: High Performance Haml Implementation
@@ -1,53 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- branches:
4
- only:
5
- - master
6
- script:
7
- - bundle exec rake $TASK
8
- env:
9
- - RUBYOPT='-w'
10
- matrix:
11
- include:
12
- - rvm: 2.3.8
13
- env: TASK=test
14
- - rvm: 2.4.9
15
- env: TASK=test
16
- - rvm: 2.5.7
17
- env: TASK=test
18
- - rvm: 2.6.5
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'
24
- - rvm: ruby-head
25
- env: TASK=test
26
- - rvm: jruby-9.2.8.0
27
- env: TASK=test
28
- - rvm: truffleruby
29
- env: TASK=test
30
- - rvm: 2.7.0
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
32
- - rvm: 2.7.0
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
34
- - rvm: 2.7.0
35
- env: TASK=bench SLIM_BENCH=1
36
- - rvm: 2.7.0
37
- env: TASK=bench TEMPLATE=benchmark/etc/attribute_builder.haml
38
- - rvm: 2.7.0
39
- env: TASK=bench TEMPLATE=benchmark/etc/static_analyzer.haml
40
- - rvm: 2.7.0
41
- env: TASK=bench TEMPLATE=benchmark/etc/string_interpolation.haml
42
- - rvm: 2.7.0
43
- env: TASK=bench TEMPLATE=test/haml/templates/standard.haml COMPILE=1
44
- allow_failures:
45
- - rvm: ruby-head
46
- env: TASK=test
47
- - env: TASK=bench TEMPLATE=benchmark/boolean_attribute.haml,benchmark/class_attribute.haml,benchmark/id_attribute.haml,benchmark/data_attribute.haml,benchmark/common_attribute.haml
48
- - 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
49
- - env: TASK=bench SLIM_BENCH=1
50
- - env: TASK=bench TEMPLATE=benchmark/etc/attribute_builder.haml
51
- - env: TASK=bench TEMPLATE=benchmark/etc/static_analyzer.haml
52
- - env: TASK=bench TEMPLATE=benchmark/etc/string_interpolation.haml
53
- - env: TASK=bench TEMPLATE=test/haml/templates/standard.haml COMPILE=1