heartml 1.0.0.beta5 → 1.0.0.beta6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 053e789d42574715a2f4269205a6dfe549a3d4af6970a6f6446b51735a9be340
4
- data.tar.gz: cfe795359ca2e951218853f336057d4751bac7e04564bc857808573c3f2e045a
3
+ metadata.gz: c09bc70bc5761750cc99010a62b106ff435e0f0ee9f72a259d62631c8913785c
4
+ data.tar.gz: 44bb47fca2eb847d2e6636ae99eb8446d32b488702a6c8e5dc57d39d571bf076
5
5
  SHA512:
6
- metadata.gz: 36c6248a2b135f2d11b20b054d2a6bf8334460d56fe184a6c4d646e92561c2210e1e3a707975930613ed86091812708888b14d1fbd46f5efefe3befe3aeb3558
7
- data.tar.gz: a4241d8e092361148f6ce228c0023007c7e97e650ab4c4336ea12b1f61287f1c1b034eff06f97f6718ae1c400fb82f252197de9205bdd7057058ad382cb56ce6
6
+ metadata.gz: 3590d652c24107deb627e3f9aa0114411c3077118b38ad54fdf986019ad5b7a4262682ff407b575796085f4a54c2331a7c82a6a95b6941484242ddc838aa17f8
7
+ data.tar.gz: 4b302508a049f09c1009d126a41f73220e63a3ffe9647f9acb689de3df5e3df0977a05fce48b62683c0e139dcc0ef2136d27ecafe3ca77bcc4cf87a3565b1c2f
data/.rubocop.yml CHANGED
@@ -18,6 +18,9 @@ Style/Documentation:
18
18
  Style/LambdaCall:
19
19
  Enabled: false
20
20
 
21
+ Style/Lambda:
22
+ Enabled: false
23
+
21
24
  Style/ParallelAssignment:
22
25
  Enabled: false
23
26
 
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
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
+
3
7
  ## [1.0.0.beta5] - 2023-09-04
4
8
 
5
9
  - Fix issue with ViewComponent in Rails apps
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- heartml (1.0.0.beta5)
4
+ heartml (1.0.0.beta6)
5
5
  concurrent-ruby (~> 1.2)
6
6
  nokolexbor (>= 0.4.2)
7
7
 
@@ -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, &block)
31
+ def directive(name, function)
32
32
  @directives ||= {}
33
- @directives[name.to_s] = block
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 do |_, element, value|
49
- element["hidden"] = "" unless value
50
- end
48
+ directive :show, ->(_, node, value) { node["hidden"] = "" unless value }
51
49
 
52
- directive :hide do |_, element, value|
53
- element["hidden"] = "" if value
54
- end
50
+ directive :hide, ->(_, node, value) { node["hidden"] = "" if value }
55
51
 
56
- directive :classMap do |_, element, obj|
52
+ directive :classMap, ->(_, node, obj) {
57
53
  obj.each do |k, v|
58
- element.add_class k.to_s if v
54
+ node.add_class k.to_s if v
59
55
  end
60
- end
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| # rubocop:disable Metrics
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 do |arg_str|
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 do |arg_str|
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Heartml
4
4
  # @return [String]
5
- VERSION = "1.0.0.beta5"
5
+ VERSION = "1.0.0.beta6"
6
6
  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.beta5
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-09-05 00:00:00.000000000 Z
11
+ date: 2023-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby