moxml 0.1.23 → 0.1.24

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 (45) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/lib/compat/opal/moxml_boot.rb +53 -0
  4. data/lib/moxml/adapter/base.rb +5 -5
  5. data/lib/moxml/adapter/customized_libxml/cdata.rb +0 -2
  6. data/lib/moxml/adapter/customized_libxml/comment.rb +0 -2
  7. data/lib/moxml/adapter/customized_libxml/element.rb +3 -5
  8. data/lib/moxml/adapter/customized_libxml/node.rb +2 -2
  9. data/lib/moxml/adapter/customized_libxml/processing_instruction.rb +0 -2
  10. data/lib/moxml/adapter/customized_libxml/text.rb +0 -2
  11. data/lib/moxml/adapter/customized_rexml/formatter.rb +3 -4
  12. data/lib/moxml/adapter/headed_ox.rb +1 -5
  13. data/lib/moxml/adapter/libxml.rb +12 -10
  14. data/lib/moxml/adapter/nokogiri.rb +4 -2
  15. data/lib/moxml/adapter/oga.rb +10 -10
  16. data/lib/moxml/adapter/ox.rb +29 -16
  17. data/lib/moxml/adapter/rexml.rb +5 -6
  18. data/lib/moxml/adapter.rb +12 -4
  19. data/lib/moxml/attribute.rb +5 -2
  20. data/lib/moxml/config.rb +1 -0
  21. data/lib/moxml/context.rb +8 -8
  22. data/lib/moxml/declaration.rb +2 -7
  23. data/lib/moxml/document.rb +0 -11
  24. data/lib/moxml/document_builder.rb +12 -8
  25. data/lib/moxml/element.rb +4 -4
  26. data/lib/moxml/node.rb +37 -14
  27. data/lib/moxml/node_set.rb +2 -4
  28. data/lib/moxml/sax/block_handler.rb +0 -2
  29. data/lib/moxml/sax/element_handler.rb +0 -2
  30. data/lib/moxml/sax/namespace_splitter.rb +5 -4
  31. data/lib/moxml/sax.rb +4 -25
  32. data/lib/moxml/version.rb +1 -1
  33. data/lib/moxml/xml_utils.rb +1 -3
  34. data/lib/moxml/xpath/compiler.rb +1 -49
  35. data/lib/moxml/xpath/conversion.rb +7 -6
  36. data/lib/moxml/xpath/ruby/generator.rb +12 -19
  37. data/lib/moxml/xpath/ruby/node.rb +1 -9
  38. data/lib/moxml/xpath.rb +6 -14
  39. data/lib/moxml.rb +67 -20
  40. data/spec/moxml/attribute_spec.rb +16 -0
  41. data/spec/moxml/context_spec.rb +14 -0
  42. data/spec/moxml/moxml_spec.rb +13 -0
  43. data/spec/moxml/node_spec.rb +58 -0
  44. data/spec/moxml/xpath/ruby/node_spec.rb +3 -3
  45. metadata +3 -2
@@ -25,4 +25,18 @@ RSpec.describe Moxml::Context do
25
25
  expect(context.config.adapter.ancestors).to include(Moxml::Adapter::Base)
26
26
  end
27
27
  end
28
+
29
+ describe "#build" do
30
+ it "creates a document via builder DSL" do
31
+ doc = context.build do
32
+ element("root") do
33
+ element("child") do
34
+ text("hello")
35
+ end
36
+ end
37
+ end
38
+ expect(doc).to be_a(Moxml::Document)
39
+ expect(doc.root.name).to eq("root")
40
+ end
41
+ end
28
42
  end
@@ -52,4 +52,17 @@ RSpec.describe Moxml do
52
52
  expect(Moxml::Config::VALID_ADAPTERS).to include(Moxml::Config.runtime_default_adapter)
53
53
  end
54
54
  end
55
+
56
+ describe ".parse" do
57
+ it "parses XML with shorthand" do
58
+ doc = described_class.parse("<root>hello</root>")
59
+ expect(doc).to be_a(Moxml::Document)
60
+ expect(doc.root.text).to eq("hello")
61
+ end
62
+
63
+ it "accepts adapter option" do
64
+ doc = described_class.parse("<root/>", adapter: :rexml)
65
+ expect(doc).to be_a(Moxml::Document)
66
+ end
67
+ end
55
68
  end
@@ -34,4 +34,62 @@ RSpec.describe Moxml::Node do
34
34
  expect(node.children).to be_empty
35
35
  end
36
36
  end
37
+
38
+ describe "#each" do
39
+ it "yields direct children" do
40
+ children = node.map { |c| c }
41
+ expect(children.size).to eq(1)
42
+ expect(children.first).to be_a(Moxml::Element)
43
+ end
44
+
45
+ it "includes Enumerable" do
46
+ expect(node.map(&:name)).to eq(["child"])
47
+ end
48
+ end
49
+
50
+ describe "#outer_xml" do
51
+ it "returns same as to_xml" do
52
+ child = node.children.first
53
+ expect(child.outer_xml).to eq(child.to_xml)
54
+ end
55
+ end
56
+
57
+ describe "#before" do
58
+ it "adds a node before self" do
59
+ child = node.children.first
60
+ child.before("before")
61
+ siblings = node.children.map(&:content).join
62
+ expect(siblings).to include("before")
63
+ end
64
+ end
65
+
66
+ describe "#after" do
67
+ it "adds a node after self" do
68
+ child = node.children.first
69
+ child.after("after")
70
+ expect(node.children.size).to be >= 2
71
+ end
72
+ end
73
+
74
+ describe "#blank?" do
75
+ it "returns true for whitespace-only text" do
76
+ doc2 = context.parse("<root> </root>")
77
+ expect(doc2.root).to be_blank
78
+ end
79
+
80
+ it "returns false for non-blank content" do
81
+ expect(node).not_to be_blank
82
+ end
83
+ end
84
+
85
+ describe "#content" do
86
+ it "returns empty string on base Node" do
87
+ expect(described_class.new(nil, context).content).to eq("")
88
+ end
89
+
90
+ it "returns text on Element" do
91
+ child = node.children.first
92
+ expect(child.content).to eq("text")
93
+ end
94
+ end
37
95
  end
@@ -113,13 +113,13 @@ RSpec.describe Moxml::XPath::Ruby::Node do
113
113
  describe "#is_a?" do
114
114
  it "creates a :send node for is_a? method call" do
115
115
  node = described_class.new(:lit, ["obj"])
116
- result = node.is_a?(String)
116
+ klass_node = described_class.new(:const, ["String"])
117
+ result = node.is_a?(klass_node)
117
118
 
118
119
  expect(result.type).to eq(:send)
119
120
  expect(result.to_a[0]).to eq(node)
120
121
  expect(result.to_a[1]).to eq("is_a?")
121
- expect(result.to_a[2].type).to eq(:lit)
122
- expect(result.to_a[2].to_a[0]).to eq("String")
122
+ expect(result.to_a[2]).to eq(klass_node)
123
123
  end
124
124
  end
125
125
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moxml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.23
4
+ version: 0.1.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-06-01 00:00:00.000000000 Z
11
+ date: 2026-06-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Moxml is a unified XML manipulation library that provides a common API
@@ -98,6 +98,7 @@ files:
98
98
  - examples/web_scraper/README.md
99
99
  - examples/web_scraper/example_page.html
100
100
  - examples/web_scraper/web_scraper.rb
101
+ - lib/compat/opal/moxml_boot.rb
101
102
  - lib/compat/opal/rexml/namespace.rb
102
103
  - lib/compat/opal/rexml/parsers/baseparser.rb
103
104
  - lib/compat/opal/rexml/source.rb