hot_module 1.0.0.alpha8 → 1.0.0.alpha10

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: 84445fa8f0ceb1c241dc1497597ff16665383a4bcea444d41569ba673cf51e84
4
+ data.tar.gz: 8416c036a600a2655c1e1883238d49b9cfefe187b35be5e93f7aa4508c364e15
5
5
  SHA512:
6
- metadata.gz: ff5eb0bcf2c3c1b3902196b394f61ca7c206a5443c15791e716a441375694c82f8f887b90ff218d7e6fa4626e79b67262e0eae82112e46d31d0e4191b1077e29
7
- data.tar.gz: ccebd667ca63b6beb81a4a20eb0f1e9d8aeea34b4b7e15d3efc79776bc60656c5b234b8b8cdf253acfc37bb692feac0c4664e7ffb55274f070d2561d5cce96be
6
+ metadata.gz: 6285f80875501f2b04b28f10bfdf7f9145a4a5a6843a3f01ed3b3a2c0848d9584b829e1ee5b0048c41d70dde248aa8f506be25155fae1a94472c57c46c77669d
7
+ data.tar.gz: ca42664335930b9468bdcd0d2e09620cd5b3b81cd2e3dfbc1fd2bd256cabe12515796f7288fa3051d59dfe80fbb5164205f1d906d270ca43e75191b36973228f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.0.0.alpha10] - 2023-04-04
4
+
5
+ - Update debugging features based on Nokolexbor fixes
6
+
7
+ ## [1.0.0.alpha9] - 2023-04-02
8
+
9
+ - Add support for [@crystallized/shadow-effects](https://github.com/hotmodule/crystallized/tree/main/packages/shadow-effects) template syntax
10
+ - Let `camelcased` handle symbol arrays, so it works with `attr_reader`
11
+
3
12
  ## [1.0.0.alpha8] - 2023-03-23
4
13
 
5
14
  - Alias `HoTModuLe` to `HotModule` for people who are annoyed :)
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hot_module (1.0.0.alpha8)
5
- nokolexbor (~> 0.4)
4
+ hot_module (1.0.0.alpha10)
5
+ nokolexbor (>= 0.4.2)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -33,9 +33,9 @@ GEM
33
33
  racc (~> 1.4)
34
34
  nokogiri (1.14.2-x86_64-linux)
35
35
  racc (~> 1.4)
36
- nokolexbor (0.4.0-arm64-darwin)
36
+ nokolexbor (0.4.2-arm64-darwin)
37
37
  parallel (1.22.1)
38
- parser (3.2.1.1)
38
+ parser (3.2.2.0)
39
39
  ast (~> 2.4.1)
40
40
  racc (1.6.2)
41
41
  rainbow (3.1.1)
@@ -44,17 +44,17 @@ GEM
44
44
  reverse_markdown (2.1.1)
45
45
  nokogiri
46
46
  rexml (3.2.5)
47
- rubocop (1.48.1)
47
+ rubocop (1.49.0)
48
48
  json (~> 2.3)
49
49
  parallel (~> 1.10)
50
50
  parser (>= 3.2.0.0)
51
51
  rainbow (>= 2.2.2, < 4.0)
52
52
  regexp_parser (>= 1.8, < 3.0)
53
53
  rexml (>= 3.2.5, < 4.0)
54
- rubocop-ast (>= 1.26.0, < 2.0)
54
+ rubocop-ast (>= 1.28.0, < 2.0)
55
55
  ruby-progressbar (~> 1.7)
56
56
  unicode-display_width (>= 2.4.0, < 3.0)
57
- rubocop-ast (1.27.0)
57
+ rubocop-ast (1.28.0)
58
58
  parser (>= 3.2.1.0)
59
59
  rubocop-minitest (0.22.2)
60
60
  rubocop (>= 0.90, < 2.0)
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Parse, mutate, and render custom elements in Ruby using [HTML Modules](https://github.com/WICG/webcomponents/blob/gh-pages/proposals/html-modules-explainer.md).
4
4
 
5
- Great for pairing with [esbuild-plugin-html-modules](https://github.com/whitefusionhq/esbuild-plugin-html-modules) for a full-stack component rendering pipeline.
5
+ Great for pairing with [esbuild-plugin-html-modules](https://github.com/hotmodule/esbuild-plugin-html-modules) for a full-stack component rendering pipeline.
6
6
 
7
7
  ## Installation
8
8
 
@@ -26,7 +26,7 @@ To install this gem onto your local machine, run `bin/rake install`. To release
26
26
 
27
27
  ## Contributing
28
28
 
29
- Bug reports and pull requests are welcome on GitHub at https://github.com/whitefusionhq/hot_module. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/whitefusionhq/hot_module/blob/main/CODE_OF_CONDUCT.md).
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hotmodule/hot_module. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/hotmodule/hot_module/blob/main/CODE_OF_CONDUCT.md).
30
30
 
31
31
  ## License
32
32
 
@@ -34,4 +34,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
34
34
 
35
35
  ## Code of Conduct
36
36
 
37
- Everyone interacting in the HoTModuLe project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/whitefusionhq/hot_module/blob/main/CODE_OF_CONDUCT.md).
37
+ Everyone interacting in the HoTModuLe project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hotmodule/hot_module/blob/main/CODE_OF_CONDUCT.md).
data/hot_module.gemspec CHANGED
@@ -9,13 +9,13 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ["jared@whitefusion.studio"]
10
10
 
11
11
  spec.summary = "Parse, mutate, and render HTML Modules in Ruby."
12
- spec.homepage = "https://github.com/whitefusionhq/hot_module#readme"
12
+ spec.homepage = "https://github.com/hotmodule/hot_module#readme"
13
13
  spec.license = "MIT"
14
14
  spec.required_ruby_version = ">= 3.0"
15
15
 
16
16
  spec.metadata["homepage_uri"] = spec.homepage
17
- spec.metadata["source_code_uri"] = "https://github.com/whitefusionhq/hot_module"
18
- spec.metadata["changelog_uri"] = "https://github.com/whitefusionhq/hot_module/blob/main/CHANGELOG.md"
17
+ spec.metadata["source_code_uri"] = "https://github.com/hotmodule/hot_module"
18
+ spec.metadata["changelog_uri"] = "https://github.com/hotmodule/hot_module/blob/main/CHANGELOG.md"
19
19
  spec.metadata["rubygems_mfa_required"] = "true"
20
20
 
21
21
  # Specify which files should be added to the gem when it is released.
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  end
28
28
  spec.require_paths = ["lib"]
29
29
 
30
- spec.add_dependency "nokolexbor", "~> 0.4"
30
+ spec.add_dependency "nokolexbor", ">= 0.4.2"
31
31
 
32
32
  spec.add_development_dependency "hash_with_dot_access", "~> 1.2"
33
33
  end
@@ -2,10 +2,12 @@
2
2
 
3
3
  module HoTModuLe
4
4
  class Fragment
5
- def initialize(fragment, attribute_bindings, html_module:)
5
+ def initialize(fragment, component)
6
6
  @fragment = fragment
7
- @attribute_bindings = attribute_bindings
8
- @html_module = html_module
7
+ @component = component
8
+ @attribute_bindings = component.class.attribute_bindings.each do |attr_def|
9
+ attr_def.method = component.method(attr_def.method_name)
10
+ end
9
11
  end
10
12
 
11
13
  # NOTE: for some reason, the Nokogiri traverse method yields node children first, then the
@@ -32,7 +34,8 @@ module HoTModuLe
32
34
  break unless attribute_binding.method.(attribute: attr_node, node: node)
33
35
  end
34
36
  rescue Exception => e # rubocop:disable Lint/RescueException
35
- raise e.class, e.message.lines.first, ["#{@html_module}:#{attr_node}", *e.backtrace]
37
+ line_segments = [@component.class.html_module, @component.class.line_number_of_node(attr_node)]
38
+ raise e.class, e.message.lines.first, [line_segments.join(":"), *e.backtrace]
36
39
  end
37
40
  end
38
41
  end
@@ -23,7 +23,7 @@ module HoTModuLe
23
23
  process_list(
24
24
  attribute: attribute,
25
25
  node: node,
26
- item_node: node.children[0].element_children.first,
26
+ item_node: node.children[0].first_element_child,
27
27
  for_in: expression
28
28
  )
29
29
  end
@@ -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.alpha10"
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
@@ -90,9 +92,15 @@ module HoTModuLe
90
92
 
91
93
  # @return [Nokogiri::XML::Element]
92
94
  def doc
93
- @doc ||= Nokolexbor::DocumentFragment.parse(
94
- "<#{tag_name}>#{File.read(html_module).strip}</#{tag_name}>"
95
- ).element_children.first
95
+ @doc ||= begin
96
+ @doc_html = "<#{tag_name}>#{File.read(html_module).strip}</#{tag_name}>"
97
+ Nokolexbor::DocumentFragment.parse(@doc_html).first_element_child
98
+ end
99
+ end
100
+
101
+ def line_number_of_node(node)
102
+ loc = node.source_location
103
+ instance_variable_get(:@doc_html)[0..loc].count("\n") + 1
96
104
  end
97
105
 
98
106
  def attribute_bindings
@@ -216,10 +224,7 @@ module HoTModuLe
216
224
  # @param fragment [Nokogiri::XML::Element]
217
225
  # @return [void]
218
226
  def process_fragment(fragment)
219
- Fragment.new(
220
- fragment, self.class.attribute_bindings.each { _1.method = method(_1.method_name) },
221
- html_module: self.class.html_module
222
- ).process
227
+ Fragment.new(fragment, self).process
223
228
  end
224
229
 
225
230
  def process_list(attribute:, node:, item_node:, for_in:) # rubocop:disable Metrics
@@ -245,10 +250,7 @@ module HoTModuLe
245
250
  _context_locals[lh[0]] = list_item
246
251
  _context_locals[lh[1]] = index if lh[1]
247
252
 
248
- Fragment.new(
249
- new_node, self.class.attribute_bindings,
250
- html_module: self.class.html_module
251
- ).process
253
+ Fragment.new(new_node, self).process
252
254
  end
253
255
  end
254
256
  end
@@ -258,7 +260,7 @@ module HoTModuLe
258
260
  _context_locals.keys.reverse_each do |name|
259
261
  eval_code = "#{name} = _context_locals[\"#{name}\"];" + eval_code
260
262
  end
261
- instance_eval(eval_code, self.class.html_module) # , attribute.line)
263
+ instance_eval(eval_code, self.class.html_module, self.class.line_number_of_node(attribute))
262
264
  end
263
265
 
264
266
  def class_list_for(obj)
metadata CHANGED
@@ -1,29 +1,29 @@
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.alpha10
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-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokolexbor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0.4'
19
+ version: 0.4.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0.4'
26
+ version: 0.4.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: hash_with_dot_access
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -60,14 +60,15 @@ 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
- homepage: https://github.com/whitefusionhq/hot_module#readme
65
+ homepage: https://github.com/hotmodule/hot_module#readme
65
66
  licenses:
66
67
  - MIT
67
68
  metadata:
68
- homepage_uri: https://github.com/whitefusionhq/hot_module#readme
69
- source_code_uri: https://github.com/whitefusionhq/hot_module
70
- changelog_uri: https://github.com/whitefusionhq/hot_module/blob/main/CHANGELOG.md
69
+ homepage_uri: https://github.com/hotmodule/hot_module#readme
70
+ source_code_uri: https://github.com/hotmodule/hot_module
71
+ changelog_uri: https://github.com/hotmodule/hot_module/blob/main/CHANGELOG.md
71
72
  rubygems_mfa_required: 'true'
72
73
  post_install_message:
73
74
  rdoc_options: []