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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/hot_module/component_renderer.rb +4 -9
- data/lib/hot_module/version.rb +1 -1
- data/lib/hot_module.rb +27 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c807341a2b68711682e37e62045bae062a490402b33da6d52dfe38ec2472b85
|
4
|
+
data.tar.gz: 06e4b4cafe75ea650c4d57a5b39df40cad4596901294a8853f7a5ff40944b776
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df99852ada0457075b72bd89e8291abe21a94ae2043ea469cca16eeeecf771c46b2d02c16b1fb1d9c6940e1edcdd5590e46fc7849297087222d7e3d44aceb5f3
|
7
|
+
data.tar.gz: ff133ae7e218263f64803c367177583b303091ebc31661e628dca3ffde0bdfa5d83f50e023f36b2a4385e4a69937d980f4ade41d015f57eaee794f9d475efbe1
|
data/Gemfile.lock
CHANGED
@@ -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 =
|
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.
|
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
|
37
|
+
component.new(**attrs).render_in(view_context, rendering_mode: :node) { node.children }
|
43
38
|
)
|
44
|
-
new_node.
|
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}"
|
data/lib/hot_module/version.rb
CHANGED
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
|
-
#
|
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
|
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.
|
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.
|
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 = @
|
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
|
-
|
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
|
-
|
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
|
-
|
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.
|
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-
|
11
|
+
date: 2023-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|