p2 2.12 → 2.13
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 +4 -0
- data/lib/p2/compiler.rb +11 -7
- data/lib/p2/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: ba1f3d8dbb8965fd65ec2d047c69679a4a07b994495422eb3cf09ca39c47c338
|
4
|
+
data.tar.gz: 7247dff71984c7903de1043383ef4049f8e6e6149962aa9ec5600a490da2a0c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9c51b267d5e350b4806de9d2f27ea03680ccfa985d237e4909614ec8f384c304c67bde8981d3a7cc20e5c8ed3cdeb1066bad068847652f3073f7dc7b1023ad0
|
7
|
+
data.tar.gz: 4adbb063d72b4d52c61df05512a19a8845ada41cd7c958e6d66677876401de53804a95a3f66d520f16b40e55ad8c625de92c2d0755b8a1169e70fc00a9708136
|
data/CHANGELOG.md
CHANGED
data/lib/p2/compiler.rb
CHANGED
@@ -10,10 +10,10 @@ module P2
|
|
10
10
|
# A Compiler converts a template into an optimized form that generates HTML
|
11
11
|
# efficiently.
|
12
12
|
class Compiler < Sirop::Sourcifier
|
13
|
-
@@
|
13
|
+
@@html_debug_attribute_injector = nil
|
14
14
|
|
15
|
-
def self.
|
16
|
-
@@
|
15
|
+
def self.html_debug_attribute_injector=(proc)
|
16
|
+
@@html_debug_attribute_injector = proc
|
17
17
|
end
|
18
18
|
|
19
19
|
# Compiles the given proc, returning the generated source map and the
|
@@ -78,6 +78,7 @@ module P2
|
|
78
78
|
super(**)
|
79
79
|
@mode = mode
|
80
80
|
@pending_html_parts = []
|
81
|
+
@level = 0
|
81
82
|
end
|
82
83
|
|
83
84
|
# Initializes a source map.
|
@@ -157,6 +158,7 @@ module P2
|
|
157
158
|
# @param node [P2::TagNode] node
|
158
159
|
# @return [void]
|
159
160
|
def visit_tag_node(node)
|
161
|
+
@level += 1
|
160
162
|
tag = node.tag
|
161
163
|
|
162
164
|
# adjust_whitespace(node.location)
|
@@ -181,6 +183,8 @@ module P2
|
|
181
183
|
end
|
182
184
|
end
|
183
185
|
emit_html(node.location, format_html_tag_close(tag))
|
186
|
+
ensure
|
187
|
+
@level -= 1
|
184
188
|
end
|
185
189
|
|
186
190
|
# Visits a const tag node.
|
@@ -468,7 +472,7 @@ module P2
|
|
468
472
|
# @return [String] HTML
|
469
473
|
def format_html_tag_open(loc, tag, attributes)
|
470
474
|
tag = convert_tag(tag)
|
471
|
-
if attributes && attributes&.elements.size > 0 || @@
|
475
|
+
if attributes && attributes&.elements.size > 0 || @@html_debug_attribute_injector
|
472
476
|
"<#{tag} #{format_html_attributes(loc, attributes)}>"
|
473
477
|
else
|
474
478
|
"<#{tag}>"
|
@@ -599,10 +603,10 @@ module P2
|
|
599
603
|
# @param loc [Prism::Location] tag location
|
600
604
|
# @return [Hash] injected attributes hash
|
601
605
|
def compute_injected_attributes(loc)
|
602
|
-
return {} if (@mode == :xml) || !@@
|
606
|
+
return {} if (@mode == :xml) || !@@html_debug_attribute_injector
|
603
607
|
|
604
608
|
loc = loc_start(loc)
|
605
|
-
@@
|
609
|
+
@@html_debug_attribute_injector&.(@level, @fn, loc[0], loc[1] + 1)
|
606
610
|
end
|
607
611
|
|
608
612
|
# Computes injected attributes for the given tag location.
|
@@ -626,7 +630,7 @@ module P2
|
|
626
630
|
format_literal(key)
|
627
631
|
when Prism::FalseNode, Prism::NilNode
|
628
632
|
nil
|
629
|
-
when String
|
633
|
+
when String, Integer, Float, Symbol
|
630
634
|
"#{P2.underscores_to_dashes(key)}=\\\"#{value}\\\""
|
631
635
|
else
|
632
636
|
key = format_literal(key)
|
data/lib/p2/version.rb
CHANGED