heartml 1.0.0.beta5 → 1.0.0.beta7

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: b691744cecebf95f2fb8f13f06a78eee6329bc9a2d254c164ee40dd3f02dadf2
4
+ data.tar.gz: f414b9bea17b174e3b0da67b4bad5cbe8e16e27e88f171cd6282e2932ea2ab27
5
5
  SHA512:
6
- metadata.gz: 36c6248a2b135f2d11b20b054d2a6bf8334460d56fe184a6c4d646e92561c2210e1e3a707975930613ed86091812708888b14d1fbd46f5efefe3befe3aeb3558
7
- data.tar.gz: a4241d8e092361148f6ce228c0023007c7e97e650ab4c4336ea12b1f61287f1c1b034eff06f97f6718ae1c400fb82f252197de9205bdd7057058ad382cb56ce6
6
+ metadata.gz: 38a1ea44179bc544eecccdce6dcb8a7628f6c203f49bfbf27674eab0a358b9f943d9e52482a6f42be890a81caf2a95a4904416280f5c56c8b67c5b0ae372671f
7
+ data.tar.gz: cb6ee9fa4cabf62994186774b1ab93ba36136ed2a945797c98fad82f35e51ae00e5d4356ba4a40625fae95026e8b1fc6d4b076b9d7e2ae8740cfa2d250a44877
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,15 @@
1
+ # Changelog
2
+
1
3
  ## [Unreleased]
2
4
 
5
+ ## [1.0.0.beta7] - 2023-09-25
6
+
7
+ - Add Railtie for Heartml component support in Rails
8
+
9
+ ## [1.0.0.beta6] - 2023-09-06
10
+
11
+ - Improvements to directives syntax (use lambda argument instead of block)
12
+
3
13
  ## [1.0.0.beta5] - 2023-09-04
4
14
 
5
15
  - 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.beta7)
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,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Heartml
4
+ class Railtie < ::Rails::Railtie
5
+ module ReloadDocsInDevelopment
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ before_action :reload_docs
10
+ end
11
+
12
+ def reload_docs
13
+ Heartml.registered_elements.each { _1.instance_variable_set(:@doc, nil) }
14
+ end
15
+ end
16
+
17
+ initializer "heartml.reload_docs_in_development" do |_app|
18
+ unless Rails.env.production?
19
+ ActiveSupport.on_load(:action_controller_base) do
20
+ include ReloadDocsInDevelopment
21
+ end
22
+ end
23
+ end
24
+
25
+ config.to_prepare do
26
+ next if Rails.env.production?
27
+
28
+ components_folder = Rails.root.join("app", "components")
29
+ unless File.directory?(components_folder)
30
+ Rails.logger.error "Heartml: missing `app/components' folder, cannot load elements"
31
+ next
32
+ end
33
+
34
+ Rails.autoloaders.main.eager_load_dir components_folder
35
+ end
36
+ end
37
+ 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, &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.beta7"
6
6
  end
data/lib/heartml.rb CHANGED
@@ -407,3 +407,4 @@ module Heartml
407
407
  end
408
408
 
409
409
  require_relative "heartml/bridgetown_renderer" if defined?(Bridgetown)
410
+ require_relative "heartml/railtie" if defined?(Rails::Railtie)
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.beta7
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-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -74,6 +74,7 @@ files:
74
74
  - lib/heartml/fragment.rb
75
75
  - lib/heartml/petite.rb
76
76
  - lib/heartml/query_selection.rb
77
+ - lib/heartml/railtie.rb
77
78
  - lib/heartml/server_effects.rb
78
79
  - lib/heartml/version.rb
79
80
  homepage: https://github.com/heartml/heartml-ruby#readme