hot_module 1.0.0.alpha12 → 1.0.0.alpha13
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 +20 -9
- 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: 90f40d53a3d644454adb306af193e5258970067eaa31075263c13ce31ce23b3f
|
4
|
+
data.tar.gz: f3308d84a9605fce9edeff88e00e29ce88ebee8d5dcde9f96439b46f6a512567
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa8b2ce963950a27f69a65c23db73f544fd52e84ab5b0d200667fc2e2a976dc2a8121c6fa7de0b4e4a50f8abb49d7243b484aea7210fc14cb3e8708414050248
|
7
|
+
data.tar.gz: 8a4a0de3a7dbd16b019327282ec3f1e604a622baf4f47dc21fffe6cd2ed9c25170de5d453ea43185deffe344fcd5324cd8696aff2046821b7988179ec4edc677
|
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
@@ -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
|
-
#
|
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
|
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.
|
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.
|
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
|
-
|
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
|
-
|
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.
|
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-
|
11
|
+
date: 2023-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|