heartml 1.0.0.beta4 → 1.0.0.beta6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +3 -1
- data/lib/heartml/fragment.rb +2 -2
- data/lib/heartml/server_effects.rb +22 -26
- data/lib/heartml/version.rb +1 -1
- data/lib/heartml.rb +16 -12
- 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: c09bc70bc5761750cc99010a62b106ff435e0f0ee9f72a259d62631c8913785c
|
4
|
+
data.tar.gz: 44bb47fca2eb847d2e6636ae99eb8446d32b488702a6c8e5dc57d39d571bf076
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3590d652c24107deb627e3f9aa0114411c3077118b38ad54fdf986019ad5b7a4262682ff407b575796085f4a54c2331a7c82a6a95b6941484242ddc838aa17f8
|
7
|
+
data.tar.gz: 4b302508a049f09c1009d126a41f73220e63a3ffe9647f9acb689de3df5e3df0977a05fce48b62683c0e139dcc0ef2136d27ecafe3ca77bcc4cf87a3565b1c2f
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [1.0.0.beta6] - 2023-09-06
|
4
|
+
|
5
|
+
- Improvements to directives syntax (use lambda argument instead of block)
|
6
|
+
|
7
|
+
## [1.0.0.beta5] - 2023-09-04
|
8
|
+
|
9
|
+
- Fix issue with ViewComponent in Rails apps
|
10
|
+
- Add fragment error handling
|
11
|
+
|
3
12
|
## [1.0.0.beta4] - 2023-08-27
|
4
13
|
|
5
14
|
- Refactor and improve Bridgetown plugin and simplify context handling for template rendering
|
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.beta6)
|
5
5
|
concurrent-ruby (~> 1.2)
|
6
6
|
nokolexbor (>= 0.4.2)
|
7
7
|
|
@@ -38,7 +38,9 @@ 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)
|
41
42
|
nokolexbor (0.5.0-arm64-darwin)
|
43
|
+
nokolexbor (0.5.0-x86_64-linux)
|
42
44
|
parallel (1.22.1)
|
43
45
|
parser (3.2.2.0)
|
44
46
|
ast (~> 2.4.1)
|
data/lib/heartml/fragment.rb
CHANGED
@@ -38,7 +38,7 @@ module Heartml
|
|
38
38
|
|
39
39
|
params.each do |param|
|
40
40
|
new_key, v2 = param.split(":").map(&:strip)
|
41
|
-
v2
|
41
|
+
v2 ||= new_key
|
42
42
|
|
43
43
|
new_attrs[new_key] = @component.evaluate_attribute_expression(attr, v2)
|
44
44
|
end
|
@@ -82,7 +82,7 @@ module Heartml
|
|
82
82
|
break unless attribute_binding.method.(attribute: attr_node, node: node)
|
83
83
|
end
|
84
84
|
rescue Exception => e # rubocop:disable Lint/RescueException
|
85
|
-
line_segments = [@component.class.heart_module, @component.
|
85
|
+
line_segments = [@component.class.heart_module, @component._line_number_of_node(attr_node)]
|
86
86
|
raise e.class, e.message.lines.first, [line_segments.join(":"), *e.backtrace]
|
87
87
|
end
|
88
88
|
end
|
@@ -28,9 +28,9 @@ module Heartml
|
|
28
28
|
Nokolexbor::Element.include JSPropertyAliases unless Nokolexbor::Element.instance_methods.include?(:textContent=)
|
29
29
|
|
30
30
|
module ClassMethods
|
31
|
-
def directive(name,
|
31
|
+
def directive(name, function)
|
32
32
|
@directives ||= {}
|
33
|
-
@directives[name.to_s] =
|
33
|
+
@directives[name.to_s] = function
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -45,19 +45,15 @@ module Heartml
|
|
45
45
|
klass.extend ClassMethods
|
46
46
|
|
47
47
|
klass.class_eval do
|
48
|
-
directive :show
|
49
|
-
element["hidden"] = "" unless value
|
50
|
-
end
|
48
|
+
directive :show, ->(_, node, value) { node["hidden"] = "" unless value }
|
51
49
|
|
52
|
-
directive :hide
|
53
|
-
element["hidden"] = "" if value
|
54
|
-
end
|
50
|
+
directive :hide, ->(_, node, value) { node["hidden"] = "" if value }
|
55
51
|
|
56
|
-
directive :classMap
|
52
|
+
directive :classMap, ->(_, node, obj) {
|
57
53
|
obj.each do |k, v|
|
58
|
-
|
54
|
+
node.add_class k.to_s if v
|
59
55
|
end
|
60
|
-
|
56
|
+
}
|
61
57
|
end
|
62
58
|
end
|
63
59
|
|
@@ -70,7 +66,7 @@ module Heartml
|
|
70
66
|
syntax = attribute.value
|
71
67
|
statements = syntax.split(";").map(&:strip)
|
72
68
|
|
73
|
-
statements.each do |statement|
|
69
|
+
statements.each do |statement|
|
74
70
|
if statement.start_with?("@")
|
75
71
|
# property assignment
|
76
72
|
expression = statement.split("=").map(&:strip)
|
@@ -86,13 +82,7 @@ module Heartml
|
|
86
82
|
arg_strs.unshift("@")
|
87
83
|
|
88
84
|
if self.class.directives[directive_name.strip[1..]]
|
89
|
-
args = arg_strs.map
|
90
|
-
next node if arg_str == "@"
|
91
|
-
|
92
|
-
next arg_str[1...-1] if arg_str.start_with?("'") # string literal
|
93
|
-
|
94
|
-
send(arg_str[1..])
|
95
|
-
end
|
85
|
+
args = arg_strs.map { _convert_effect_arg_to_value _1, node }
|
96
86
|
|
97
87
|
self.class.directives[directive_name.strip[1..]]&.(self, *args)
|
98
88
|
end
|
@@ -102,13 +92,7 @@ module Heartml
|
|
102
92
|
arg_strs = args_str.split(",").map(&:strip)
|
103
93
|
arg_strs.unshift("@")
|
104
94
|
|
105
|
-
args = arg_strs.map
|
106
|
-
next node if arg_str == "@"
|
107
|
-
|
108
|
-
next arg_str[1...-1] if arg_str.start_with?("'") # string literal
|
109
|
-
|
110
|
-
send(arg_str[1..])
|
111
|
-
end
|
95
|
+
args = arg_strs.map { _convert_effect_arg_to_value _1, node }
|
112
96
|
|
113
97
|
send(method_name.strip, *args)
|
114
98
|
end
|
@@ -116,5 +100,17 @@ module Heartml
|
|
116
100
|
attribute.name = "host-effect"
|
117
101
|
end
|
118
102
|
end
|
103
|
+
|
104
|
+
def _convert_effect_arg_to_value(arg_str, node)
|
105
|
+
return node if arg_str == "@"
|
106
|
+
|
107
|
+
return arg_str[1...-1] if arg_str.start_with?("'") # string literal
|
108
|
+
|
109
|
+
if arg_str.match(/^[0-9]/)
|
110
|
+
return arg_str.include?(".") ? arg_str.to_f : arg_str.to_i
|
111
|
+
end
|
112
|
+
|
113
|
+
send(arg_str[1..])
|
114
|
+
end
|
119
115
|
end
|
120
116
|
end
|
data/lib/heartml/version.rb
CHANGED
data/lib/heartml.rb
CHANGED
@@ -54,9 +54,13 @@ module Heartml
|
|
54
54
|
klass.attribute_binding "server-unsafe-eval", :_server_replace_binding
|
55
55
|
|
56
56
|
# Don't stomp on a superclass's `content` method
|
57
|
-
|
57
|
+
has_content_method = begin
|
58
|
+
klass.instance_method(:content)
|
59
|
+
rescue NameError
|
60
|
+
false
|
61
|
+
end
|
58
62
|
|
59
|
-
klass.include ContentMethod
|
63
|
+
klass.include ContentMethod unless has_content_method
|
60
64
|
end
|
61
65
|
|
62
66
|
# Extends the component class
|
@@ -124,10 +128,8 @@ module Heartml
|
|
124
128
|
end
|
125
129
|
end
|
126
130
|
|
127
|
-
|
128
|
-
|
129
|
-
instance_variable_get(:@doc_html)[0..loc].count("\n") + 1
|
130
|
-
end
|
131
|
+
# @return [String]
|
132
|
+
def doc_html = @doc_html
|
131
133
|
|
132
134
|
def attribute_bindings = @attribute_bindings ||= []
|
133
135
|
|
@@ -175,6 +177,7 @@ module Heartml
|
|
175
177
|
# @param content [String, Nokolexbor::Element]
|
176
178
|
def render_element(attributes: self.attributes, content: self.content, context: self.context) # rubocop:disable Metrics
|
177
179
|
doc = self.class.doc.clone
|
180
|
+
@doc_html ||= self.class.doc_html # keep a spare copy for determining error line number
|
178
181
|
@_content = content
|
179
182
|
@context = context
|
180
183
|
|
@@ -305,7 +308,7 @@ module Heartml
|
|
305
308
|
_context_locals.keys.reverse_each do |name|
|
306
309
|
eval_code = "#{name} = _context_locals[\"#{name}\"];" + eval_code
|
307
310
|
end
|
308
|
-
instance_eval(eval_code, self.class.heart_module,
|
311
|
+
instance_eval(eval_code, self.class.heart_module, _line_number_of_node(attribute))
|
309
312
|
end
|
310
313
|
|
311
314
|
def class_list_for(obj)
|
@@ -320,6 +323,11 @@ module Heartml
|
|
320
323
|
end.join(" ")
|
321
324
|
end
|
322
325
|
|
326
|
+
def _line_number_of_node(node)
|
327
|
+
loc = node.source_location
|
328
|
+
instance_variable_get(:@doc_html)[0..loc].count("\n") + 1
|
329
|
+
end
|
330
|
+
|
323
331
|
def _context_nodes = @_context_nodes ||= []
|
324
332
|
|
325
333
|
def _context_locals = @_context_locals ||= {}
|
@@ -376,12 +384,8 @@ module Heartml
|
|
376
384
|
"eval"
|
377
385
|
end
|
378
386
|
|
379
|
-
def self.line_number_of_node(_node)
|
380
|
-
# FIXME: this should actually work!
|
381
|
-
0
|
382
|
-
end
|
383
|
-
|
384
387
|
def initialize(body:, context:) # rubocop:disable Lint/MissingSuper
|
388
|
+
@doc_html = body.is_a?(String) ? body : body.to_html
|
385
389
|
@body = body.is_a?(String) ? Nokolexbor::DocumentFragment.parse(body) : body
|
386
390
|
@context = context
|
387
391
|
end
|
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.beta6
|
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-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|