haml 5.2.0 → 5.2.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: ccbf9b5c93745c83284467b77b73dd156f049dacf55861dd486bd14404d84e84
4
- data.tar.gz: 4e2439c5e370db4bd765ca76ab4d76c027d9a9f9f6b68e5d38761e6858f3312f
3
+ metadata.gz: e3182fca5b2f85849a1abd849d3352858834737b83b7d57d4d29c19e84518f1c
4
+ data.tar.gz: ea005149aeccb8247ff121a4a33b3118d289f18ed5f12b101fd739892fb4edae
5
5
  SHA512:
6
- metadata.gz: f0c7b716e9866070fc50281e4486eb519832c3f098cbd58bb62ca18f2659ca85bc44cd6a275121fe71f37f8d9e442ac9b75f254b28747b5fbff47a98b1e633c5
7
- data.tar.gz: 3e870080f42d925cddc479a52318d2cb8e6a9dbfd5613e8027c0c4dfd80e4f7636fa9f50cd41d3eca6f72f12bcc1cc7e5a5b2b9120223e1e6218ad8d6dcf9ca8
6
+ metadata.gz: e8fcd8c9cb45217a405820c13d69330ef53c82aa22b25026d0886937505a5dc101803c55087f74cc5467a1930f43bd5ab6fd7d44d69e1234aeab06db634b8fdd
7
+ data.tar.gz: b8c0f35f75c6beac4e27c7066eefbf8385346abecbdab2cb3303b2ea2a3f19dfc2d209f171c0801d383d9bc3bd526721e674939e808ec2763712bbd94c7110d8
@@ -9,6 +9,9 @@ rvm:
9
9
  - 2.6
10
10
  - 2.5
11
11
  - jruby-9.2
12
+ env:
13
+ - RUBYOPT="--enable-frozen-string-literal"
14
+ - RUBYOPT=""
12
15
  gemfile:
13
16
  - test/gemfiles/Gemfile.rails-6.0.x
14
17
  - test/gemfiles/Gemfile.rails-5.2.x
@@ -26,24 +29,60 @@ matrix:
26
29
  gemfile: test/gemfiles/Gemfile.rails-4.1.x
27
30
  - rvm: 2.5
28
31
  gemfile: test/gemfiles/Gemfile.rails-4.2.x
32
+ - rvm: 2.5
33
+ gemfile: test/gemfiles/Gemfile.rails-5.0.x
34
+ env: RUBYOPT="--enable-frozen-string-literal"
35
+ - rvm: 2.5
36
+ gemfile: test/gemfiles/Gemfile.rails-5.0.x.erubi
37
+ env: RUBYOPT="--enable-frozen-string-literal"
38
+ - rvm: 2.5
39
+ gemfile: test/gemfiles/Gemfile.rails-5.1.x
40
+ env: RUBYOPT="--enable-frozen-string-literal"
29
41
  - rvm: 2.6
30
42
  gemfile: test/gemfiles/Gemfile.rails-4.0.x
31
43
  - rvm: 2.6
32
44
  gemfile: test/gemfiles/Gemfile.rails-4.1.x
33
45
  - rvm: 2.6
34
46
  gemfile: test/gemfiles/Gemfile.rails-4.2.x
47
+ - rvm: 2.6
48
+ gemfile: test/gemfiles/Gemfile.rails-5.0.x
49
+ env: RUBYOPT="--enable-frozen-string-literal"
50
+ - rvm: 2.6
51
+ gemfile: test/gemfiles/Gemfile.rails-5.0.x.erubi
52
+ env: RUBYOPT="--enable-frozen-string-literal"
53
+ - rvm: 2.6
54
+ gemfile: test/gemfiles/Gemfile.rails-5.1.x
55
+ env: RUBYOPT="--enable-frozen-string-literal"
35
56
  - rvm: 2.7
36
57
  gemfile: test/gemfiles/Gemfile.rails-4.0.x
37
58
  - rvm: 2.7
38
59
  gemfile: test/gemfiles/Gemfile.rails-4.1.x
39
60
  - rvm: 2.7
40
61
  gemfile: test/gemfiles/Gemfile.rails-4.2.x
62
+ - rvm: 2.7
63
+ gemfile: test/gemfiles/Gemfile.rails-5.0.x
64
+ env: RUBYOPT="--enable-frozen-string-literal"
65
+ - rvm: 2.7
66
+ gemfile: test/gemfiles/Gemfile.rails-5.0.x.erubi
67
+ env: RUBYOPT="--enable-frozen-string-literal"
68
+ - rvm: 2.7
69
+ gemfile: test/gemfiles/Gemfile.rails-5.1.x
70
+ env: RUBYOPT="--enable-frozen-string-literal"
41
71
  - rvm: ruby-head
42
72
  gemfile: test/gemfiles/Gemfile.rails-4.0.x
43
73
  - rvm: ruby-head
44
74
  gemfile: test/gemfiles/Gemfile.rails-4.1.x
45
75
  - rvm: ruby-head
46
76
  gemfile: test/gemfiles/Gemfile.rails-4.2.x
77
+ - rvm: jruby-9.2
78
+ gemfile: test/gemfiles/Gemfile.rails-5.0.x
79
+ env: RUBYOPT="--enable-frozen-string-literal"
80
+ - rvm: jruby-9.2
81
+ gemfile: test/gemfiles/Gemfile.rails-5.0.x.erubi
82
+ env: RUBYOPT="--enable-frozen-string-literal"
83
+ - rvm: jruby-9.2
84
+ gemfile: test/gemfiles/Gemfile.rails-5.1.x
85
+ env: RUBYOPT="--enable-frozen-string-literal"
47
86
  include:
48
87
  - rvm: 2.7
49
88
  gemfile: test/gemfiles/Gemfile.rails-edge
@@ -69,4 +108,4 @@ before_install:
69
108
  - ./cc-test-reporter before-build
70
109
  script: "bundle exec rake submodules test"
71
110
  after_script:
72
- - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
111
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
@@ -1,9 +1,16 @@
1
1
  # Haml Changelog
2
2
 
3
+ ## 5.2.1
4
+
5
+ Released on November 30, 2020
6
+ ([diff](https://github.com/haml/haml/compare/v5.2.0...v5.2.1)).
7
+
8
+ * Add in improved "multiline" support for attributes [#1043](https://github.com/haml/haml/issues/1043)
9
+
3
10
  ## 5.2
4
11
 
5
12
  Released on September 28, 2020
6
- ([diff](https://github.com/haml/haml/compare/v5.1.2...v5.2)).
13
+ ([diff](https://github.com/haml/haml/compare/v5.1.2...v5.2.0)).
7
14
 
8
15
  * Fix crash in the attribute optimizer when `#inspect` is overridden in TrueClass / FalseClass [#972](https://github.com/haml/haml/issues/972)
9
16
  * Do not HTML-escape templates that are declared to be plaintext [#1014](https://github.com/haml/haml/issues/1014) (Thanks [@cesarizu](https://github.com/cesarizu))
@@ -228,15 +228,19 @@ is compiled to:
228
228
  <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'></html>
229
229
 
230
230
  Attribute hashes can also be stretched out over multiple lines to accommodate
231
- many attributes. However, newlines may only be placed immediately after commas.
232
- For example:
231
+ many attributes.
233
232
 
234
- %script{:type => "text/javascript",
235
- :src => "javascripts/script_#{2 + 7}"}
233
+ %script{
234
+ "type": text/javascript",
235
+ "src": javascripts/script_#{2 + 7}",
236
+ "data": {
237
+ "controller": "reporter",
238
+ },
239
+ }
236
240
 
237
241
  is compiled to:
238
242
 
239
- <script src='javascripts/script_9' type='text/javascript'></script>
243
+ <script src='javascripts/script_9' type='text/javascript' data-controller='reporter'></script>
240
244
 
241
245
  #### `:class` and `:id` Attributes {#class-and-id-attributes}
242
246
 
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency 'rbench'
33
33
  spec.add_development_dependency 'minitest', '>= 4.0'
34
34
  spec.add_development_dependency 'nokogiri'
35
- spec.add_development_dependency 'simplecov', '0.17.1' # Locked to this version due to https://github.com/codeclimate/test-reporter/issues/418
35
+ spec.add_development_dependency 'simplecov'
36
36
 
37
37
  spec.description = <<-END
38
38
  Haml (HTML Abstraction Markup Language) is a layer on top of HTML or XML that's
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'ripper'
3
4
  require 'strscan'
4
5
 
5
6
  module Haml
@@ -90,6 +91,9 @@ module Haml
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 = Options.wrap(options)
95
99
  # Record the indent levels of "if" statements to validate the subsequent
@@ -651,13 +655,18 @@ module Haml
651
655
  # @return [String] rest
652
656
  # @return [Integer] last_line
653
657
  def parse_old_attributes(text)
654
- text = text.dup
655
658
  last_line = @line.index + 1
656
659
 
657
660
  begin
658
- attributes_hash, rest = balance(text, ?{, ?})
661
+ # Old attributes often look like a valid Hash literal, but it sometimes allow code like
662
+ # `{ hash, foo: bar }`, which is compiled to `_hamlout.attributes({}, nil, hash, foo: bar)`.
663
+ #
664
+ # To scan such code correctly, this scans `a( hash, foo: bar }` instead, stops when there is
665
+ # 1 more :on_embexpr_end (the last '}') than :on_embexpr_beg, and resurrects '{' afterwards.
666
+ balanced, rest = balance_tokens(text.sub(?{, METHOD_CALL_PREFIX), :on_embexpr_beg, :on_embexpr_end, count: 1)
667
+ attributes_hash = balanced.sub(METHOD_CALL_PREFIX, ?{)
659
668
  rescue SyntaxError => e
660
- if text.strip[-1] == ?, && e.message == Error.message(:unbalanced_brackets)
669
+ if e.message == Error.message(:unbalanced_brackets) && !@template.empty?
661
670
  text << "\n#{@next_line.text}"
662
671
  last_line += 1
663
672
  next_line
@@ -811,6 +820,25 @@ module Haml
811
820
  Haml::Util.balance(*args) or raise(SyntaxError.new(Error.message(:unbalanced_brackets)))
812
821
  end
813
822
 
823
+ # Unlike #balance, this balances Ripper tokens to balance something like `{ a: "}" }` correctly.
824
+ def balance_tokens(buf, start, finish, count: 0)
825
+ text = ''.dup
826
+ Ripper.lex(buf).each do |_, token, str|
827
+ text << str
828
+ case token
829
+ when start
830
+ count += 1
831
+ when finish
832
+ count -= 1
833
+ end
834
+
835
+ if count == 0
836
+ return text, buf.sub(text, '')
837
+ end
838
+ end
839
+ raise SyntaxError.new(Error.message(:unbalanced_brackets))
840
+ end
841
+
814
842
  def block_opened?
815
843
  @next_line.tabs > @line.tabs
816
844
  end
@@ -213,7 +213,7 @@ MSG
213
213
  scan.scan(/\w+/)
214
214
  end
215
215
  content = eval("\"#{interpolated}\"")
216
- content.prepend(char) if char == '@' || char == '$'
216
+ content = "#{char}#{content}" if char == '@' || char == '$'
217
217
  content = "Haml::Helpers.html_escape((#{content}))" if escape_html
218
218
 
219
219
  res << "\#{#{content}}"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Haml
4
- VERSION = "5.2.0"
4
+ VERSION = "5.2.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.0
4
+ version: 5.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Natalie Weizenbaum
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2020-09-28 00:00:00.000000000 Z
14
+ date: 2020-11-30 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: temple
@@ -101,16 +101,16 @@ dependencies:
101
101
  name: simplecov
102
102
  requirement: !ruby/object:Gem::Requirement
103
103
  requirements:
104
- - - '='
104
+ - - ">="
105
105
  - !ruby/object:Gem::Version
106
- version: 0.17.1
106
+ version: '0'
107
107
  type: :development
108
108
  prerelease: false
109
109
  version_requirements: !ruby/object:Gem::Requirement
110
110
  requirements:
111
- - - '='
111
+ - - ">="
112
112
  - !ruby/object:Gem::Version
113
- version: 0.17.1
113
+ version: '0'
114
114
  description: |
115
115
  Haml (HTML Abstraction Markup Language) is a layer on top of HTML or XML that's
116
116
  designed to express the structure of documents in a non-repetitive, elegant, and