hot_module 1.0.0.alpha8 → 1.0.0.alpha9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 990a6f28bab40a5307b988d5409362c5f3b5c913306785acc893b30d01a53ca2
4
- data.tar.gz: 52cbe7db9a562446c7d4c5c1b8327863aa2128f9fd78cc55945a48441c212d32
3
+ metadata.gz: 8ee386965712348631ddb7f2727e757c6a3665de96bad4ce22e5d92cc41bff07
4
+ data.tar.gz: 4ae0fce88ec73e62512105db857cd6406778dbf75d850bfce3bdb1ef02a7321b
5
5
  SHA512:
6
- metadata.gz: ff5eb0bcf2c3c1b3902196b394f61ca7c206a5443c15791e716a441375694c82f8f887b90ff218d7e6fa4626e79b67262e0eae82112e46d31d0e4191b1077e29
7
- data.tar.gz: ccebd667ca63b6beb81a4a20eb0f1e9d8aeea34b4b7e15d3efc79776bc60656c5b234b8b8cdf253acfc37bb692feac0c4664e7ffb55274f070d2561d5cce96be
6
+ metadata.gz: 829ba7ad837dd654893f48c381930ec50144094d0c4c2efd06efbd9925175d35e784a9a6097aedbf756cd018cfe11737be6f59d9eb994e4ff1ccba7d3fd04096
7
+ data.tar.gz: 5435dc0c0e835c12ce9458787a8681d1a86d259af1fd086edc8e8844f082ce6e75e820914befb5bb2ac88848a57d61219dacef3813d629b8bc554090c05199aa
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.0.0.alpha9] - 2023-04-02
4
+
5
+ - Add support for [@crystallized/shadow-effects](https://github.com/whitefusionhq/crystallized/tree/main/packages/shadow-effects) template syntax
6
+ - Let `camelcased` handle symbol arrays, so it works with `attr_reader`
7
+
3
8
  ## [1.0.0.alpha8] - 2023-03-23
4
9
 
5
10
  - Alias `HoTModuLe` to `HotModule` for people who are annoyed :)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hot_module (1.0.0.alpha8)
4
+ hot_module (1.0.0.alpha9)
5
5
  nokolexbor (~> 0.4)
6
6
 
7
7
  GEM
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "hot_module"
4
+
5
+ module HoTModuLe
6
+ module ShadowEffects
7
+ # rubocop:disable Naming/MethodName
8
+ module JSPropertyAliases
9
+ def textContent=(value)
10
+ self.content = value
11
+ end
12
+
13
+ def innerHTML=(value)
14
+ self.inner_html = value
15
+ end
16
+
17
+ def method_missing(meth, *args, **kwargs) # rubocop:disable Style/MissingRespondToMissing
18
+ return super unless meth.to_s.end_with?("=")
19
+
20
+ kebob_cased = meth.to_s
21
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1-\2')
22
+ .gsub(/([a-z\d])([A-Z])/, '\1-\2')
23
+ .downcase
24
+
25
+ self[kebob_cased.delete_suffix("=")] = args[0]
26
+ end
27
+ end
28
+ # rubocop:enable Naming/MethodName
29
+
30
+ Nokolexbor::Element.include JSPropertyAliases unless Nokolexbor::Element.instance_methods.include?(:textContent=)
31
+
32
+ module ClassMethods
33
+ def directive(name, &block)
34
+ @directives ||= {}
35
+ @directives[name.to_s] = block
36
+ end
37
+ end
38
+
39
+ # @param klass [Class]
40
+ # @return [void]
41
+ def self.included(klass)
42
+ klass.attribute_binding "host-effect", :_shadow_effect_binding
43
+
44
+ klass.singleton_class.attr_reader :directives
45
+
46
+ klass.extend ClassMethods
47
+
48
+ klass.class_eval do
49
+ directive :show do |_, element, value|
50
+ element["hidden"] = "" unless value
51
+ end
52
+
53
+ directive :hide do |_, element, value|
54
+ element["hidden"] = "" if value
55
+ end
56
+
57
+ directive :classMap do |_, element, obj|
58
+ obj.each do |k, v|
59
+ element.add_class k.to_s if v
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ def _shadow_effect_binding(attribute:, node:) # rubocop:disable Metrics
66
+ syntax = attribute.value
67
+ statements = syntax.split(";").map(&:strip)
68
+
69
+ statements.each do |statement| # rubocop:disable Metrics
70
+ if statement.start_with?("$el.")
71
+ # property assignment
72
+ expression = statement.split("=").map(&:strip)
73
+ expression[0] = expression[0][4..]
74
+
75
+ value = send(expression[1])
76
+
77
+ node.send("#{expression[0]}=", value_to_attribute(value))
78
+ elsif statement.start_with?("$")
79
+ # directive
80
+ directive_name, args_str = statement.strip.match(/(.*)\((.*)\)/).captures
81
+ arg_strs = args_str.split(",").map(&:strip)
82
+ arg_strs.unshift("$el")
83
+
84
+ if self.class.directives[directive_name.strip[1..]]
85
+ args = arg_strs.map do |arg_str|
86
+ next node if arg_str == "$el"
87
+
88
+ next arg_str[1...-1] if arg_str.start_with?("'") # string literal
89
+
90
+ send(arg_str)
91
+ end
92
+
93
+ self.class.directives[directive_name.strip[1..]]&.(self, *args)
94
+ end
95
+ else
96
+ # method call
97
+ method_name, args_str = statement.strip.match(/(.*)\((.*)\)/).captures
98
+ arg_strs = args_str.split(",").map(&:strip)
99
+
100
+ args = arg_strs.map do |arg_str|
101
+ next node if arg_str == "$el"
102
+
103
+ next arg_str[1...-1] if arg_str.start_with?("'") # string literal
104
+
105
+ send(arg_str)
106
+ end
107
+
108
+ send(method_name.strip, *args)
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module HoTModuLe
4
4
  # @return [String]
5
- VERSION = "1.0.0.alpha8"
5
+ VERSION = "1.0.0.alpha9"
6
6
  end
data/lib/hot_module.rb CHANGED
@@ -35,8 +35,10 @@ module HoTModuLe
35
35
 
36
36
  # Extends the component class
37
37
  module ClassMethods
38
- def camelcased(method_symbol)
39
- alias_method(method_symbol.to_s.gsub(/(?!^)_[a-z0-9]/) { |match| match[1].upcase }, method_symbol)
38
+ def camelcased(method_symbols)
39
+ Array(method_symbols).each do |method_symbol|
40
+ alias_method(method_symbol.to_s.gsub(/(?!^)_[a-z0-9]/) { |match| match[1].upcase }, method_symbol)
41
+ end
40
42
  end
41
43
 
42
44
  def html_file_extensions = %w[module.html tmpl.html html].freeze
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.alpha8
4
+ version: 1.0.0.alpha9
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-25 00:00:00.000000000 Z
11
+ date: 2023-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokolexbor
@@ -60,6 +60,7 @@ files:
60
60
  - lib/hot_module/fragment.rb
61
61
  - lib/hot_module/petite.rb
62
62
  - lib/hot_module/query_selection.rb
63
+ - lib/hot_module/shadow_effects.rb
63
64
  - lib/hot_module/version.rb
64
65
  homepage: https://github.com/whitefusionhq/hot_module#readme
65
66
  licenses: