heartml 1.0.0.beta2 → 1.0.0.beta4
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 +12 -0
- data/Gemfile.lock +1 -3
- data/lib/heartml/bridgetown_renderer.rb +40 -0
- data/lib/heartml/fragment.rb +9 -5
- data/lib/heartml/version.rb +1 -1
- data/lib/heartml.rb +16 -76
- metadata +3 -3
- data/lib/heartml/component_renderer.rb +0 -52
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 76684cce6c5e1c52ce68f4b0b0770a60377aefc908ce38c469ee540b576eac8d
|
|
4
|
+
data.tar.gz: 388c37ecfc4829cbe1c0635ff301d4957b8eca52b6f75603d83b9184c36accc8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 531c6b5411396f98d55ef33e3b2f8abb8c12fabd251c9fdfc2bfed032d36f188fc9d5f5721c7262bdb8adaa1e63c94f4744e1a4b5354f895579a97f359013406
|
|
7
|
+
data.tar.gz: dd55039932a06904f0fd911b9d3d2ddca7ee696fd3a085a5a3e931bac7ec1b31d9004092cacf9ea02b8b4048b463eed35480d68f563e01cf8778bcbd1f057afa
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [1.0.0.beta4] - 2023-08-27
|
|
4
|
+
|
|
5
|
+
- Refactor and improve Bridgetown plugin and simplify context handling for template rendering
|
|
6
|
+
|
|
7
|
+
## [1.0.0.beta3] - 2023-08-12
|
|
8
|
+
|
|
9
|
+
- Ensure attributes are processed on component node before it's rendered as component
|
|
10
|
+
|
|
11
|
+
## [1.0.0.beta2] - 2023-08-12
|
|
12
|
+
|
|
13
|
+
- Fix Bridgetown issues and process component "light DOM" children
|
|
14
|
+
|
|
3
15
|
## [1.0.0.beta1] - 2023-08-12
|
|
4
16
|
|
|
5
17
|
- Major refactor as part of the new Heartml project
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
heartml (1.0.0.
|
|
4
|
+
heartml (1.0.0.beta4)
|
|
5
5
|
concurrent-ruby (~> 1.2)
|
|
6
6
|
nokolexbor (>= 0.4.2)
|
|
7
7
|
|
|
@@ -38,9 +38,7 @@ GEM
|
|
|
38
38
|
racc (~> 1.4)
|
|
39
39
|
nokogiri (1.14.2-x86_64-linux)
|
|
40
40
|
racc (~> 1.4)
|
|
41
|
-
nokolexbor (0.5.0)
|
|
42
41
|
nokolexbor (0.5.0-arm64-darwin)
|
|
43
|
-
nokolexbor (0.5.0-x86_64-linux)
|
|
44
42
|
parallel (1.22.1)
|
|
45
43
|
parser (3.2.2.0)
|
|
46
44
|
ast (~> 2.4.1)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Heartml
|
|
4
|
+
class BridgetownRenderer < Bridgetown::Builder
|
|
5
|
+
def build
|
|
6
|
+
render_heart_modules
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def render_heart_modules
|
|
10
|
+
inspect_html do |doc, resource|
|
|
11
|
+
view_context = Bridgetown::ERBView.new(resource)
|
|
12
|
+
|
|
13
|
+
rdr = Heartml::TemplateRenderer.new(body: doc.at_css("body"), context: view_context)
|
|
14
|
+
# rdr.define_singleton_method(:view_context) { view_context }
|
|
15
|
+
rdr.call
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
Bridgetown.initializer :heartml do |config|
|
|
22
|
+
Bridgetown::Component.extend ActiveSupport::DescendantsTracker
|
|
23
|
+
|
|
24
|
+
Heartml.module_eval do
|
|
25
|
+
def render_in(view_context, rendering_mode: :string, &block)
|
|
26
|
+
self.rendering_mode = rendering_mode
|
|
27
|
+
super(view_context, &block)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Eager load all components
|
|
32
|
+
config.hook :site, :after_reset do |site|
|
|
33
|
+
unless site.config.eager_load_paths.find { _1.end_with?(site.config.components_dir) }
|
|
34
|
+
site.config.eager_load_paths << site.config.autoload_paths.find { _1.end_with?(site.config.components_dir) }
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
config.html_inspector_parser "nokolexbor"
|
|
39
|
+
config.builder Heartml::BridgetownRenderer
|
|
40
|
+
end
|
data/lib/heartml/fragment.rb
CHANGED
|
@@ -20,6 +20,8 @@ module Heartml
|
|
|
20
20
|
|
|
21
21
|
def process(fragment = @fragment) # rubocop:disable Metrics
|
|
22
22
|
traverse(fragment) do |node| # rubocop:disable Metrics/BlockLength
|
|
23
|
+
process_attribute_bindings(node)
|
|
24
|
+
|
|
23
25
|
component = Heartml.registered_elements.find { _1.tag_name == node.name }
|
|
24
26
|
if component
|
|
25
27
|
attrs = node.attributes.dup
|
|
@@ -36,27 +38,29 @@ module Heartml
|
|
|
36
38
|
|
|
37
39
|
params.each do |param|
|
|
38
40
|
new_key, v2 = param.split(":").map(&:strip)
|
|
41
|
+
v2 = new_key unless v2
|
|
42
|
+
|
|
39
43
|
new_attrs[new_key] = @component.evaluate_attribute_expression(attr, v2)
|
|
40
44
|
end
|
|
41
45
|
attrs.delete(k)
|
|
42
46
|
end
|
|
43
47
|
attrs.merge!(new_attrs)
|
|
44
48
|
attrs.reject! { |k| k.start_with?("server-") || k.start_with?("iso-") || k.start_with?("host-") }
|
|
45
|
-
attrs.transform_keys!(
|
|
49
|
+
attrs.transform_keys! { _1.tr("-", "_").to_sym }
|
|
46
50
|
|
|
47
51
|
obj = component.new(**attrs)
|
|
48
52
|
render_output = if obj.respond_to?(:render_in)
|
|
49
|
-
obj.render_in(@component.
|
|
53
|
+
obj.render_in(@component.context, rendering_mode: :node) do
|
|
50
54
|
process(fragamatize(node.children))
|
|
51
55
|
end
|
|
52
56
|
else
|
|
53
|
-
obj.render_element(
|
|
57
|
+
obj.render_element(
|
|
58
|
+
content: process(fragamatize(node.children)), context: @component.context
|
|
59
|
+
)
|
|
54
60
|
end
|
|
55
61
|
|
|
56
62
|
node.replace(render_output)
|
|
57
63
|
end
|
|
58
|
-
|
|
59
|
-
process_attribute_bindings(node)
|
|
60
64
|
end
|
|
61
65
|
|
|
62
66
|
fragment
|
data/lib/heartml/version.rb
CHANGED
data/lib/heartml.rb
CHANGED
|
@@ -149,6 +149,14 @@ module Heartml
|
|
|
149
149
|
@_replaced_content = new_content
|
|
150
150
|
end
|
|
151
151
|
|
|
152
|
+
def context
|
|
153
|
+
return @context if @context
|
|
154
|
+
|
|
155
|
+
return unless respond_to?(:view_context)
|
|
156
|
+
|
|
157
|
+
view_context # compatibility with other Ruby component systems
|
|
158
|
+
end
|
|
159
|
+
|
|
152
160
|
# Override in component
|
|
153
161
|
#
|
|
154
162
|
# @return [Hash]
|
|
@@ -165,9 +173,10 @@ module Heartml
|
|
|
165
173
|
|
|
166
174
|
# @param attributes [Hash]
|
|
167
175
|
# @param content [String, Nokolexbor::Element]
|
|
168
|
-
def render_element(attributes: self.attributes, content: self.content) # rubocop:disable Metrics
|
|
176
|
+
def render_element(attributes: self.attributes, content: self.content, context: self.context) # rubocop:disable Metrics
|
|
169
177
|
doc = self.class.doc.clone
|
|
170
178
|
@_content = content
|
|
179
|
+
@context = context
|
|
171
180
|
|
|
172
181
|
tmpl_el = doc.css("> template").find do |node|
|
|
173
182
|
node.attributes.empty? ||
|
|
@@ -184,33 +193,6 @@ module Heartml
|
|
|
184
193
|
# Process all the template bits
|
|
185
194
|
process_fragment(tmpl_el)
|
|
186
195
|
|
|
187
|
-
# Heartml.registered_elements.each do |component|
|
|
188
|
-
# tmpl_el.children[0].css(component.tag_name).reverse.each do |node|
|
|
189
|
-
# if node["server-ignore"]
|
|
190
|
-
# node.remove_attribute("server-ignore")
|
|
191
|
-
# next
|
|
192
|
-
# end
|
|
193
|
-
|
|
194
|
-
# attrs = node.attributes.transform_values(&:value)
|
|
195
|
-
# attrs.reject! { |k| k.start_with?("server-") }
|
|
196
|
-
# new_attrs = {}
|
|
197
|
-
# attrs.each do |k, v|
|
|
198
|
-
# next unless k.start_with?("arg:")
|
|
199
|
-
|
|
200
|
-
# new_key = k.delete_prefix("arg:")
|
|
201
|
-
# attrs.delete(k)
|
|
202
|
-
# new_attrs[new_key] = instance_eval(v, self.class.heart_module, self.class.line_number_of_node(node))
|
|
203
|
-
# end
|
|
204
|
-
# attrs.merge!(new_attrs)
|
|
205
|
-
# attrs.transform_keys!(&:to_sym)
|
|
206
|
-
|
|
207
|
-
# new_node = node.replace(
|
|
208
|
-
# component.new(**attrs).render_element(content: node.children)
|
|
209
|
-
# )
|
|
210
|
-
# new_node.remove_attribute("server-ignore")
|
|
211
|
-
# end
|
|
212
|
-
# end
|
|
213
|
-
|
|
214
196
|
# Set attributes on the custom element
|
|
215
197
|
attributes.each { |k, v| doc[k.to_s.tr("_", "-")] = value_to_attribute(v) if v }
|
|
216
198
|
|
|
@@ -381,26 +363,6 @@ module Heartml
|
|
|
381
363
|
end
|
|
382
364
|
end
|
|
383
365
|
|
|
384
|
-
# def _server_replace_binding(attribute:, node:)
|
|
385
|
-
# if node.name == "template"
|
|
386
|
-
# node.children[0].inner_html = node_or_string(evaluate_attribute_expression(attribute))
|
|
387
|
-
# node.replace(node.children[0].children)
|
|
388
|
-
# else
|
|
389
|
-
# node.inner_html = node_or_string(evaluate_attribute_expression(attribute))
|
|
390
|
-
# node.replace(node.children)
|
|
391
|
-
# end
|
|
392
|
-
# end
|
|
393
|
-
|
|
394
|
-
# def _server_expr_binding(attribute:, node:)
|
|
395
|
-
# if attribute.name.end_with?(":text")
|
|
396
|
-
# node.content = node_or_string(evaluate_attribute_expression(attribute))
|
|
397
|
-
# attribute.parent.delete(attribute.name)
|
|
398
|
-
# elsif attribute.name.end_with?(":html")
|
|
399
|
-
# node.inner_html = node_or_string(evaluate_attribute_expression(attribute))
|
|
400
|
-
# attribute.parent.delete(attribute.name)
|
|
401
|
-
# end
|
|
402
|
-
# end
|
|
403
|
-
|
|
404
366
|
class ServerComponent
|
|
405
367
|
def self.inherited(klass)
|
|
406
368
|
super
|
|
@@ -409,7 +371,7 @@ module Heartml
|
|
|
409
371
|
end
|
|
410
372
|
end
|
|
411
373
|
|
|
412
|
-
class
|
|
374
|
+
class TemplateRenderer < ServerComponent
|
|
413
375
|
def self.heart_module
|
|
414
376
|
"eval"
|
|
415
377
|
end
|
|
@@ -419,9 +381,9 @@ module Heartml
|
|
|
419
381
|
0
|
|
420
382
|
end
|
|
421
383
|
|
|
422
|
-
def initialize(body:,
|
|
384
|
+
def initialize(body:, context:) # rubocop:disable Lint/MissingSuper
|
|
423
385
|
@body = body.is_a?(String) ? Nokolexbor::DocumentFragment.parse(body) : body
|
|
424
|
-
@
|
|
386
|
+
@context = context
|
|
425
387
|
end
|
|
426
388
|
|
|
427
389
|
def call
|
|
@@ -430,36 +392,14 @@ module Heartml
|
|
|
430
392
|
end
|
|
431
393
|
|
|
432
394
|
def respond_to_missing?(key)
|
|
433
|
-
|
|
395
|
+
context.respond_to?(key)
|
|
434
396
|
end
|
|
435
397
|
|
|
436
398
|
# TODO: delegate instead?
|
|
437
399
|
def method_missing(key, *args, **kwargs)
|
|
438
|
-
|
|
400
|
+
context.send(key, *args, **kwargs)
|
|
439
401
|
end
|
|
440
402
|
end
|
|
441
403
|
end
|
|
442
404
|
|
|
443
|
-
if defined?(Bridgetown)
|
|
444
|
-
Bridgetown.initializer :heartml do |config|
|
|
445
|
-
Bridgetown::Component.extend ActiveSupport::DescendantsTracker
|
|
446
|
-
|
|
447
|
-
Heartml.module_eval do
|
|
448
|
-
def render_in(view_context, rendering_mode = :string, &block)
|
|
449
|
-
self.rendering_mode = rendering_mode
|
|
450
|
-
super(view_context, &block)
|
|
451
|
-
end
|
|
452
|
-
end
|
|
453
|
-
|
|
454
|
-
# Eager load all components
|
|
455
|
-
config.hook :site, :after_reset do |site|
|
|
456
|
-
unless site.config.eager_load_paths.find { _1.end_with?(site.config.components_dir) }
|
|
457
|
-
site.config.eager_load_paths << site.config.autoload_paths.find { _1.end_with?(site.config.components_dir) }
|
|
458
|
-
end
|
|
459
|
-
end
|
|
460
|
-
|
|
461
|
-
config.html_inspector_parser "nokolexbor"
|
|
462
|
-
require_relative "heartml/component_renderer"
|
|
463
|
-
config.builder Heartml::ComponentRenderer
|
|
464
|
-
end
|
|
465
|
-
end
|
|
405
|
+
require_relative "heartml/bridgetown_renderer" if defined?(Bridgetown)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: heartml
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.0.
|
|
4
|
+
version: 1.0.0.beta4
|
|
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-08-
|
|
11
|
+
date: 2023-08-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: concurrent-ruby
|
|
@@ -70,7 +70,7 @@ files:
|
|
|
70
70
|
- benchmark.rb
|
|
71
71
|
- heartml.gemspec
|
|
72
72
|
- lib/heartml.rb
|
|
73
|
-
- lib/heartml/
|
|
73
|
+
- lib/heartml/bridgetown_renderer.rb
|
|
74
74
|
- lib/heartml/fragment.rb
|
|
75
75
|
- lib/heartml/petite.rb
|
|
76
76
|
- lib/heartml/query_selection.rb
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Heartml
|
|
4
|
-
class ComponentRenderer < Bridgetown::Builder
|
|
5
|
-
def build
|
|
6
|
-
render_heart_modules
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
# TODO: rework this using new server effects and component context!
|
|
10
|
-
def render_heart_modules
|
|
11
|
-
inspect_html do |doc, resource|
|
|
12
|
-
view_context = Bridgetown::ERBView.new(resource)
|
|
13
|
-
|
|
14
|
-
rdr = FragmentRenderComponent.new(body: doc.at_css("body"), scope: view_context)
|
|
15
|
-
rdr.define_singleton_method(:view_context) { view_context }
|
|
16
|
-
rdr.call
|
|
17
|
-
|
|
18
|
-
# Heartml.registered_elements.each do |component|
|
|
19
|
-
# tag_name = component.tag_name
|
|
20
|
-
# doc.xpath("//#{tag_name}").reverse.each do |node|
|
|
21
|
-
# if node["server-ignore"]
|
|
22
|
-
# node.remove_attribute("server-ignore")
|
|
23
|
-
# next
|
|
24
|
-
# end
|
|
25
|
-
|
|
26
|
-
# attrs = node.attributes.transform_values(&:value)
|
|
27
|
-
# attrs.reject! { |k| k.start_with?("server-") }
|
|
28
|
-
|
|
29
|
-
# new_attrs = {}
|
|
30
|
-
# attrs.each do |k, v|
|
|
31
|
-
# next unless k.start_with?("arg:")
|
|
32
|
-
|
|
33
|
-
# new_key = k.delete_prefix("arg:")
|
|
34
|
-
# attrs.delete(k)
|
|
35
|
-
# new_attrs[new_key] = resource.instance_eval(v)
|
|
36
|
-
# end
|
|
37
|
-
# attrs.merge!(new_attrs)
|
|
38
|
-
# attrs.transform_keys!(&:to_sym)
|
|
39
|
-
|
|
40
|
-
# new_node = node.replace(
|
|
41
|
-
# component.new(**attrs).render_in(view_context, rendering_mode: :node) { node.children }
|
|
42
|
-
# )
|
|
43
|
-
# new_node.remove_attribute("server-ignore")
|
|
44
|
-
# end
|
|
45
|
-
# rescue StandardError => e
|
|
46
|
-
# Bridgetown.logger.error "Unable to render <#{tag_name}> (#{component}) in #{resource.path}"
|
|
47
|
-
# raise e
|
|
48
|
-
# end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|