hot_module 1.0.0.alpha7 → 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: 79f6d2dbc700738200463f57ed0dd8fb1f51e232ea008bb00e0f432a824d8878
4
- data.tar.gz: 5b33750ca18d01edd6601785a2505b296a20ae79ebca681237f4b7c0167f78d5
3
+ metadata.gz: 8ee386965712348631ddb7f2727e757c6a3665de96bad4ce22e5d92cc41bff07
4
+ data.tar.gz: 4ae0fce88ec73e62512105db857cd6406778dbf75d850bfce3bdb1ef02a7321b
5
5
  SHA512:
6
- metadata.gz: 320f2ea2a3b2b36f01c3ab22c41597a461e87439834f3937d38ca11ddde3a0594b65f3b15c11d26d7c640b8e742a77c59e0b38768916152de4bb90cd6a8fea6f
7
- data.tar.gz: f9d6ad5c6d41bbee14bccb1795e8435dd198621d0fb3c00bc583f582fc853bb970688440f9f3d02ce038bbce30f4699ff77cf541135ae6022165bbcddfcb12b5
6
+ metadata.gz: 829ba7ad837dd654893f48c381930ec50144094d0c4c2efd06efbd9925175d35e784a9a6097aedbf756cd018cfe11737be6f59d9eb994e4ff1ccba7d3fd04096
7
+ data.tar.gz: 5435dc0c0e835c12ce9458787a8681d1a86d259af1fd086edc8e8844f082ce6e75e820914befb5bb2ac88848a57d61219dacef3813d629b8bc554090c05199aa
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
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
+
8
+ ## [1.0.0.alpha8] - 2023-03-23
9
+
10
+ - Alias `HoTModuLe` to `HotModule` for people who are annoyed :)
11
+ - Fix bug with view context
12
+
3
13
  ## [1.0.0.alpha7] - 2023-03-23
4
14
 
5
15
  - Provide original child nodes through the view context
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hot_module (1.0.0.alpha7)
4
+ hot_module (1.0.0.alpha9)
5
5
  nokolexbor (~> 0.4)
6
6
 
7
7
  GEM
@@ -19,7 +19,7 @@ module HoTModuLe
19
19
 
20
20
  def render_html_modules(registered_tags) # rubocop:todo Metrics
21
21
  inspect_html do |doc, resource| # rubocop:todo Metrics
22
- view_context = Bridgetown::ERBView.new(resource)
22
+ view_context = HoTModuLe::View.new(resource)
23
23
 
24
24
  registered_tags.each do |tag_name, component|
25
25
  doc.xpath("//#{tag_name}").reverse.each do |node|
@@ -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.alpha7"
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
@@ -325,3 +327,5 @@ if defined?(Bridgetown)
325
327
  config.builder HoTModuLe::ComponentRenderer
326
328
  end
327
329
  end
330
+
331
+ HotModule = HoTModuLe # alias for people who are annoyed :)
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.alpha7
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: