hamlit 2.11.0 → 2.11.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: ea5913914011f369b96f45e350597bd102cd21adaa708c71bdd78e48a9d0379f
4
- data.tar.gz: 1e02820e534617ffe3df742ac06aa28b2c8ff49e3bf7d6b22d67bac36017e6f8
3
+ metadata.gz: 315b433bd4a2af17f13b1a8ff54787c65b25beabcbdb1274dd86b29248e75f60
4
+ data.tar.gz: cd02934b413dd1cf6891f35f5cb1ee8731d68e0f82eb300bf92679b7574ec598
5
5
  SHA512:
6
- metadata.gz: 0cb42767eb9b77de2c881d7c0b3546b086dd97f65a05a4cd81d525ff3428e5065c33a41bd0dbddf19045682181fd3eaf73fb541dbf930554d3bbe80c7fee77aa
7
- data.tar.gz: 47fe8b4b28777a5aaa84f37049b163625b24f1d111cb41e20df6275c2c49d3755cd8231aa81311019e0b961668c19f6ad43512d7eef6a7ff89dd26c38e6741ed
6
+ metadata.gz: 128daeb6d3f1d34fd33718b90b20b75117cda4147e8783d039b2daf0e019d836ac580d78fd3e01561f53f4348e442d3a04169761048cc2105ef1e3cae5c5c131
7
+ data.tar.gz: 0c11bc8dce803aa8d2adfdc78c7b91274678371adb7d30a8a36d997b60ada32320349712cd39c1feec7d965f5e1bbf6b6ab878a3769d4e20ee245afd1772bf79
@@ -9,11 +9,13 @@ matrix:
9
9
  include:
10
10
  - rvm: 2.3.8
11
11
  env: TASK=test
12
- - rvm: 2.4.5
12
+ - rvm: 2.4.9
13
13
  env: TASK=test
14
- - rvm: 2.5.3
14
+ - rvm: 2.5.7
15
15
  env: TASK=test
16
- - rvm: 2.6.0
16
+ - rvm: 2.6.5
17
+ env: TASK=test
18
+ - rvm: 2.7.0
17
19
  env: TASK=test
18
20
  - rvm: ruby-head
19
21
  env: TASK=test
@@ -21,19 +23,19 @@ matrix:
21
23
  env: TASK=test
22
24
  - rvm: truffleruby
23
25
  env: TASK=test
24
- - rvm: 2.6.0
26
+ - rvm: 2.7.0
25
27
  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.6.0
28
+ - rvm: 2.7.0
27
29
  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.6.0
30
+ - rvm: 2.7.0
29
31
  env: TASK=bench SLIM_BENCH=1
30
- - rvm: 2.6.0
32
+ - rvm: 2.7.0
31
33
  env: TASK=bench TEMPLATE=benchmark/etc/attribute_builder.haml
32
- - rvm: 2.6.0
34
+ - rvm: 2.7.0
33
35
  env: TASK=bench TEMPLATE=benchmark/etc/static_analyzer.haml
34
- - rvm: 2.6.0
36
+ - rvm: 2.7.0
35
37
  env: TASK=bench TEMPLATE=benchmark/etc/string_interpolation.haml
36
- - rvm: 2.6.0
38
+ - rvm: 2.7.0
37
39
  env: TASK=bench TEMPLATE=test/haml/templates/standard.haml COMPILE=1
38
40
  allow_failures:
39
41
  - rvm: ruby-head
@@ -4,7 +4,14 @@ 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.11.0](https://github.com/k0kubun/hamlit/compare/v2.10.0...v2.10.1) - 2019-12-12
7
+ ## [2.11.1](https://github.com/k0kubun/hamlit/compare/v2.11.0...v2.11.1) - 2020-08-25
8
+
9
+ ### Fixed
10
+
11
+ - Fix a line number on an error after filters like preserve, plain, and ruby.
12
+ *Thanks to @rgisiger*
13
+
14
+ ## [2.11.0](https://github.com/k0kubun/hamlit/compare/v2.10.1...v2.11.0) - 2019-12-12
8
15
 
9
16
  ### Added
10
17
 
data/Gemfile CHANGED
@@ -22,9 +22,7 @@ else
22
22
  gem 'redcarpet'
23
23
 
24
24
  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
25
+ gem 'faml'
28
26
  gem 'stackprof'
29
27
  end
30
28
  end
@@ -122,10 +122,10 @@ and merging multiple ids results in concatenation by "\_".
122
122
  %div{ id: false }
123
123
 
124
124
  # Output
125
- <div id='foo_bar'></span>
126
- <div id='foo_bar'></span>
127
- <div id='foo_bar'></span>
128
- <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>
129
129
  ```
130
130
 
131
131
  ### class attribute
@@ -1,4 +1,6 @@
1
1
  # frozen_string_literal: true
2
+ require 'hamlit/temple_line_counter'
3
+
2
4
  module Hamlit
3
5
  class Compiler
4
6
  class ChildrenCompiler
@@ -14,7 +16,7 @@ module Hamlit
14
16
  node.children.each do |n|
15
17
  rstrip_whitespace!(temple) if nuke_prev_whitespace?(n)
16
18
  insert_newlines!(temple, n)
17
- temple << yield(n)
19
+ temple << moving_lineno(n) { block.call(n) }
18
20
  temple << :whitespace if insert_whitespace?(n)
19
21
  end
20
22
  rstrip_whitespace!(temple) if nuke_inner_whitespace?(node)
@@ -27,19 +29,31 @@ module Hamlit
27
29
  (node.line - @lineno).times do
28
30
  temple << [:newline]
29
31
  end
32
+
30
33
  @lineno = node.line
34
+ end
31
35
 
36
+ def moving_lineno(node, &block)
37
+ # before: As they may have children, we need to increment lineno before compilation.
32
38
  case node.type
33
39
  when :script, :silent_script
34
40
  @lineno += 1
35
- when :filter
36
- @lineno += (node.value[:text] || '').split("\n").size
37
41
  when :tag
38
42
  node.value[:attributes_hashes].each do |attribute_hash|
39
43
  @lineno += attribute_hash.count("\n")
40
44
  end
41
45
  @lineno += 1 if node.children.empty? && node.value[:parse]
42
46
  end
47
+
48
+ temple = block.call # compile
49
+
50
+ # after: filter may not have children, and for some dynamic filters we can't predict the number of lines.
51
+ case node.type
52
+ when :filter
53
+ @lineno += TempleLineCounter.count_lines(temple)
54
+ end
55
+
56
+ temple
43
57
  end
44
58
 
45
59
  def confirm_whitespace(temple)
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+ module Hamlit
3
+ # A module to count lines of expected code. This would be faster than actual code generation
4
+ # and counting newlines in it.
5
+ module TempleLineCounter
6
+ class UnexpectedExpression < StandardError; end
7
+
8
+ def self.count_lines(exp)
9
+ type, *args = exp
10
+ case type
11
+ when :multi
12
+ args.map { |a| count_lines(a) }.reduce(:+) || 0
13
+ when :dynamic, :code
14
+ args.first.count("\n")
15
+ when :static
16
+ 0 # It has not real newline "\n" but escaped "\\n".
17
+ when :case
18
+ arg, *cases = args
19
+ arg.count("\n") + cases.map do |cond, e|
20
+ (cond == :else ? 0 : cond.count("\n")) + count_lines(e)
21
+ end.reduce(:+)
22
+ when :escape
23
+ count_lines(args[1])
24
+ when :newline
25
+ 1
26
+ else
27
+ raise UnexpectedExpression.new("[HAML BUG] Unexpected Temple expression '#{type}' is given!")
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Hamlit
3
- VERSION = '2.11.0'
3
+ VERSION = '2.11.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.11.0
4
+ version: 2.11.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: 2019-12-13 00:00:00.000000000 Z
11
+ date: 2020-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: temple
@@ -364,6 +364,7 @@ files:
364
364
  - lib/hamlit/ruby_expression.rb
365
365
  - lib/hamlit/string_splitter.rb
366
366
  - lib/hamlit/template.rb
367
+ - lib/hamlit/temple_line_counter.rb
367
368
  - lib/hamlit/utils.rb
368
369
  - lib/hamlit/version.rb
369
370
  homepage: https://github.com/k0kubun/hamlit
@@ -385,7 +386,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
385
386
  - !ruby/object:Gem::Version
386
387
  version: '0'
387
388
  requirements: []
388
- rubygems_version: 3.0.3
389
+ rubygems_version: 3.1.2
389
390
  signing_key:
390
391
  specification_version: 4
391
392
  summary: High Performance Haml Implementation