moxml 0.1.21 → 0.1.22

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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/opal.yml +37 -0
  3. data/.rspec-opal +5 -0
  4. data/Gemfile +6 -0
  5. data/Rakefile +67 -0
  6. data/lib/compat/opal/rexml/namespace.rb +56 -0
  7. data/lib/compat/opal/rexml/parsers/baseparser.rb +952 -0
  8. data/lib/compat/opal/rexml/source.rb +213 -0
  9. data/lib/compat/opal/rexml/text.rb +418 -0
  10. data/lib/compat/opal/rexml/xmltokens.rb +45 -0
  11. data/lib/compat/opal/rexml_compat.rb +76 -0
  12. data/lib/moxml/adapter/customized_rexml/formatter.rb +11 -10
  13. data/lib/moxml/adapter/headed_ox.rb +2 -6
  14. data/lib/moxml/adapter/libxml.rb +5 -20
  15. data/lib/moxml/adapter/nokogiri.rb +7 -18
  16. data/lib/moxml/adapter/oga.rb +4 -22
  17. data/lib/moxml/adapter/ox.rb +8 -23
  18. data/lib/moxml/adapter/rexml.rb +29 -33
  19. data/lib/moxml/adapter.rb +38 -8
  20. data/lib/moxml/config.rb +1 -1
  21. data/lib/moxml/entity_registry.rb +36 -31
  22. data/lib/moxml/entity_registry_opal_data.rb +2137 -0
  23. data/lib/moxml/node.rb +19 -26
  24. data/lib/moxml/sax/namespace_splitter.rb +54 -0
  25. data/lib/moxml/version.rb +1 -1
  26. data/lib/moxml/xml_utils.rb +9 -1
  27. data/spec/consistency/adapter_parity_spec.rb +1 -1
  28. data/spec/integration/all_adapters_spec.rb +1 -1
  29. data/spec/integration/w3c_namespace_spec.rb +1 -1
  30. data/spec/moxml/adapter/ox_spec.rb +8 -0
  31. data/spec/moxml/adapter/platform_spec.rb +69 -0
  32. data/spec/moxml/adapter/shared_examples/adapter_contract.rb +0 -6
  33. data/spec/moxml/entity_registry_spec.rb +10 -0
  34. data/spec/moxml/native_attachment/opal_spec.rb +39 -2
  35. data/spec/moxml/node_type_map_spec.rb +43 -0
  36. data/spec/moxml/opal_rexml_adapter_spec.rb +14 -0
  37. data/spec/moxml/opal_smoke_spec.rb +61 -0
  38. data/spec/moxml/sax/namespace_splitter_spec.rb +67 -0
  39. data/spec/moxml/text_spec.rb +1 -1
  40. data/spec/spec_helper.rb +32 -13
  41. data/spec/support/opal.rb +16 -0
  42. metadata +17 -1
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "json"
3
+ require "json" unless RUBY_ENGINE == "opal"
4
4
  require "set"
5
+ require_relative "entity_registry_opal_data" if RUBY_ENGINE == "opal"
5
6
 
6
7
  module Moxml
7
8
  # EntityRegistry maintains a knowledge base of XML entity definitions.
@@ -55,6 +56,10 @@ module Moxml
55
56
  # Load entity data from bundled gem data or local file
56
57
  # @return [Hash{String => String}]
57
58
  def load_entity_data
59
+ if RUBY_ENGINE == "opal"
60
+ return OPAL_ENTITY_DATA
61
+ end
62
+
58
63
  # Try multiple paths in order of priority
59
64
  paths_to_try = []
60
65
 
@@ -216,33 +221,40 @@ module Moxml
216
221
  self
217
222
  end
218
223
 
219
- # Load all entities from the W3C HTMLMathML entity set
220
- # This is called automatically by initialize
224
+ # Load all entities from the W3C HTMLMathML entity set.
225
+ # All entities are loaded during initialize; this method is a no-op
226
+ # kept for backward compatibility.
221
227
  # @return [self]
222
228
  def load_html5
223
- # All entities are loaded by default from initialize
229
+ warn "EntityRegistry#load_html5 is a no-op (all entities load during initialize)", uplevel: 1
224
230
  self
225
231
  end
226
232
 
227
- # Load MathML entity set (included in HTMLMathML)
233
+ # Load MathML entity set (included in HTMLMathML).
234
+ # All entities are loaded during initialize; this method is a no-op
235
+ # kept for backward compatibility.
228
236
  # @return [self]
229
237
  def load_mathml
230
- # All entities are loaded by default from initialize
238
+ warn "EntityRegistry#load_mathml is a no-op (all entities load during initialize)", uplevel: 1
231
239
  self
232
240
  end
233
241
 
234
- # Load ISO entity sets (included in HTMLMathML)
242
+ # Load ISO entity sets (included in HTMLMathML).
243
+ # All entities are loaded during initialize; this method is a no-op
244
+ # kept for backward compatibility.
235
245
  # @param _set_name [Symbol] (ignored, all loaded together)
236
246
  # @return [self]
237
247
  def load_iso(_set_name = :iso8879)
238
- # All entities are loaded by default from initialize
248
+ warn "EntityRegistry#load_iso is a no-op (all entities load during initialize)", uplevel: 1
239
249
  self
240
250
  end
241
251
 
242
- # Load all standard entity sets
252
+ # Load all standard entity sets.
253
+ # All entities are loaded during initialize; this method is a no-op
254
+ # kept for backward compatibility.
243
255
  # @return [self]
244
256
  def load_all
245
- # All entities are loaded by default from initialize
257
+ warn "EntityRegistry#load_all is a no-op (all entities load during initialize)", uplevel: 1
246
258
  self
247
259
  end
248
260
 
@@ -256,6 +268,17 @@ module Moxml
256
268
 
257
269
  private
258
270
 
271
+ def populate_from_hash(data)
272
+ data.each do |name, char_or_codepoint|
273
+ codepoint = char_or_codepoint.is_a?(Integer) ? char_or_codepoint : parse_codepoint(char_or_codepoint)
274
+ next unless codepoint
275
+
276
+ @by_name[name] = codepoint
277
+ @by_codepoint[codepoint] ||= []
278
+ @by_codepoint[codepoint] << name unless @by_codepoint[codepoint].include?(name)
279
+ end
280
+ end
281
+
259
282
  # Load entities from the centralized JSON data source
260
283
  # @raise [EntityDataError] if entity data is required but cannot be loaded
261
284
  # @return [void]
@@ -267,14 +290,7 @@ module Moxml
267
290
  "Entity data is not available. Set entity_load_mode to :optional or :disabled to skip entity loading."
268
291
  end
269
292
 
270
- data.each do |name, char|
271
- codepoint = parse_codepoint(char)
272
- next unless codepoint
273
-
274
- @by_name[name] = codepoint
275
- @by_codepoint[codepoint] ||= []
276
- @by_codepoint[codepoint] << name unless @by_codepoint[codepoint].include?(name)
277
- end
293
+ populate_from_hash(data)
278
294
  end
279
295
 
280
296
  # Load entities from the centralized JSON data source (optional mode)
@@ -284,14 +300,7 @@ module Moxml
284
300
  data = self.class.entity_data
285
301
  return unless data
286
302
 
287
- data.each do |name, char|
288
- codepoint = parse_codepoint(char)
289
- next unless codepoint
290
-
291
- @by_name[name] = codepoint
292
- @by_codepoint[codepoint] ||= []
293
- @by_codepoint[codepoint] << name unless @by_codepoint[codepoint].include?(name)
294
- end
303
+ populate_from_hash(data)
295
304
  rescue EntityDataError
296
305
  # Silently ignore - optional mode
297
306
  end
@@ -304,11 +313,7 @@ module Moxml
304
313
  entities = @entity_provider.call
305
314
  return unless entities
306
315
 
307
- entities.each do |name, codepoint|
308
- @by_name[name] = codepoint
309
- @by_codepoint[codepoint] ||= []
310
- @by_codepoint[codepoint] << name unless @by_codepoint[codepoint].include?(name)
311
- end
316
+ populate_from_hash(entities)
312
317
  end
313
318
 
314
319
  # Parse a Unicode character escape to codepoint