hot_module 1.0.0.alpha3 → 1.0.0.alpha4
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 +4 -4
- data/CHANGELOG.md +2 -2
- data/Gemfile.lock +1 -2
- data/benchmark.rb +2 -0
- data/lib/hot_module/component_renderer.rb +53 -0
- data/lib/hot_module/version.rb +1 -1
- data/lib/hot_module.rb +24 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f1f98447dc175047e9ff9158705fb70736244cea4f1dcd8f014a9d7c19bd525
|
4
|
+
data.tar.gz: 65fa70bbba49a2e0077716315e976f5cc61db9228df638c5ef318d08e5d787b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 126deaf01781d54059a03645e1ae894b169702b37a622427010ce6e87523428ed937d18877025bbcab1900b0887b7b17bf25ece52076689db75ae6d19f60e553
|
7
|
+
data.tar.gz: 94ebbe7fa9f2a084e1babf420b71f96ede5e01e73190272d0168d26fde8d6dbb032cf93ed9bea3ccb9ec91843f5a27f260fb27dc1a73f912aa822f14bc8a2319
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
hot_module (1.0.0.
|
4
|
+
hot_module (1.0.0.alpha4)
|
5
5
|
nokolexbor (~> 0.4)
|
6
6
|
|
7
7
|
GEM
|
@@ -34,7 +34,6 @@ GEM
|
|
34
34
|
nokogiri (1.14.2-x86_64-linux)
|
35
35
|
racc (~> 1.4)
|
36
36
|
nokolexbor (0.4.0-arm64-darwin)
|
37
|
-
nokolexbor (0.4.0-x86_64-linux)
|
38
37
|
parallel (1.22.1)
|
39
38
|
parser (3.2.1.1)
|
40
39
|
ast (~> 2.4.1)
|
data/benchmark.rb
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HoTModuLe
|
4
|
+
class ComponentRenderer < Bridgetown::Builder
|
5
|
+
def build
|
6
|
+
registered_tags = {}
|
7
|
+
Bridgetown::Component.subclasses.each do |component|
|
8
|
+
next unless component.respond_to?(:tag_name)
|
9
|
+
|
10
|
+
registered_tags[component.tag_name] = component
|
11
|
+
end
|
12
|
+
|
13
|
+
render_html_modules(registered_tags)
|
14
|
+
end
|
15
|
+
|
16
|
+
def render_html_modules(registered_tags) # rubocop:todo Metrics
|
17
|
+
inspect_html do |doc, resource| # rubocop:todo Metrics
|
18
|
+
view_context = Bridgetown::ERBView.new(resource)
|
19
|
+
|
20
|
+
registered_tags.each do |tag_name, component|
|
21
|
+
doc.xpath("//#{tag_name}").reverse.each do |node|
|
22
|
+
if node["hmod:ignore"]
|
23
|
+
node.attribute("hmod:ignore").remove
|
24
|
+
next
|
25
|
+
end
|
26
|
+
|
27
|
+
attrs = node.attributes.transform_values(&:value)
|
28
|
+
attrs.reject! { |k| k.start_with?("hmod:") }
|
29
|
+
|
30
|
+
new_attrs = {}
|
31
|
+
attrs.each do |k, v|
|
32
|
+
next unless k.start_with?("ruby:")
|
33
|
+
|
34
|
+
new_key = k.delete_prefix("ruby:")
|
35
|
+
attrs.delete(k)
|
36
|
+
new_attrs[new_key] = resource.instance_eval(v)
|
37
|
+
end
|
38
|
+
attrs.merge!(new_attrs)
|
39
|
+
attrs.transform_keys!(&:to_sym)
|
40
|
+
|
41
|
+
new_node = node.replace(
|
42
|
+
component.new(**attrs).render_in(view_context) { node.children.to_html }
|
43
|
+
)
|
44
|
+
new_node.first.attribute("hmod:ignore")&.remove
|
45
|
+
end
|
46
|
+
rescue StandardError => e
|
47
|
+
Bridgetown.logger.error "Unable to render <#{tag_name}> (#{component}) in #{resource.path}"
|
48
|
+
raise e
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/hot_module/version.rb
CHANGED
data/lib/hot_module.rb
CHANGED
@@ -126,7 +126,7 @@ module HoTModuLe
|
|
126
126
|
def render_element(attributes: self.attributes, content: self.content, return_node: false) # rubocop:disable Metrics
|
127
127
|
doc = self.class.doc.clone
|
128
128
|
|
129
|
-
tmpl_el = doc.css("> template").find { _1.attributes.
|
129
|
+
tmpl_el = doc.css("> template").find { _1.attributes.empty? }
|
130
130
|
|
131
131
|
unless tmpl_el
|
132
132
|
tmpl_el = doc.document.create_element("template")
|
@@ -302,3 +302,26 @@ module HoTModuLe
|
|
302
302
|
@_context_locals = previous_context
|
303
303
|
end
|
304
304
|
end
|
305
|
+
|
306
|
+
if defined?(Bridgetown)
|
307
|
+
Bridgetown.initializer :hot_module do |config|
|
308
|
+
Bridgetown::Component.extend ActiveSupport::DescendantsTracker
|
309
|
+
|
310
|
+
HoTModuLe.module_eval do
|
311
|
+
def render_in(*)
|
312
|
+
@attributes&.[]=("hmod:ignore", "")
|
313
|
+
super
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
# Eager load all components
|
318
|
+
hook :site, :after_reset do |site|
|
319
|
+
unless site.config.eager_load_paths.find { _1.end_with?(site.config.components_dir) }
|
320
|
+
site.config.eager_load_paths << site.config.autoload_paths.find { _1.end_with?(site.config.components_dir) }
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
require_relative "hot_module/component_renderer"
|
325
|
+
config.builder HoTModuLe::ComponentRenderer
|
326
|
+
end
|
327
|
+
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.alpha4
|
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-03-
|
11
|
+
date: 2023-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokolexbor
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- benchmark.rb
|
57
57
|
- hot_module.gemspec
|
58
58
|
- lib/hot_module.rb
|
59
|
+
- lib/hot_module/component_renderer.rb
|
59
60
|
- lib/hot_module/fragment.rb
|
60
61
|
- lib/hot_module/petite.rb
|
61
62
|
- lib/hot_module/query_selection.rb
|