hot_module 1.0.0.alpha12 → 1.0.0.alpha14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 51da117a031a9b9ad3c16a35b4b5276928874e742bf72e90bc9e1089f4b856a1
4
- data.tar.gz: b1bb49f906b3dbc82671ec7a4850baac1899c93ce3237cc88c8bb3c69dff75f3
3
+ metadata.gz: 8c807341a2b68711682e37e62045bae062a490402b33da6d52dfe38ec2472b85
4
+ data.tar.gz: 06e4b4cafe75ea650c4d57a5b39df40cad4596901294a8853f7a5ff40944b776
5
5
  SHA512:
6
- metadata.gz: 0b6b8661ec4ee9f416eff3373a049c126a744e5bd280ddf88fac6d896f58df1f844f170ddc85d5addbd099e70e5fc8f5d3421a966ea5b13bba2f568eb2bc8f86
7
- data.tar.gz: d50b1b02e71f78e14ebde1c8c08abcd80eb79911fd1fafcf15de6a89ea5c412db50ddeecc23e804f05acee61b8d75d1be8ca5bef38937105b779f32b39b4e6e4
6
+ metadata.gz: df99852ada0457075b72bd89e8291abe21a94ae2043ea469cca16eeeecf771c46b2d02c16b1fb1d9c6940e1edcdd5590e46fc7849297087222d7e3d44aceb5f3
7
+ data.tar.gz: ff133ae7e218263f64803c367177583b303091ebc31661e628dca3ffde0bdfa5d83f50e023f36b2a4385e4a69937d980f4ade41d015f57eaee794f9d475efbe1
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.alpha14)
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.alpha14"
6
6
  end
data/lib/hot_module.rb CHANGED
@@ -145,19 +145,34 @@ module HoTModuLe
145
145
  def content = @_content
146
146
  end
147
147
 
148
+ def replaced_content=(new_content)
149
+ @_replaced_content = new_content
150
+ end
151
+
148
152
  # Override in component
149
153
  #
150
154
  # @return [Hash]
151
155
  def attributes = {}
152
156
 
157
+ def rendering_mode = @_rendering_mode || :node
158
+
159
+ def rendering_mode=(mode)
160
+ @_rendering_mode = case mode
161
+ when :node, :string
162
+ mode
163
+ end
164
+ end
165
+
153
166
  # @param attributes [Hash]
154
167
  # @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
168
+ def render_element(attributes: self.attributes, content: self.content) # rubocop:disable Metrics
157
169
  doc = self.class.doc.clone
158
170
  @_content = content
159
171
 
160
- tmpl_el = doc.css("> template").find { _1.attributes.empty? }
172
+ tmpl_el = doc.css("> template").find do |node|
173
+ node.attributes.empty? ||
174
+ (node.attributes.count == 1 && node.attributes.any? { |k| k[0].start_with?("data-") })
175
+ end
161
176
 
162
177
  unless tmpl_el
163
178
  tmpl_el = doc.document.create_element("template")
@@ -172,7 +187,7 @@ module HoTModuLe
172
187
  HoTModuLe.registered_elements.each do |component|
173
188
  tmpl_el.children[0].css(component.tag_name).reverse.each do |node|
174
189
  if node["hmod:ignore"]
175
- node.attribute("hmod:ignore").remove
190
+ node.remove_attribute("hmod:ignore")
176
191
  next
177
192
  end
178
193
 
@@ -192,7 +207,7 @@ module HoTModuLe
192
207
  new_node = node.replace(
193
208
  component.new(**attrs).render_element(content: node.children)
194
209
  )
195
- new_node.first.attribute("hmod:ignore")&.remove
210
+ new_node.remove_attribute("hmod:ignore")
196
211
  end
197
212
  end
198
213
 
@@ -232,7 +247,7 @@ module HoTModuLe
232
247
  style_tag.content = output_styles
233
248
  end
234
249
 
235
- child_content = @_replaced_children || content
250
+ child_content = @_replaced_content || content
236
251
  if self.class.shadow_root
237
252
  # Guess what? We can reuse the same template tag! =)
238
253
  tmpl_el["shadowrootmode"] = "open"
@@ -247,8 +262,7 @@ module HoTModuLe
247
262
  tmpl_el.remove
248
263
  end
249
264
 
250
- # And that is that.
251
- return_node ? doc : doc.to_html
265
+ rendering_mode == :node ? doc : doc.to_html
252
266
  end
253
267
 
254
268
  def call(...) = render_element(...)
@@ -350,7 +364,7 @@ module HoTModuLe
350
364
  end
351
365
 
352
366
  def _hmod_children_binding(attribute:, node:) # rubocop:disable Lint/UnusedMethodArgument
353
- @_replaced_children = node.children[0]
367
+ self.replaced_content = node.children[0]
354
368
  node.remove
355
369
  end
356
370
 
@@ -380,9 +394,10 @@ if defined?(Bridgetown)
380
394
  Bridgetown::Component.extend ActiveSupport::DescendantsTracker
381
395
 
382
396
  HoTModuLe.module_eval do
383
- def render_in(*)
397
+ def render_in(view_context, rendering_mode = :string, &block)
384
398
  @attributes&.[]=("hmod:ignore", "")
385
- super
399
+ self.rendering_mode = rendering_mode
400
+ super(view_context, &block)
386
401
  end
387
402
  end
388
403
 
@@ -393,6 +408,7 @@ if defined?(Bridgetown)
393
408
  end
394
409
  end
395
410
 
411
+ config.html_inspector_parser "nokolexbor"
396
412
  require_relative "hot_module/component_renderer"
397
413
  config.builder HoTModuLe::ComponentRenderer
398
414
  end
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.alpha14
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