doxo-roxml 2.5.3

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 (104) hide show
  1. data/History.txt +279 -0
  2. data/MIT-LICENSE +18 -0
  3. data/Manifest.txt +103 -0
  4. data/README.rdoc +158 -0
  5. data/Rakefile +96 -0
  6. data/TODO +62 -0
  7. data/config/website.yml +2 -0
  8. data/examples/active_record.rb +70 -0
  9. data/examples/amazon.rb +33 -0
  10. data/examples/current_weather.rb +27 -0
  11. data/examples/dashed_elements.rb +20 -0
  12. data/examples/library.rb +40 -0
  13. data/examples/posts.rb +27 -0
  14. data/examples/twitter.rb +37 -0
  15. data/examples/xml/active_record.xml +70 -0
  16. data/examples/xml/amazon.xml +133 -0
  17. data/examples/xml/current_weather.xml +89 -0
  18. data/examples/xml/dashed_elements.xml +52 -0
  19. data/examples/xml/posts.xml +23 -0
  20. data/examples/xml/twitter.xml +422 -0
  21. data/lib/roxml.rb +511 -0
  22. data/lib/roxml/definition.rb +234 -0
  23. data/lib/roxml/extensions.rb +6 -0
  24. data/lib/roxml/extensions/array.rb +13 -0
  25. data/lib/roxml/extensions/array/conversions.rb +12 -0
  26. data/lib/roxml/extensions/deprecation.rb +33 -0
  27. data/lib/roxml/extensions/string.rb +6 -0
  28. data/lib/roxml/extensions/string/conversions.rb +5 -0
  29. data/lib/roxml/extensions/string/iterators.rb +12 -0
  30. data/lib/roxml/hash_definition.rb +25 -0
  31. data/lib/roxml/xml.rb +40 -0
  32. data/lib/roxml/xml/parsers/libxml.rb +86 -0
  33. data/lib/roxml/xml/parsers/rexml.rb +84 -0
  34. data/lib/roxml/xml/references.rb +299 -0
  35. data/roxml.gemspec +50 -0
  36. data/spec/definition_spec.rb +490 -0
  37. data/spec/examples/active_record_spec.rb +40 -0
  38. data/spec/examples/amazon_spec.rb +53 -0
  39. data/spec/examples/current_weather_spec.rb +37 -0
  40. data/spec/examples/dashed_elements_spec.rb +20 -0
  41. data/spec/examples/library_spec.rb +46 -0
  42. data/spec/examples/post_spec.rb +24 -0
  43. data/spec/examples/twitter_spec.rb +32 -0
  44. data/spec/roxml_spec.rb +372 -0
  45. data/spec/shared_specs.rb +15 -0
  46. data/spec/spec.opts +1 -0
  47. data/spec/spec_helper.rb +33 -0
  48. data/spec/xml/parser_spec.rb +47 -0
  49. data/tasks/rspec.rake +21 -0
  50. data/tasks/test.rake +42 -0
  51. data/test/bugs/rexml_bugs.rb +15 -0
  52. data/test/fixtures/book_malformed.xml +5 -0
  53. data/test/fixtures/book_pair.xml +8 -0
  54. data/test/fixtures/book_text_with_attribute.xml +5 -0
  55. data/test/fixtures/book_valid.xml +5 -0
  56. data/test/fixtures/book_with_authors.xml +7 -0
  57. data/test/fixtures/book_with_contributions.xml +9 -0
  58. data/test/fixtures/book_with_contributors.xml +7 -0
  59. data/test/fixtures/book_with_contributors_attrs.xml +7 -0
  60. data/test/fixtures/book_with_default_namespace.xml +9 -0
  61. data/test/fixtures/book_with_depth.xml +6 -0
  62. data/test/fixtures/book_with_octal_pages.xml +4 -0
  63. data/test/fixtures/book_with_publisher.xml +7 -0
  64. data/test/fixtures/book_with_wrapped_attr.xml +3 -0
  65. data/test/fixtures/dictionary_of_attr_name_clashes.xml +8 -0
  66. data/test/fixtures/dictionary_of_attrs.xml +6 -0
  67. data/test/fixtures/dictionary_of_guarded_names.xml +6 -0
  68. data/test/fixtures/dictionary_of_mixeds.xml +4 -0
  69. data/test/fixtures/dictionary_of_name_clashes.xml +10 -0
  70. data/test/fixtures/dictionary_of_names.xml +4 -0
  71. data/test/fixtures/dictionary_of_texts.xml +10 -0
  72. data/test/fixtures/library.xml +30 -0
  73. data/test/fixtures/library_uppercase.xml +30 -0
  74. data/test/fixtures/muffins.xml +3 -0
  75. data/test/fixtures/nameless_ageless_youth.xml +2 -0
  76. data/test/fixtures/node_with_attr_name_conflicts.xml +1 -0
  77. data/test/fixtures/node_with_name_conflicts.xml +4 -0
  78. data/test/fixtures/numerology.xml +4 -0
  79. data/test/fixtures/person.xml +1 -0
  80. data/test/fixtures/person_with_guarded_mothers.xml +13 -0
  81. data/test/fixtures/person_with_mothers.xml +10 -0
  82. data/test/mocks/dictionaries.rb +57 -0
  83. data/test/mocks/mocks.rb +279 -0
  84. data/test/test_helper.rb +45 -0
  85. data/test/unit/definition_test.rb +235 -0
  86. data/test/unit/deprecations_test.rb +24 -0
  87. data/test/unit/to_xml_test.rb +81 -0
  88. data/test/unit/xml_attribute_test.rb +39 -0
  89. data/test/unit/xml_block_test.rb +81 -0
  90. data/test/unit/xml_bool_test.rb +122 -0
  91. data/test/unit/xml_convention_test.rb +150 -0
  92. data/test/unit/xml_hash_test.rb +115 -0
  93. data/test/unit/xml_initialize_test.rb +49 -0
  94. data/test/unit/xml_name_test.rb +141 -0
  95. data/test/unit/xml_namespace_test.rb +76 -0
  96. data/test/unit/xml_object_test.rb +207 -0
  97. data/test/unit/xml_required_test.rb +93 -0
  98. data/test/unit/xml_text_test.rb +71 -0
  99. data/vendor/override_rake_task/README +30 -0
  100. data/vendor/override_rake_task/init.rb +1 -0
  101. data/vendor/override_rake_task/install.rb +46 -0
  102. data/vendor/override_rake_task/lib/override_rake_task.rb +16 -0
  103. data/website/index.html +98 -0
  104. metadata +234 -0
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "freezable xml reference", :shared => true do
4
+ describe "with :frozen option" do
5
+ it "should be frozen" do
6
+ @frozen.frozen?.should be_true
7
+ end
8
+ end
9
+
10
+ describe "without :frozen option" do
11
+ it "should not be frozen" do
12
+ @unfrozen.frozen?.should be_false
13
+ end
14
+ end
15
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,33 @@
1
+ require 'pathname'
2
+
3
+ module ROXML
4
+ SILENCE_XML_NAME_WARNING = true
5
+ end
6
+
7
+ DIR = Pathname.new(__FILE__ + '../..').expand_path.dirname
8
+ LOAD_PATH = DIR.join('lib').to_s
9
+ $LOAD_PATH.unshift(LOAD_PATH) unless
10
+ $LOAD_PATH.include?(LOAD_PATH) || $LOAD_PATH.include?(File.expand_path(LOAD_PATH))
11
+ require 'roxml'
12
+
13
+ require File.join(File.dirname(__FILE__), 'shared_specs')
14
+
15
+ def example(name)
16
+ DIR.join("examples/#{name}.rb")
17
+ end
18
+
19
+ def fixture(name)
20
+ File.read(fixture_path(name))
21
+ end
22
+
23
+ def xml_fixture(name)
24
+ ROXML::XML::Parser.parse_file(fixture_path(name)).root
25
+ end
26
+
27
+ def fixture_path(name)
28
+ "test/fixtures/#{name}.xml"
29
+ end
30
+
31
+ def xml_for(name)
32
+ DIR.join("examples/xml/#{name}.xml")
33
+ end
@@ -0,0 +1,47 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ describe ROXML::XML::Parser do
4
+ before do
5
+ # quiet the error handler
6
+ ROXML::XML::Error.reset_handler
7
+ end
8
+
9
+ it "should raise on malformed xml" do
10
+ proc { Book.from_xml(fixture(:book_malformed)) }.should raise_error(ROXML::XML::Error)
11
+ end
12
+
13
+ it "should escape invalid characters on output to text node" do
14
+ node = ROXML::XML::Node.new("entities")
15
+ node.content = " < > ' \" & "
16
+ if ROXML::XML_PARSER == 'libxml'
17
+ node.to_s.should == "<entities> &lt; &gt; ' \" &amp; </entities>"
18
+ else
19
+ node.to_s.should == "<entities> &lt; &gt; &apos; &quot; &amp; </entities>"
20
+ end
21
+ end
22
+
23
+ it "should esape invalid characters for attribute name" do
24
+ node = ROXML::XML::Node.new("attr_holder")
25
+ node.attributes["entities"] = "\"'<>&"
26
+ if ROXML::XML_PARSER == 'libxml'
27
+ node.to_s.should == %{<attr_holder entities="&quot;'&lt;&gt;&amp;"/>}
28
+ else
29
+ node.to_s.should == %{<attr_holder entities='&quot;&apos;&lt;&gt;&amp;'/>}
30
+ end
31
+ end
32
+ end
33
+
34
+ describe ROXML::XML::Document do
35
+ describe "#save" do
36
+ context "with rexml parser" do
37
+ it "should defer to existing XMLDecl" do
38
+ if ROXML::XML_PARSER == 'rexml'
39
+ @doc = ROXML::XML::Document.new
40
+ @doc << REXML::XMLDecl.new('1.1')
41
+ @doc.save('spec/xml/decl_test.xml')
42
+ ROXML::XML::Parser.parse(File.read('spec/xml/decl_test.xml')).to_s.should == ROXML::XML::Parser.parse(%{<?xml version="1.1"?>}).to_s
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
data/tasks/rspec.rake ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/**/*_spec.rb']
21
+ end
data/tasks/test.rake ADDED
@@ -0,0 +1,42 @@
1
+ # We need to override hoe's test task in order to support separate REXML & LibXML testing
2
+ require File.join(File.dirname(__FILE__), '../vendor/override_rake_task/lib/override_rake_task')
3
+
4
+ Rake::TestTask.new(:bugs) do |t|
5
+ t.libs << 'test'
6
+ t.test_files = FileList['test/bugs/*_bugs.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ remove_task :test
11
+ desc "Test ROXML using the default parser selection behavior"
12
+ task :test do
13
+ module ROXML
14
+ SILENCE_XML_NAME_WARNING = true
15
+ end
16
+ require 'lib/roxml'
17
+ require 'rake/runtest'
18
+ Rake.run_tests $hoe.test_globs
19
+ end
20
+
21
+ namespace :test do
22
+ desc "Test ROXML under the LibXML parser"
23
+ task :libxml do
24
+ module ROXML
25
+ XML_PARSER = 'libxml'
26
+ end
27
+ Rake::Task["test"].invoke
28
+ end
29
+
30
+ desc "Test ROXML under the REXML parser"
31
+ task :rexml do
32
+ module ROXML
33
+ XML_PARSER = 'rexml'
34
+ end
35
+ Rake::Task["test"].invoke
36
+ end
37
+
38
+ desc "Runs tests under RCOV"
39
+ task :rcov do
40
+ system "rcov -T --no-html -x '^/' #{FileList[$hoe.test_globs]}"
41
+ end
42
+ end
@@ -0,0 +1,15 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class RexmlBugs < ActiveSupport::TestCase
4
+ def test_that_some_illegal_chars_are_parsed_without_complaint
5
+ p "REXML ignores illegal ']]>' brackets in xml content"
6
+ assert_nothing_raised do
7
+ # The right angle bracket (>) may be represented using the string "&gt;", and MUST, for compatibility,
8
+ # be escaped using either "&gt;" or a character reference when it appears in the string "]]>" in content,
9
+ # when that string is not marking the end of a CDATA section.
10
+ # - http://www.w3.org/TR/xml11/#syntax
11
+ xml = "<title>The Big Book of ]]> everything more</title>"
12
+ assert_equal xml, REXML::Document.new(xml).to_s
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ <book isbn="0201710897">
2
+ <title>The PickAxe<title>
3
+ <description><![CDATA[Probably the best Ruby book out there]]></description>
4
+ <author>David Thomas, Andrew Hunt, Dave Thomas</author>
5
+ </book>
@@ -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,5 @@
1
+ <book ISBN="0201710897">
2
+ <title>The PickAxe</title>
3
+ <description><![CDATA[Probably the best Ruby book out there]]></description>
4
+ <author role="primary">David Thomas</author>
5
+ </book>
@@ -0,0 +1,5 @@
1
+ <book ISBN="0201710897">
2
+ <title>The PickAxe</title>
3
+ <description><![CDATA[Probably the best Ruby book out there]]></description>
4
+ <author>David Thomas, Andrew Hunt &amp; Dave Thomas</author>
5
+ <pagecount>357</pagecount></book>
@@ -0,0 +1,7 @@
1
+ <book ISBN="0201710897">
2
+ <title>The PickAxe</title>
3
+ <description><![CDATA[Probably the best Ruby book out there]]></description>
4
+ <author>David Thomas</author>
5
+ <author>Andrew Hunt</author>
6
+ <author>Dave Thomas</author>
7
+ </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,6 @@
1
+ <book ISBN="0201710897">
2
+ <title>The PickAxe</title>
3
+ <description><![CDATA[Probably the best Ruby book out there]]></description>
4
+ <author>David Thomas, Andrew Hunt, Dave Thomas</author>
5
+ <depth units="hundredths-meters">1130</depth>
6
+ </book>
@@ -0,0 +1,4 @@
1
+ <bookwithoctalpages>
2
+ <pages_with_to_xml_proc>0357</pages_with_to_xml_proc>
3
+ <pages_with_type>0357</pages_with_type>
4
+ </bookwithoctalpages>
@@ -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
+ <publisher>
5
+ <name>Pragmatic Bookshelf</name>
6
+ </publisher>
7
+ </book>
@@ -0,0 +1,3 @@
1
+ <book>
2
+ <ids ISBN="0974514055" />
3
+ </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,6 @@
1
+ <dictionary>
2
+ <definitions>
3
+ <quaquaversally>adjective: (of a geological formation) sloping downward from the center in all directions.</quaquaversally>
4
+ <tergiversate>To use evasions or ambiguities; equivocate.</tergiversate>
5
+ </definitions>
6
+ </dictionary>
@@ -0,0 +1,4 @@
1
+ <dictionary>
2
+ <definition word="quaquaversally">adjective: (of a geological formation) sloping downward from the center in all directions.</definition>
3
+ <definition word="tergiversate">To use evasions or ambiguities; equivocate.</definition>
4
+ </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,4 @@
1
+ <dictionary>
2
+ <quaquaversally>adjective: (of a geological formation) sloping downward from the center in all directions.</quaquaversally>
3
+ <tergiversate>To use evasions or ambiguities; equivocate.</tergiversate>
4
+ </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>
@@ -0,0 +1,3 @@
1
+ <muffins>
2
+ <bakers_dozens>3</bakers_dozens>
3
+ </muffins>
@@ -0,0 +1,2 @@
1
+ <person>
2
+ </person>
@@ -0,0 +1 @@
1
+ <node content="Just junk... really" name="Cartwheel" />
@@ -0,0 +1,4 @@
1
+ <node>
2
+ <content>Just junk... really</content>
3
+ <name>Cartwheel</name>
4
+ </node>