klenod-build 0.0.22 → 0.0.23

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: d7873fce94ba35f8420b6aa896bca1866896d5c9f038102f0d13522fb1fa9a16
4
- data.tar.gz: 715c13a86148ae750ed6151f05e4fbcb32d1d73bf21d139d1b21d42f7bb405f4
3
+ metadata.gz: ac47aee2306ee0d732be8f5959e27c168022a6b6d9cc8f6fec350e8cde16e38d
4
+ data.tar.gz: a3af1863c0c21df86885135fdd7c29d8b6a48b3997eb125fe00b0f02c72c5a64
5
5
  SHA512:
6
- metadata.gz: 29157efe18cfdd5982f05ef742f07bb56ee64f54c820b152569be703b76a97dc76f71c166b67ff57e8b5124bed59f16ecbcf39415118dba3672a304854d4fbfa
7
- data.tar.gz: 0a0b9e45f353aa70004c01ed9f78d1fe6ef667c7eb4faa5e7c64d038087ed82501c7f77755ed5e67dd26504ac122ee14a7c5414164b36c5933afae86df89df37
6
+ metadata.gz: 17abab231fe71a6022e15a5ed712273ce59b4234e0593211ea9fb4614cfa089dc0fa8c4930a058a0034e2703c13a979cc3b0e23437b1e930f465c0361fdff419
7
+ data.tar.gz: e5305dbcc39bc6ae1bfb14369060806b333d3e091ff562d4030136e514149ee658fdd964abf5372693575227f8a69ed7364e08551510a14b924c4b85005581f2
@@ -40,13 +40,28 @@ module Klenod
40
40
  # `video` plus a `.id` class. Extend that form to ordinary Ruby
41
41
  # member and index expressions while leaving all other attributes on
42
42
  # Haml's native parsing path.
43
+ #
44
+ # Haml also continues a parenthesized list onto following lines only
45
+ # after the first attribute, so `%a(` followed by a line break is an
46
+ # invalid attribute list. Join the lines of an unclosed list first so
47
+ # both forms work across lines.
43
48
  def parse_new_attributes(text)
44
- balanced, rest = ::Haml::Util.balance(text, "(", ")")
45
- pairs = balanced && extended_attribute_pairs(balanced[1...-1])
46
- return super unless pairs&.any? { |_name, value| value.match?(/[.\[]/) }
49
+ joined_lines = 0
50
+ until (close_index = attribute_list_close_index(text)) || @next_line.eod?
51
+ text = "#{text} #{@next_line.text}"
52
+ joined_lines += 1
53
+ next_line
54
+ end
55
+
56
+ pairs = close_index && extended_attribute_pairs(text[1...close_index])
57
+ rest = close_index && text[(close_index + 1)..]
58
+ unless pairs&.any? { |_name, value| value.match?(/[.\[]/) }
59
+ attributes, rest, last_line = super
60
+ return [attributes, rest, last_line + joined_lines]
61
+ end
47
62
 
48
63
  dynamic = pairs.reduce("{") { |source, (name, value)| "#{source}#{::Haml::Util.inspect_obj(name)} => #{value}," } << "}"
49
- [[{}, dynamic], rest, @line.index + 1]
64
+ [[{}, dynamic], rest, @line.index + 1 + joined_lines]
50
65
  end
51
66
 
52
67
  def annotate_tag_nodes(root)
@@ -132,6 +147,36 @@ module Klenod
132
147
  pairs
133
148
  end
134
149
 
150
+ # Returns the index of the `)` that closes the list opened at index 0,
151
+ # ignoring brackets inside quoted values.
152
+ def attribute_list_close_index(source)
153
+ depth = 0
154
+ quote = nil
155
+ escaped = false
156
+
157
+ source.each_char.with_index do |character, index|
158
+ if quote
159
+ if escaped
160
+ escaped = false
161
+ elsif character == "\\"
162
+ escaped = true
163
+ elsif character == quote
164
+ quote = nil
165
+ end
166
+ else
167
+ case character
168
+ when "'", '"' then quote = character
169
+ when "(", "[", "{" then depth += 1
170
+ when ")", "]", "}"
171
+ depth -= 1
172
+ return index if depth.zero?
173
+ end
174
+ end
175
+ end
176
+
177
+ nil
178
+ end
179
+
135
180
  def attribute_boundary?(remaining_source)
136
181
  attribute_sequence?(remaining_source)
137
182
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Klenod
4
4
  module Build
5
- VERSION = "0.0.22"
5
+ VERSION = "0.0.23"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: klenod-build
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.22
4
+ version: 0.0.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrés Alin
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - '='
17
17
  - !ruby/object:Gem::Version
18
- version: 0.0.22
18
+ version: 0.0.23
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - '='
24
24
  - !ruby/object:Gem::Version
25
- version: 0.0.22
25
+ version: 0.0.23
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: async
28
28
  requirement: !ruby/object:Gem::Requirement