haml 7.4.1 → 7.5.0
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/haml/attribute_compiler.rb +13 -2
- data/lib/haml/attribute_parser.rb +8 -6
- data/lib/haml/compiler/children_compiler.rb +1 -3
- data/lib/haml/parser.rb +6 -0
- data/lib/haml/template.rb +1 -1
- data/lib/haml/temple_line_counter.rb +15 -1
- data/lib/haml/util.rb +0 -1
- data/lib/haml/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6436b78efc92438b9bd1a948dd0672bc8d3798c654fa2846d310386ef0552084
|
|
4
|
+
data.tar.gz: b8c2657b36c209e49c0e58c95470c45cc8213e30b1eb17458e0550db37bd616e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0530e52beb2fd093dfeb7d55c107b92a84f91e854bd38ed2e919349fcb820043cd3dd6e328ba4b2b24aa1b64ee8fcf2faf4a36dae1da60cb1b0a2b6abef7f531
|
|
7
|
+
data.tar.gz: b5a94fe5203318f1eaefa08b86e418090b8d0ef48cb94afa219512d87b116f568833cdf42e8f24a0a5e540d47b4b98dfb8a04f9e372bfe99d912d01dc41c2c24
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Haml Changelog
|
|
2
2
|
|
|
3
|
+
## 7.5.0
|
|
4
|
+
|
|
5
|
+
* Compile a multi-line attribute hash statically https://github.com/haml/haml/pull/1222
|
|
6
|
+
* Errors from multi-line attributes will be reported on the tag's line instead of the expression that raised the error.
|
|
7
|
+
|
|
3
8
|
## 7.4.1
|
|
4
9
|
|
|
5
10
|
* Build the preserve regex once per tag list instead of per call https://github.com/haml/haml/pull/1220
|
|
@@ -3,6 +3,7 @@ require 'set'
|
|
|
3
3
|
require 'haml/attribute_builder'
|
|
4
4
|
require 'haml/attribute_parser'
|
|
5
5
|
require 'haml/ruby_expression'
|
|
6
|
+
require 'haml/temple_line_counter'
|
|
6
7
|
|
|
7
8
|
module Haml
|
|
8
9
|
# The set of boolean attributes. You may add custom attributes to this constant.
|
|
@@ -24,12 +25,15 @@ module Haml
|
|
|
24
25
|
def compile(node)
|
|
25
26
|
hashes = []
|
|
26
27
|
return runtime_compile(node) if node.value[:object_ref] != :nil
|
|
27
|
-
|
|
28
|
+
dynamic_attributes = node.value[:dynamic_attributes]
|
|
29
|
+
[dynamic_attributes.new, dynamic_attributes.old].compact.each do |attribute_str|
|
|
28
30
|
hash = AttributeParser.parse(attribute_str)
|
|
29
31
|
return runtime_compile(node) if hash.nil? || hash.any? { |_key, value| value.empty? }
|
|
30
32
|
hashes << hash
|
|
31
33
|
end
|
|
32
|
-
static_compile(node.value[:attributes], hashes)
|
|
34
|
+
temple = static_compile(node.value[:attributes], hashes)
|
|
35
|
+
restore_newlines!(temple, dynamic_attributes)
|
|
36
|
+
temple
|
|
33
37
|
end
|
|
34
38
|
|
|
35
39
|
private
|
|
@@ -67,6 +71,13 @@ module Haml
|
|
|
67
71
|
temple
|
|
68
72
|
end
|
|
69
73
|
|
|
74
|
+
# ChildrenCompiler counts on the tag spanning as many lines as its attribute source does.
|
|
75
|
+
def restore_newlines!(temple, dynamic_attributes)
|
|
76
|
+
missing = dynamic_attributes.newline_count
|
|
77
|
+
missing -= TempleLineCounter.count_lines(temple) if missing > 0
|
|
78
|
+
missing.times { temple << [:newline] }
|
|
79
|
+
end
|
|
80
|
+
|
|
70
81
|
def compile_id!(temple, key, values)
|
|
71
82
|
build_code = attribute_builder(:id, values)
|
|
72
83
|
if values.all? { |type, exp| type == :static || Temple::StaticAnalyzer.static?(exp) }
|
|
@@ -15,15 +15,11 @@ module Haml
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
# @return [Hash,nil] - keys and values are the attribute source as written, or nil if
|
|
18
|
-
# the text is not a Hash literal whose keys are all static.
|
|
18
|
+
# the text is not a Hash literal whose keys are all static, or if it holds a heredoc.
|
|
19
19
|
def parse(text)
|
|
20
20
|
exp = wrap_bracket(text)
|
|
21
|
-
# A multi-line hash is left to the runtime, which keeps the [:newline] bookkeeping of
|
|
22
|
-
# the compiled code correct. Compiling it statically is a separate optimization.
|
|
23
|
-
return if exp.include?("\n")
|
|
24
|
-
|
|
25
21
|
node = hash_node(exp)
|
|
26
|
-
return if node.nil?
|
|
22
|
+
return if node.nil? || contains_heredoc?(exp, node)
|
|
27
23
|
|
|
28
24
|
hash = {}
|
|
29
25
|
node.elements.each do |element|
|
|
@@ -58,6 +54,12 @@ module Haml
|
|
|
58
54
|
node if node.is_a?(Prism::HashNode)
|
|
59
55
|
end
|
|
60
56
|
|
|
57
|
+
# A heredoc's body lies outside its node, so the value's slice would not be the value.
|
|
58
|
+
# Its opener always spells `<<`, which spares the tree walk for nearly every hash.
|
|
59
|
+
def contains_heredoc?(exp, node)
|
|
60
|
+
exp.include?('<<') && !node.breadth_first_search { |n| n.respond_to?(:heredoc?) && n.heredoc? }.nil?
|
|
61
|
+
end
|
|
62
|
+
|
|
61
63
|
# The key as written between its delimiters, not unescaped: an escape has to reach the
|
|
62
64
|
# attribute name as the source spelled it, like the `\0` of `{ "a\0b" => 1 }`.
|
|
63
65
|
def static_key(key)
|
|
@@ -40,9 +40,7 @@ module Haml
|
|
|
40
40
|
when :script, :silent_script
|
|
41
41
|
@lineno += 1
|
|
42
42
|
when :tag
|
|
43
|
-
|
|
44
|
-
@lineno += attribute_hash.count("\n")
|
|
45
|
-
end
|
|
43
|
+
@lineno += node.value[:dynamic_attributes].newline_count
|
|
46
44
|
@lineno += 1 if node.children.empty? && node.value[:parse]
|
|
47
45
|
end
|
|
48
46
|
|
data/lib/haml/parser.rb
CHANGED
|
@@ -247,6 +247,12 @@ module Haml
|
|
|
247
247
|
[new, stripped_old].compact.join(', ')
|
|
248
248
|
end
|
|
249
249
|
|
|
250
|
+
# The lines a tag spans beyond its first because of these attributes, which is what
|
|
251
|
+
# the compiled tag has to span too for the line numbers after it to hold.
|
|
252
|
+
def newline_count
|
|
253
|
+
(new ? new.count("\n") : 0) + (old ? old.count("\n") : 0)
|
|
254
|
+
end
|
|
255
|
+
|
|
250
256
|
private
|
|
251
257
|
|
|
252
258
|
# For `%foo{ { foo: 1 }, bar: 2 }`, :old is "{ { foo: 1 }, bar: 2 }" and this method returns " { foo: 1 }, bar: 2 " for last argument.
|
data/lib/haml/template.rb
CHANGED
|
@@ -19,13 +19,27 @@ module Haml
|
|
|
19
19
|
arg.count("\n") + cases.map do |cond, e|
|
|
20
20
|
(cond == :else ? 0 : cond.count("\n")) + count_lines(e)
|
|
21
21
|
end.reduce(:+)
|
|
22
|
-
when :escape
|
|
22
|
+
when :escape, :fescape
|
|
23
23
|
count_lines(args[1])
|
|
24
|
+
when :html
|
|
25
|
+
count_html_lines(args)
|
|
24
26
|
when :newline
|
|
25
27
|
1
|
|
26
28
|
else
|
|
27
29
|
raise UnexpectedExpression.new("[HAML BUG] Unexpected Temple expression '#{type}' is given!")
|
|
28
30
|
end
|
|
29
31
|
end
|
|
32
|
+
|
|
33
|
+
def self.count_html_lines(args)
|
|
34
|
+
case args[0]
|
|
35
|
+
when :attrs
|
|
36
|
+
args.drop(1).sum { |a| count_lines(a) }
|
|
37
|
+
when :attr
|
|
38
|
+
count_lines(args[2])
|
|
39
|
+
else
|
|
40
|
+
raise UnexpectedExpression.new("[HAML BUG] Unexpected Temple expression 'html #{args[0]}' is given!")
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
private_class_method :count_html_lines
|
|
30
44
|
end
|
|
31
45
|
end
|
data/lib/haml/util.rb
CHANGED
data/lib/haml/version.rb
CHANGED