homura-runtime 0.3.24 → 0.3.25

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: 15f29c823a5ee92dbb02ebe0077fc886edfdbb090eb7d7b582b9e22e869bd865
4
- data.tar.gz: 6bcf7628ae0f110004fc35a0ca797cf3e5b62aae9141dc09ab3844501e0f33dc
3
+ metadata.gz: 0b2d4ab2b10a143e1d6498e18df0a8b434fe68375824363ab529f866cecd6893
4
+ data.tar.gz: 6a9ec9a85df8450c752cee860de6acfc5cffe9c5285372e991da9372e07527aa
5
5
  SHA512:
6
- metadata.gz: ef8beda77132a6d8adeb1527ec4036fc4fb5d636b55ea9419c90d382e52a23588992a28ba24615a4af8da42f5dabd39176a853212006cd9461463982b64d411b
7
- data.tar.gz: 2933b6ec1729bd796ad2c938121735bef2c19d5f95c41affafbd9702df888fa3b80d7bf7fbe8968596542dddb1553cb24266b2fd907f2ed80a741c0ff8a75014
6
+ metadata.gz: '08f2e8a1c214545e38378c23de1d5204ad430ebe843326a3bd92b5998223aefdef20b6ab5be7ee5b3a29949b61aea5c3b2a12d6daa2fb7e76d8b6cbc322d2cca'
7
+ data.tar.gz: 938b603a2aefe6d4f343e3ecf87b1098ef6a19c9a6c0e68d162fdd32dfa5363255fcdab9a9b42d02076036af4ab555d0e471921b86f23b845a724d06468f491b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.25 (2026-06-25)
4
+
5
+ - Override Phlex element registration before loading HTML/SVG element modules.
6
+ The override uses `define_method` instead of string `class_eval`, avoiding
7
+ `opal-parser` in Worker bundles.
8
+
3
9
  ## 0.3.24 (2026-06-25)
4
10
 
5
11
  - Add a Phlex Opal compatibility shim for `String#name`. Phlex's element
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HomuraRuntime
4
- VERSION = "0.3.24"
4
+ VERSION = "0.3.25"
5
5
  end
@@ -4,8 +4,7 @@ require "corelib/pattern_matching"
4
4
  require "zeitwerk/opal_compat"
5
5
  require "phlex" unless defined?(Phlex)
6
6
 
7
- unless
8
- String.method_defined?(:name)
7
+ unless String.method_defined?(:name)
9
8
  class String
10
9
  def name
11
10
  self
@@ -36,6 +35,73 @@ unless defined?(Phlex::SVG)
36
35
  end
37
36
  end
38
37
 
38
+ module Phlex::SGML::Elements
39
+ def register_element(method_name, tag: method_name.name.tr("_", "-"))
40
+ define_method(method_name) do |**attributes, &content|
41
+ state = @_state
42
+ buffer = state.buffer
43
+ has_content = !content.nil?
44
+
45
+ unless state.should_render?
46
+ content.call(self) if has_content
47
+ return nil
48
+ end
49
+
50
+ if attributes.length > 0
51
+ buffer << "<#{tag}"
52
+ __homura_normalize_comma_separated_tokens__(method_name, attributes)
53
+ buffer << (Phlex::ATTRIBUTE_CACHE[attributes] ||= Phlex::SGML::Attributes.generate_attributes(attributes))
54
+ buffer << ">"
55
+
56
+ if has_content
57
+ original_length = buffer.bytesize
58
+ rendered_content = content.call(self)
59
+ __implicit_output__(rendered_content) if original_length == buffer.bytesize
60
+ buffer << "</#{tag}>"
61
+ else
62
+ buffer << "</#{tag}>"
63
+ end
64
+ elsif has_content
65
+ buffer << "<#{tag}>"
66
+ original_length = buffer.bytesize
67
+ rendered_content = content.call(self)
68
+ __implicit_output__(rendered_content) if original_length == buffer.bytesize
69
+ buffer << "</#{tag}>"
70
+ else
71
+ buffer << "<#{tag}></#{tag}>"
72
+ end
73
+
74
+ flush if tag == "head"
75
+ nil
76
+ end
77
+
78
+ __registered_elements__[method_name] = tag
79
+ method_name
80
+ end
81
+
82
+ def __register_void_element__(method_name, tag: method_name.name.tr("_", "-"))
83
+ define_method(method_name) do |**attributes|
84
+ state = @_state
85
+ return unless state.should_render?
86
+
87
+ buffer = state.buffer
88
+ if attributes.length > 0
89
+ buffer << "<#{tag}"
90
+ __homura_normalize_comma_separated_tokens__(method_name, attributes)
91
+ buffer << (Phlex::ATTRIBUTE_CACHE[attributes] ||= Phlex::SGML::Attributes.generate_attributes(attributes))
92
+ buffer << ">"
93
+ else
94
+ buffer << "<#{tag}>"
95
+ end
96
+
97
+ nil
98
+ end
99
+
100
+ __registered_elements__[method_name] = tag
101
+ method_name
102
+ end
103
+ end
104
+
39
105
  require "phlex/html/void_elements"
40
106
  require "phlex/html/standard_elements"
41
107
  require "phlex/html"
@@ -246,86 +312,6 @@ if defined?(Phlex::SGML)
246
312
  end
247
313
  end
248
314
 
249
- module Phlex::SGML::Elements
250
- def register_element(method_name, tag: method_name.name.tr("_", "-"))
251
- define_method(method_name) do |**attributes, &content|
252
- state = @_state
253
- buffer = state.buffer
254
- has_content = !content.nil?
255
-
256
- unless state.should_render?
257
- content.call(self) if has_content
258
- return nil
259
- end
260
-
261
- if attributes.length > 0
262
- buffer << "<#{tag}"
263
- begin
264
- __homura_normalize_comma_separated_tokens__(method_name, attributes)
265
- buffer << (Phlex::ATTRIBUTE_CACHE[attributes] ||= Phlex::SGML::Attributes.generate_attributes(attributes))
266
- ensure
267
- buffer << ">"
268
- end
269
-
270
- if has_content
271
- begin
272
- original_length = buffer.bytesize
273
- rendered_content = content.call(self)
274
- __implicit_output__(rendered_content) if original_length == buffer.bytesize
275
- ensure
276
- buffer << "</#{tag}>"
277
- end
278
- else
279
- buffer << "</#{tag}>"
280
- end
281
- elsif has_content
282
- buffer << "<#{tag}>"
283
- begin
284
- original_length = buffer.bytesize
285
- rendered_content = content.call(self)
286
- __implicit_output__(rendered_content) if original_length == buffer.bytesize
287
- ensure
288
- buffer << "</#{tag}>"
289
- end
290
- else
291
- buffer << "<#{tag}></#{tag}>"
292
- end
293
-
294
- flush if tag == "head"
295
- nil
296
- end
297
-
298
- __registered_elements__[method_name] = tag
299
- method_name
300
- end
301
-
302
- def __register_void_element__(method_name, tag: method_name.name.tr("_", "-"))
303
- define_method(method_name) do |**attributes|
304
- state = @_state
305
- return unless state.should_render?
306
-
307
- buffer = state.buffer
308
-
309
- if attributes.length > 0
310
- buffer << "<#{tag}"
311
- begin
312
- __homura_normalize_comma_separated_tokens__(method_name, attributes)
313
- buffer << (Phlex::ATTRIBUTE_CACHE[attributes] ||= Phlex::SGML::Attributes.generate_attributes(attributes))
314
- ensure
315
- buffer << ">"
316
- end
317
- else
318
- buffer << "<#{tag}>"
319
- end
320
-
321
- nil
322
- end
323
-
324
- __registered_elements__[method_name] = tag
325
- method_name
326
- end
327
- end
328
-
329
315
  module Phlex::SGML::Attributes
330
316
  class << self
331
317
  alias __homura_generate_attributes__ generate_attributes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: homura-runtime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.24
4
+ version: 0.3.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuhiro Homma