hot_module 1.0.0.alpha2 → 1.0.0.alpha4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -2
- data/Gemfile.lock +24 -24
- data/benchmark.rb +2 -0
- data/hot_module.gemspec +1 -1
- data/lib/hot_module/component_renderer.rb +53 -0
- data/lib/hot_module/petite.rb +1 -1
- data/lib/hot_module/query_selection.rb +1 -2
- data/lib/hot_module/version.rb +1 -1
- data/lib/hot_module.rb +26 -26
- metadata +5 -4
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,21 +1,21 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
hot_module (1.0.0.
|
5
|
-
nokolexbor (~> 0.
|
4
|
+
hot_module (1.0.0.alpha4)
|
5
|
+
nokolexbor (~> 0.4)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activesupport (7.0.4)
|
10
|
+
activesupport (7.0.4.3)
|
11
11
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
12
|
i18n (>= 1.6, < 2)
|
13
13
|
minitest (>= 5.1)
|
14
14
|
tzinfo (~> 2.0)
|
15
15
|
ast (2.4.2)
|
16
16
|
backport (1.2.0)
|
17
|
-
benchmark (0.2.
|
18
|
-
concurrent-ruby (1.
|
17
|
+
benchmark (0.2.1)
|
18
|
+
concurrent-ruby (1.2.2)
|
19
19
|
diff-lcs (1.5.0)
|
20
20
|
e2mmap (0.1.0)
|
21
21
|
hash_with_dot_access (1.2.0)
|
@@ -23,44 +23,44 @@ GEM
|
|
23
23
|
i18n (1.12.0)
|
24
24
|
concurrent-ruby (~> 1.0)
|
25
25
|
jaro_winkler (1.5.4)
|
26
|
-
json (2.6.
|
26
|
+
json (2.6.3)
|
27
27
|
kramdown (2.4.0)
|
28
28
|
rexml
|
29
29
|
kramdown-parser-gfm (1.1.0)
|
30
30
|
kramdown (~> 2.0)
|
31
|
-
minitest (5.
|
32
|
-
nokogiri (1.
|
31
|
+
minitest (5.18.0)
|
32
|
+
nokogiri (1.14.2-arm64-darwin)
|
33
33
|
racc (~> 1.4)
|
34
|
-
nokogiri (1.
|
34
|
+
nokogiri (1.14.2-x86_64-linux)
|
35
35
|
racc (~> 1.4)
|
36
|
-
nokolexbor (0.
|
36
|
+
nokolexbor (0.4.0-arm64-darwin)
|
37
37
|
parallel (1.22.1)
|
38
|
-
parser (3.
|
38
|
+
parser (3.2.1.1)
|
39
39
|
ast (~> 2.4.1)
|
40
|
-
racc (1.6.
|
40
|
+
racc (1.6.2)
|
41
41
|
rainbow (3.1.1)
|
42
42
|
rake (13.0.6)
|
43
|
-
regexp_parser (2.
|
43
|
+
regexp_parser (2.7.0)
|
44
44
|
reverse_markdown (2.1.1)
|
45
45
|
nokogiri
|
46
46
|
rexml (3.2.5)
|
47
|
-
rubocop (1.
|
47
|
+
rubocop (1.48.1)
|
48
48
|
json (~> 2.3)
|
49
49
|
parallel (~> 1.10)
|
50
|
-
parser (>= 3.
|
50
|
+
parser (>= 3.2.0.0)
|
51
51
|
rainbow (>= 2.2.2, < 4.0)
|
52
52
|
regexp_parser (>= 1.8, < 3.0)
|
53
53
|
rexml (>= 3.2.5, < 4.0)
|
54
|
-
rubocop-ast (>= 1.
|
54
|
+
rubocop-ast (>= 1.26.0, < 2.0)
|
55
55
|
ruby-progressbar (~> 1.7)
|
56
|
-
unicode-display_width (>=
|
57
|
-
rubocop-ast (1.
|
58
|
-
parser (>= 3.
|
59
|
-
rubocop-minitest (0.22.
|
56
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
57
|
+
rubocop-ast (1.27.0)
|
58
|
+
parser (>= 3.2.1.0)
|
59
|
+
rubocop-minitest (0.22.2)
|
60
60
|
rubocop (>= 0.90, < 2.0)
|
61
61
|
rubocop-rake (0.6.0)
|
62
62
|
rubocop (~> 1.0)
|
63
|
-
ruby-progressbar (1.
|
63
|
+
ruby-progressbar (1.13.0)
|
64
64
|
solargraph (0.47.2)
|
65
65
|
backport (~> 1.2)
|
66
66
|
benchmark
|
@@ -77,10 +77,10 @@ GEM
|
|
77
77
|
tilt (~> 2.0)
|
78
78
|
yard (~> 0.9, >= 0.9.24)
|
79
79
|
thor (1.2.1)
|
80
|
-
tilt (2.0
|
81
|
-
tzinfo (2.0.
|
80
|
+
tilt (2.1.0)
|
81
|
+
tzinfo (2.0.6)
|
82
82
|
concurrent-ruby (~> 1.0)
|
83
|
-
unicode-display_width (2.
|
83
|
+
unicode-display_width (2.4.2)
|
84
84
|
webrick (1.7.0)
|
85
85
|
yard (0.9.28)
|
86
86
|
webrick (~> 1.7.0)
|
data/benchmark.rb
CHANGED
data/hot_module.gemspec
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/petite.rb
CHANGED
@@ -12,6 +12,5 @@ module HoTModuLe
|
|
12
12
|
def query_selector_all(selector) = css(selector)
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
# Nokogiri::XML::Node.include QuerySelection unless Nokogiri::XML::Node.instance_methods.include?(:query_selector)
|
15
|
+
Nokolexbor::Element.include QuerySelection unless Nokolexbor::Element.instance_methods.include?(:query_selector)
|
17
16
|
end
|
data/lib/hot_module/version.rb
CHANGED
data/lib/hot_module.rb
CHANGED
@@ -21,7 +21,7 @@ module HoTModuLe
|
|
21
21
|
AttributeBinding = Struct.new(:matcher, :method_name, :method, :only_for_tag, keyword_init: true) # rubocop:disable Lint/StructNewOverride
|
22
22
|
|
23
23
|
require_relative "hot_module/fragment"
|
24
|
-
|
24
|
+
require_relative "hot_module/query_selection"
|
25
25
|
|
26
26
|
# @param klass [Class]
|
27
27
|
# @return [void]
|
@@ -92,7 +92,7 @@ module HoTModuLe
|
|
92
92
|
def doc
|
93
93
|
@doc ||= Nokolexbor::DocumentFragment.parse(
|
94
94
|
"<#{tag_name}>#{File.read(html_module).strip}</#{tag_name}>"
|
95
|
-
).
|
95
|
+
).element_children.first
|
96
96
|
end
|
97
97
|
|
98
98
|
def attribute_bindings
|
@@ -126,18 +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
|
-
|
130
|
-
doc.css("template").each do |bad_tmpl|
|
131
|
-
frag = bad_tmpl.children.last
|
132
|
-
new_tmpl = doc.document.create_element("template")
|
133
|
-
bad_tmpl.attributes.each do |k, v|
|
134
|
-
new_tmpl[k] = v
|
135
|
-
end
|
136
|
-
new_tmpl.children[0].children = frag
|
137
|
-
bad_tmpl.swap(new_tmpl)
|
138
|
-
end
|
139
|
-
|
140
|
-
tmpl_el = doc.css("> template").find { _1.attributes.length.zero? }
|
129
|
+
tmpl_el = doc.css("> template").find { _1.attributes.empty? }
|
141
130
|
|
142
131
|
unless tmpl_el
|
143
132
|
tmpl_el = doc.document.create_element("template")
|
@@ -249,18 +238,6 @@ module HoTModuLe
|
|
249
238
|
_in_context_nodes do |previous_context|
|
250
239
|
list_items.each_with_index do |list_item, index|
|
251
240
|
new_node = item_node.clone
|
252
|
-
|
253
|
-
# NOTE: have to fix cloned templates
|
254
|
-
new_node.css("template").each do |bad_tmpl|
|
255
|
-
frag = bad_tmpl.children.last
|
256
|
-
new_tmpl = item_node.document.create_element("template")
|
257
|
-
bad_tmpl.attributes.each do |k, v|
|
258
|
-
new_tmpl[k] = v
|
259
|
-
end
|
260
|
-
new_tmpl.children[0].children = frag
|
261
|
-
bad_tmpl.swap(new_tmpl)
|
262
|
-
end
|
263
|
-
|
264
241
|
node.parent << new_node
|
265
242
|
new_node["hmod-added"] = ""
|
266
243
|
|
@@ -325,3 +302,26 @@ module HoTModuLe
|
|
325
302
|
@_context_locals = previous_context
|
326
303
|
end
|
327
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
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.4'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
26
|
+
version: '0.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: hash_with_dot_access
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -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
|