yob-roxml 3.1.6
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.
- data/.gitignore +7 -0
- data/.gitmodules +3 -0
- data/History.txt +354 -0
- data/LICENSE +20 -0
- data/README.rdoc +195 -0
- data/Rakefile +117 -0
- data/TODO +37 -0
- data/VERSION +1 -0
- data/examples/amazon.rb +35 -0
- data/examples/current_weather.rb +27 -0
- data/examples/dashed_elements.rb +20 -0
- data/examples/library.rb +40 -0
- data/examples/posts.rb +27 -0
- data/examples/rails.rb +70 -0
- data/examples/twitter.rb +37 -0
- data/examples/xml/active_record.xml +70 -0
- data/examples/xml/amazon.xml +133 -0
- data/examples/xml/current_weather.xml +89 -0
- data/examples/xml/dashed_elements.xml +52 -0
- data/examples/xml/posts.xml +23 -0
- data/examples/xml/twitter.xml +422 -0
- data/lib/roxml.rb +556 -0
- data/lib/roxml/definition.rb +238 -0
- data/lib/roxml/hash_definition.rb +25 -0
- data/lib/roxml/xml.rb +40 -0
- data/lib/roxml/xml/parsers/libxml.rb +85 -0
- data/lib/roxml/xml/parsers/nokogiri.rb +82 -0
- data/lib/roxml/xml/references.rb +322 -0
- data/roxml.gemspec +206 -0
- data/spec/definition_spec.rb +494 -0
- data/spec/examples/active_record_spec.rb +40 -0
- data/spec/examples/amazon_spec.rb +54 -0
- data/spec/examples/current_weather_spec.rb +37 -0
- data/spec/examples/dashed_elements_spec.rb +20 -0
- data/spec/examples/library_spec.rb +46 -0
- data/spec/examples/post_spec.rb +24 -0
- data/spec/examples/twitter_spec.rb +32 -0
- data/spec/roxml_spec.rb +372 -0
- data/spec/shared_specs.rb +15 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/support/libxml.rb +3 -0
- data/spec/support/nokogiri.rb +3 -0
- data/spec/xml/array_spec.rb +36 -0
- data/spec/xml/attributes_spec.rb +71 -0
- data/spec/xml/encoding_spec.rb +52 -0
- data/spec/xml/namespace_spec.rb +270 -0
- data/spec/xml/namespaces_spec.rb +67 -0
- data/spec/xml/object_spec.rb +82 -0
- data/spec/xml/parser_spec.rb +21 -0
- data/spec/xml/text_spec.rb +71 -0
- data/test/fixtures/book_malformed.xml +5 -0
- data/test/fixtures/book_pair.xml +8 -0
- data/test/fixtures/book_text_with_attribute.xml +5 -0
- data/test/fixtures/book_valid.xml +5 -0
- data/test/fixtures/book_with_authors.xml +7 -0
- data/test/fixtures/book_with_contributions.xml +9 -0
- data/test/fixtures/book_with_contributors.xml +7 -0
- data/test/fixtures/book_with_contributors_attrs.xml +7 -0
- data/test/fixtures/book_with_default_namespace.xml +9 -0
- data/test/fixtures/book_with_depth.xml +6 -0
- data/test/fixtures/book_with_octal_pages.xml +4 -0
- data/test/fixtures/book_with_publisher.xml +7 -0
- data/test/fixtures/book_with_wrapped_attr.xml +3 -0
- data/test/fixtures/dictionary_of_attr_name_clashes.xml +8 -0
- data/test/fixtures/dictionary_of_attrs.xml +6 -0
- data/test/fixtures/dictionary_of_guarded_names.xml +6 -0
- data/test/fixtures/dictionary_of_mixeds.xml +4 -0
- data/test/fixtures/dictionary_of_name_clashes.xml +10 -0
- data/test/fixtures/dictionary_of_names.xml +4 -0
- data/test/fixtures/dictionary_of_texts.xml +10 -0
- data/test/fixtures/library.xml +30 -0
- data/test/fixtures/library_uppercase.xml +30 -0
- data/test/fixtures/muffins.xml +3 -0
- data/test/fixtures/nameless_ageless_youth.xml +2 -0
- data/test/fixtures/node_with_attr_name_conflicts.xml +1 -0
- data/test/fixtures/node_with_name_conflicts.xml +4 -0
- data/test/fixtures/numerology.xml +4 -0
- data/test/fixtures/person.xml +1 -0
- data/test/fixtures/person_with_guarded_mothers.xml +13 -0
- data/test/fixtures/person_with_mothers.xml +10 -0
- data/test/load_test.rb +6 -0
- data/test/mocks/dictionaries.rb +57 -0
- data/test/mocks/mocks.rb +279 -0
- data/test/support/fixtures.rb +11 -0
- data/test/test_helper.rb +34 -0
- data/test/unit/definition_test.rb +235 -0
- data/test/unit/deprecations_test.rb +24 -0
- data/test/unit/to_xml_test.rb +81 -0
- data/test/unit/xml_attribute_test.rb +39 -0
- data/test/unit/xml_block_test.rb +81 -0
- data/test/unit/xml_bool_test.rb +122 -0
- data/test/unit/xml_convention_test.rb +150 -0
- data/test/unit/xml_hash_test.rb +115 -0
- data/test/unit/xml_initialize_test.rb +49 -0
- data/test/unit/xml_name_test.rb +141 -0
- data/test/unit/xml_namespace_test.rb +31 -0
- data/test/unit/xml_object_test.rb +205 -0
- data/test/unit/xml_required_test.rb +94 -0
- data/test/unit/xml_text_test.rb +71 -0
- data/website/index.html +98 -0
- metadata +300 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec/spec_helper.rb'
|
2
|
+
|
3
|
+
describe ROXML, "#xml_namespaces" do
|
4
|
+
describe "for reading" do
|
5
|
+
class Tires
|
6
|
+
include ROXML
|
7
|
+
|
8
|
+
xml_namespaces \
|
9
|
+
:bobsbike => 'http://bobsbikes.example.com',
|
10
|
+
:alicesauto => 'http://alicesautosupply.example.com/'
|
11
|
+
|
12
|
+
xml_reader :bike_tires, :as => [], :from => '@name', :in => 'bobsbike:tire'
|
13
|
+
xml_reader :car_tires, :as => [], :from => '@name', :in => 'alicesauto:tire'
|
14
|
+
xml_reader :tires, :as => [], :from => '@name', :in => 'tire', :namespace => '*'
|
15
|
+
end
|
16
|
+
|
17
|
+
before do
|
18
|
+
@xml = %{<?xml version="1.0"?>
|
19
|
+
<inventory xmlns="http://alicesautosupply.example.com/" xmlns:bike="http://bobsbikes.example.com">
|
20
|
+
<tire name="super slick racing tire" />
|
21
|
+
<tire name="all weather tire" />
|
22
|
+
<bike:tire name="skinny street" />
|
23
|
+
</inventory>
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should remap default namespaces" do
|
28
|
+
Tires.from_xml(@xml).car_tires.should =~ ['super slick racing tire', 'all weather tire']
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should remap prefix namespaces" do
|
32
|
+
Tires.from_xml(@xml).bike_tires.should == ['skinny street']
|
33
|
+
end
|
34
|
+
|
35
|
+
context "with namespace-indifferent option" do
|
36
|
+
it "should return all tires" do
|
37
|
+
Tires.from_xml(@xml).tires.should =~ ['super slick racing tire', 'all weather tire', 'skinny street']
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when an included namespace is not defined in the xml" do
|
43
|
+
context "where the missing namespace is the default" do
|
44
|
+
it "should raise"
|
45
|
+
|
46
|
+
context "but the namespace is declared in the body" do
|
47
|
+
it "should succeed"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "where the missing namespace is included in a namespacey from" do
|
52
|
+
it "should raise"
|
53
|
+
|
54
|
+
context "but the namespace is declared in the body" do
|
55
|
+
it "should succeed"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "where the missing namespace is included in an explicit :namespace" do
|
60
|
+
it "should raise"
|
61
|
+
|
62
|
+
context "but the namespace is declared in the body" do
|
63
|
+
it "should succeed"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe ROXML::XMLObjectRef do
|
4
|
+
class SubObject
|
5
|
+
include ROXML
|
6
|
+
|
7
|
+
xml_reader :value, :from => :attr
|
8
|
+
|
9
|
+
def initialize(value = nil)
|
10
|
+
@value = value
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
before do
|
15
|
+
@xml = ROXML::XML.parse_string %(
|
16
|
+
<myxml>
|
17
|
+
<node>
|
18
|
+
<name value="first" />
|
19
|
+
<name value="second" />
|
20
|
+
<name value="third" />
|
21
|
+
</node>
|
22
|
+
</myxml>)
|
23
|
+
end
|
24
|
+
|
25
|
+
context "plain vanilla" do
|
26
|
+
before do
|
27
|
+
@ref = ROXML::XMLObjectRef.new(OpenStruct.new(:name => 'name', :wrapper => 'node', :array? => false, :sought_type => SubObject), RoxmlObject.new)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should return one instance" do
|
31
|
+
@ref.value_in(@xml).value.should == "first"
|
32
|
+
end
|
33
|
+
it "should output one instance"
|
34
|
+
end
|
35
|
+
|
36
|
+
context "with :as => []" do
|
37
|
+
before do
|
38
|
+
@ref = ROXML::XMLObjectRef.new(OpenStruct.new(:name => 'name', :wrapper => 'node', :array? => true, :sought_type => SubObject), RoxmlObject.new)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should collect all instances" do
|
42
|
+
@ref.value_in(@xml).map(&:value).should == ["first", "second", "third"]
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should output all instances" do
|
46
|
+
xml = ROXML::XML.new_node('myxml')
|
47
|
+
@ref.update_xml(xml, ["first", "second", "third"].map {|value| SubObject.new(value) })
|
48
|
+
xml.to_s.squeeze(' ').should == @xml.root.to_s.squeeze(' ')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when the namespaces are different" do
|
53
|
+
before do
|
54
|
+
@xml = ROXML::XML.parse_string %(
|
55
|
+
<myxml xmlns="http://example.com/three" xmlns:one="http://example.com/one" xmlns:two="http://example.com/two">
|
56
|
+
<node>
|
57
|
+
<one:name>first</one:name>
|
58
|
+
<two:name>second</two:name>
|
59
|
+
<name>third</name>
|
60
|
+
</node>
|
61
|
+
</myxml>)
|
62
|
+
end
|
63
|
+
|
64
|
+
context "with :namespace => '*'" do
|
65
|
+
before do
|
66
|
+
@ref = ROXML::XMLObjectRef.new(OpenStruct.new(:name => 'name', :wrapper => 'node', :array? => true, :namespace => '*', :sought_type => SubObject), RoxmlObject.new)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should collect all instances" do
|
70
|
+
pending "Test bug?"
|
71
|
+
@ref.value_in(@xml).map(&:value).should == ["first", "second", "third"]
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should output all instances with namespaces" do
|
75
|
+
pending "Full namespace write support"
|
76
|
+
xml = ROXML::XML.new_node('myxml')
|
77
|
+
@ref.update_xml(xml, ["first", "second", "third"].map {|value| SubObject.new(value) })
|
78
|
+
xml.should == @xml.root
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec/spec_helper.rb'
|
2
|
+
|
3
|
+
describe ROXML::XML do
|
4
|
+
it "should raise on malformed xml" do
|
5
|
+
if ROXML::XML_PARSER == 'libxml' # nokogiri is less strict and auto-closes for some reason
|
6
|
+
proc { Book.from_xml(fixture(:book_malformed)) }.should raise_error(LibXML::XML::Error)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should escape invalid characters on output to text node" do
|
11
|
+
node = ROXML::XML.new_node("entities")
|
12
|
+
ROXML::XML.set_content(node, " < > ' \" & ")
|
13
|
+
node.to_s.should == "<entities> < > ' \" & </entities>"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should esape invalid characters for attribute name" do
|
17
|
+
node = ROXML::XML.new_node("attr_holder")
|
18
|
+
ROXML::XML.set_attribute(node, "entities", "\"'<>&")
|
19
|
+
node.to_s.should == %{<attr_holder entities=""'<>&"/>}
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe ROXML::XMLTextRef do
|
4
|
+
before do
|
5
|
+
@xml = ROXML::XML.parse_string %(
|
6
|
+
<myxml>
|
7
|
+
<node>
|
8
|
+
<name>first</name>
|
9
|
+
<name>second</name>
|
10
|
+
<name>third</name>
|
11
|
+
</node>
|
12
|
+
</myxml>)
|
13
|
+
end
|
14
|
+
|
15
|
+
context "plain vanilla" do
|
16
|
+
before do
|
17
|
+
@ref = ROXML::XMLTextRef.new(OpenStruct.new(:name => 'name', :wrapper => 'node', :array? => false), RoxmlObject.new)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return one instance" do
|
21
|
+
@ref.value_in(@xml).should == "first"
|
22
|
+
end
|
23
|
+
it "should output one instance"
|
24
|
+
end
|
25
|
+
|
26
|
+
context "with :as => []" do
|
27
|
+
before do
|
28
|
+
@ref = ROXML::XMLTextRef.new(OpenStruct.new(:name => 'name', :wrapper => 'node', :array? => true), RoxmlObject.new)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should collect all instances" do
|
32
|
+
@ref.value_in(@xml).should == ["first", "second", "third"]
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should output all instances" do
|
36
|
+
xml = ROXML::XML.new_node('myxml')
|
37
|
+
@ref.update_xml(xml, ["first", "second", "third"])
|
38
|
+
xml.to_s.squeeze(' ').should == @xml.root.to_s.squeeze(' ')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when the namespaces are different" do
|
43
|
+
before do
|
44
|
+
@xml = ROXML::XML.parse_string %(
|
45
|
+
<myxml xmlns="http://example.com/three" xmlns:one="http://example.com/one" xmlns:two="http://example.com/two">
|
46
|
+
<node>
|
47
|
+
<one:name>first</one:name>
|
48
|
+
<two:name>second</two:name>
|
49
|
+
<name>third</name>
|
50
|
+
</node>
|
51
|
+
</myxml>)
|
52
|
+
end
|
53
|
+
|
54
|
+
context "with :namespace => '*'" do
|
55
|
+
before do
|
56
|
+
@ref = ROXML::XMLTextRef.new(OpenStruct.new(:name => 'name', :wrapper => 'node', :array? => true, :namespace => '*'), RoxmlObject.new)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should collect all instances" do
|
60
|
+
@ref.value_in(@xml).should == ["first", "second", "third"]
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should output all instances with namespaces" do
|
64
|
+
pending "Full namespace write support"
|
65
|
+
xml = ROXML::XML.new_node('myxml')
|
66
|
+
@ref.update_xml(xml, ["first", "second", "third"])
|
67
|
+
xml.should == @xml.root
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<book isbn="0974514055">
|
2
|
+
<title>Programming Ruby - 2nd Edition</title>
|
3
|
+
<description>Second edition of the great book out there</description>
|
4
|
+
<book isbn="0974514055">
|
5
|
+
<title>Agile Web Development with Rails</title>
|
6
|
+
<description>Jolt winning original Ruby on Rails book</description>
|
7
|
+
</book>
|
8
|
+
</book>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<book isbn="0974514055">
|
2
|
+
<title>Programming Ruby - 2nd Edition</title>
|
3
|
+
<description>Second edition of the great book out there</description>
|
4
|
+
<contributions>
|
5
|
+
<contributor role="author"><name>David Thomas</name></contributor>
|
6
|
+
<contributor role="supporting author"><name>Andrew Hunt</name></contributor>
|
7
|
+
<contributor role="supporting author"><name>Chad Fowler</name></contributor>
|
8
|
+
</contributions>
|
9
|
+
</book>
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<book isbn="0974514055">
|
2
|
+
<title>Programming Ruby - 2nd Edition</title>
|
3
|
+
<description>Second edition of the great book out there</description>
|
4
|
+
<contributor role="author"><name>David Thomas</name></contributor>
|
5
|
+
<contributor role="supporting author"><name>Andrew Hunt</name></contributor>
|
6
|
+
<contributor role="supporting author"><name>Chad Fowler</name></contributor>
|
7
|
+
</book>
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<book isbn="0974514055">
|
2
|
+
<title>Programming Ruby - 2nd Edition</title>
|
3
|
+
<description>Second edition of the great book out there</description>
|
4
|
+
<contributor role="author" name="David Thomas" />
|
5
|
+
<contributor role="supporting author" name="Andrew Hunt" />
|
6
|
+
<contributor role="supporting author" name="Chad Fowler" />
|
7
|
+
</book>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<book xmlns="http://booknamespace.org" isbn="0974514055">
|
2
|
+
<title>Programming Ruby - 2nd Edition</title>
|
3
|
+
<description>Second edition of the great book out there</description>
|
4
|
+
<contributions>
|
5
|
+
<contributor role="author"><name>David Thomas</name></contributor>
|
6
|
+
<contributor role="supporting author"><name>Andrew Hunt</name></contributor>
|
7
|
+
<contributor role="supporting author"><name>Chad Fowler</name></contributor>
|
8
|
+
</contributions>
|
9
|
+
</book>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<dictionary>
|
2
|
+
<definition name="quaquaversally">
|
3
|
+
<content>adjective: (of a geological formation) sloping downward from the center in all directions.</content>
|
4
|
+
</definition>
|
5
|
+
<definition name="tergiversate">
|
6
|
+
<content>To use evasions or ambiguities; equivocate.</content>
|
7
|
+
</definition>
|
8
|
+
</dictionary>
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<dictionary>
|
2
|
+
<definitions>
|
3
|
+
<definition dt="quaquaversally" dd="adjective: (of a geological formation) sloping downward from the center in all directions." />
|
4
|
+
<definition dt="tergiversate" dd="To use evasions or ambiguities; equivocate." />
|
5
|
+
</definitions>
|
6
|
+
</dictionary>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<dictionary>
|
2
|
+
<definition>
|
3
|
+
<name>quaquaversally</name>
|
4
|
+
<content>adjective: (of a geological formation) sloping downward from the center in all directions.</content>
|
5
|
+
</definition>
|
6
|
+
<definition>
|
7
|
+
<name>tergiversate</name>
|
8
|
+
<content>To use evasions or ambiguities; equivocate.</content>
|
9
|
+
</definition>
|
10
|
+
</dictionary>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<dictionary>
|
2
|
+
<definition>
|
3
|
+
<word>quaquaversally</word>
|
4
|
+
<meaning>adjective: (of a geological formation) sloping downward from the center in all directions.</meaning>
|
5
|
+
</definition>
|
6
|
+
<definition>
|
7
|
+
<word>tergiversate</word>
|
8
|
+
<meaning>To use evasions or ambiguities; equivocate.</meaning>
|
9
|
+
</definition>
|
10
|
+
</dictionary>
|
@@ -0,0 +1,30 @@
|
|
1
|
+
<library>
|
2
|
+
<name>Ruby library</name>
|
3
|
+
<book isbn="0974514055">
|
4
|
+
<title>Programming Ruby - 2nd Edition</title>
|
5
|
+
<description>Second edition of the great book out there</description>
|
6
|
+
<contributions>
|
7
|
+
<contributor role="author">
|
8
|
+
<name>David Thomas</name>
|
9
|
+
</contributor>
|
10
|
+
<contributor role="supporting author">
|
11
|
+
<name>Andrew Hunt</name>
|
12
|
+
</contributor>
|
13
|
+
<contributor role="supporting author">
|
14
|
+
<name>Chad Fowler</name>
|
15
|
+
</contributor>
|
16
|
+
</contributions>
|
17
|
+
</book>
|
18
|
+
<book isbn="0974514055">
|
19
|
+
<title>Agile Web Development with Rails</title>
|
20
|
+
<description>Jolt winning original Ruby on Rails book</description>
|
21
|
+
<contributions>
|
22
|
+
<contributor role="author">
|
23
|
+
<name>David Thomas</name>
|
24
|
+
</contributor>
|
25
|
+
<contributor role="author">
|
26
|
+
<name>David Heinemeier Hansson</name>
|
27
|
+
</contributor>
|
28
|
+
</contributions>
|
29
|
+
</book>
|
30
|
+
</library>
|
@@ -0,0 +1,30 @@
|
|
1
|
+
<library>
|
2
|
+
<NAME>Ruby library</NAME>
|
3
|
+
<BOOK isbn="0974514055">
|
4
|
+
<title>Programming Ruby - 2nd Edition</title>
|
5
|
+
<description>Second edition of the great book out there</description>
|
6
|
+
<contributions>
|
7
|
+
<contributor role="author">
|
8
|
+
<name>David Thomas</name>
|
9
|
+
</contributor>
|
10
|
+
<contributor role="supporting author">
|
11
|
+
<name>Andrew Hunt</name>
|
12
|
+
</contributor>
|
13
|
+
<contributor role="supporting author">
|
14
|
+
<name>Chad Fowler</name>
|
15
|
+
</contributor>
|
16
|
+
</contributions>
|
17
|
+
</BOOK>
|
18
|
+
<BOOK isbn="0974514055">
|
19
|
+
<title>Agile Web Development with Rails</title>
|
20
|
+
<description>Jolt winning original Ruby on Rails book</description>
|
21
|
+
<contributions>
|
22
|
+
<contributor role="author">
|
23
|
+
<name>David Thomas</name>
|
24
|
+
</contributor>
|
25
|
+
<contributor role="author">
|
26
|
+
<name>David Heinemeier Hansson</name>
|
27
|
+
</contributor>
|
28
|
+
</contributions>
|
29
|
+
</BOOK>
|
30
|
+
</library>
|