hot_module 1.0.0.alpha12 → 1.0.0.alpha13

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: 51da117a031a9b9ad3c16a35b4b5276928874e742bf72e90bc9e1089f4b856a1
4
- data.tar.gz: b1bb49f906b3dbc82671ec7a4850baac1899c93ce3237cc88c8bb3c69dff75f3
3
+ metadata.gz: 90f40d53a3d644454adb306af193e5258970067eaa31075263c13ce31ce23b3f
4
+ data.tar.gz: f3308d84a9605fce9edeff88e00e29ce88ebee8d5dcde9f96439b46f6a512567
5
5
  SHA512:
6
- metadata.gz: 0b6b8661ec4ee9f416eff3373a049c126a744e5bd280ddf88fac6d896f58df1f844f170ddc85d5addbd099e70e5fc8f5d3421a966ea5b13bba2f568eb2bc8f86
7
- data.tar.gz: d50b1b02e71f78e14ebde1c8c08abcd80eb79911fd1fafcf15de6a89ea5c412db50ddeecc23e804f05acee61b8d75d1be8ca5bef38937105b779f32b39b4e6e4
6
+ metadata.gz: aa8b2ce963950a27f69a65c23db73f544fd52e84ab5b0d200667fc2e2a976dc2a8121c6fa7de0b4e4a50f8abb49d7243b484aea7210fc14cb3e8708414050248
7
+ data.tar.gz: 8a4a0de3a7dbd16b019327282ec3f1e604a622baf4f47dc21fffe6cd2ed9c25170de5d453ea43185deffe344fcd5324cd8696aff2046821b7988179ec4edc677
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hot_module (1.0.0.alpha12)
4
+ hot_module (1.0.0.alpha13)
5
5
  concurrent-ruby (~> 1.2)
6
6
  nokolexbor (>= 0.4.2)
7
7
 
@@ -1,10 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HoTModuLe
4
- class View < Bridgetown::ERBView
5
- attr_accessor :child_nodes
6
- end
7
-
8
4
  class ComponentRenderer < Bridgetown::Builder
9
5
  def build
10
6
  render_html_modules
@@ -13,13 +9,13 @@ module HoTModuLe
13
9
  # rubocop:todo Metrics
14
10
  def render_html_modules
15
11
  inspect_html do |doc, resource|
16
- view_context = HoTModuLe::View.new(resource)
12
+ view_context = Bridgetown::ERBView.new(resource)
17
13
 
18
14
  HoTModuLe.registered_elements.each do |component|
19
15
  tag_name = component.tag_name
20
16
  doc.xpath("//#{tag_name}").reverse.each do |node|
21
17
  if node["hmod:ignore"]
22
- node.attribute("hmod:ignore").remove
18
+ node.remove_attribute("hmod:ignore")
23
19
  next
24
20
  end
25
21
 
@@ -37,11 +33,10 @@ module HoTModuLe
37
33
  attrs.merge!(new_attrs)
38
34
  attrs.transform_keys!(&:to_sym)
39
35
 
40
- view_context.child_nodes = node.children
41
36
  new_node = node.replace(
42
- component.new(**attrs).render_in(view_context) { node.children.to_html.html_safe }
37
+ component.new(**attrs).render_in(view_context, rendering_mode: :node) { node.children }
43
38
  )
44
- new_node.first.attribute("hmod:ignore")&.remove
39
+ new_node.remove_attribute("hmod:ignore")
45
40
  end
46
41
  rescue StandardError => e
47
42
  Bridgetown.logger.error "Unable to render <#{tag_name}> (#{component}) in #{resource.path}"
@@ -2,5 +2,5 @@
2
2
 
3
3
  module HoTModuLe
4
4
  # @return [String]
5
- VERSION = "1.0.0.alpha12"
5
+ VERSION = "1.0.0.alpha13"
6
6
  end
data/lib/hot_module.rb CHANGED
@@ -150,14 +150,25 @@ module HoTModuLe
150
150
  # @return [Hash]
151
151
  def attributes = {}
152
152
 
153
+ def rendering_mode = @_rendering_mode || :node
154
+
155
+ def rendering_mode=(mode)
156
+ @_rendering_mode = case mode
157
+ when :node, :string
158
+ mode
159
+ end
160
+ end
161
+
153
162
  # @param attributes [Hash]
154
163
  # @param content [String, Nokolexbor::Element]
155
- # @param return_node [Boolean]
156
- def render_element(attributes: self.attributes, content: self.content, return_node: false) # rubocop:disable Metrics
164
+ def render_element(attributes: self.attributes, content: self.content) # rubocop:disable Metrics
157
165
  doc = self.class.doc.clone
158
166
  @_content = content
159
167
 
160
- tmpl_el = doc.css("> template").find { _1.attributes.empty? }
168
+ tmpl_el = doc.css("> template").find do |node|
169
+ node.attributes.empty? ||
170
+ (node.attributes.count == 1 && node.attributes.any? { |k| k[0].start_with?("data-") })
171
+ end
161
172
 
162
173
  unless tmpl_el
163
174
  tmpl_el = doc.document.create_element("template")
@@ -172,7 +183,7 @@ module HoTModuLe
172
183
  HoTModuLe.registered_elements.each do |component|
173
184
  tmpl_el.children[0].css(component.tag_name).reverse.each do |node|
174
185
  if node["hmod:ignore"]
175
- node.attribute("hmod:ignore").remove
186
+ node.remove_attribute("hmod:ignore")
176
187
  next
177
188
  end
178
189
 
@@ -192,7 +203,7 @@ module HoTModuLe
192
203
  new_node = node.replace(
193
204
  component.new(**attrs).render_element(content: node.children)
194
205
  )
195
- new_node.first.attribute("hmod:ignore")&.remove
206
+ new_node.remove_attribute("hmod:ignore")
196
207
  end
197
208
  end
198
209
 
@@ -247,8 +258,7 @@ module HoTModuLe
247
258
  tmpl_el.remove
248
259
  end
249
260
 
250
- # And that is that.
251
- return_node ? doc : doc.to_html
261
+ rendering_mode == :node ? doc : doc.to_html
252
262
  end
253
263
 
254
264
  def call(...) = render_element(...)
@@ -380,9 +390,10 @@ if defined?(Bridgetown)
380
390
  Bridgetown::Component.extend ActiveSupport::DescendantsTracker
381
391
 
382
392
  HoTModuLe.module_eval do
383
- def render_in(*)
393
+ def render_in(view_context, rendering_mode = :string, &block)
384
394
  @attributes&.[]=("hmod:ignore", "")
385
- super
395
+ self.rendering_mode = rendering_mode
396
+ super(view_context, &block)
386
397
  end
387
398
  end
388
399
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hot_module
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.alpha12
4
+ version: 1.0.0.alpha13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared White
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-08 00:00:00.000000000 Z
11
+ date: 2023-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby