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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c26b9c214f11c471fb039fba72fdde0b98f8d7c85864ec9db271a295f2e078fa
4
- data.tar.gz: 52dc0929deb222d22e496cf451ee927f5047403e1b687f1588e2dccc74f59135
3
+ metadata.gz: ba1f3d8dbb8965fd65ec2d047c69679a4a07b994495422eb3cf09ca39c47c338
4
+ data.tar.gz: 7247dff71984c7903de1043383ef4049f8e6e6149962aa9ec5600a490da2a0c9
5
5
  SHA512:
6
- metadata.gz: cb6032e2a12263ca0ff29cf00b677d1aa88dbd2becf57e662d09c857ecc39e4670af18b1b6493e548b83a4e73d010822b3cca4b07b4ed372e5b63d566bd11861
7
- data.tar.gz: cbdbaf04e4beb275463b38ee453b93dac751a74166f3264a41269177f869a04a2082999dc4f2adca03ef85b075d5726fbc0300bb5ffa9d27041bddaf146b87f3
6
+ metadata.gz: e9c51b267d5e350b4806de9d2f27ea03680ccfa985d237e4909614ec8f384c304c67bde8981d3a7cc20e5c8ed3cdeb1066bad068847652f3073f7dc7b1023ad0
7
+ data.tar.gz: 4adbb063d72b4d52c61df05512a19a8845ada41cd7c958e6d66677876401de53804a95a3f66d520f16b40e55ad8c625de92c2d0755b8a1169e70fc00a9708136
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 2.13 2025-09-11
2
+
3
+ - Pass level to HTML debug attribute injection proc
4
+
1
5
  # 2.12 2025-09-11
2
6
 
3
7
  - Add support for injecting location attributes into HTML tags (for debug purposes)
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
- @@html_atts_injector = nil
13
+ @@html_debug_attribute_injector = nil
14
14
 
15
- def self.html_atts_injector=(proc)
16
- @@html_atts_injector = proc
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 || @@html_atts_injector
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) || !@@html_atts_injector
606
+ return {} if (@mode == :xml) || !@@html_debug_attribute_injector
603
607
 
604
608
  loc = loc_start(loc)
605
- @@html_atts_injector&.(@fn, loc[0], loc[1] + 1)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module P2
4
- VERSION = '2.12'
4
+ VERSION = '2.13'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: p2
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.12'
4
+ version: '2.13'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner