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.
- data/History.txt +279 -0
- data/MIT-LICENSE +18 -0
- data/Manifest.txt +103 -0
- data/README.rdoc +158 -0
- data/Rakefile +96 -0
- data/TODO +62 -0
- data/config/website.yml +2 -0
- data/examples/active_record.rb +70 -0
- data/examples/amazon.rb +33 -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/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 +511 -0
- data/lib/roxml/definition.rb +234 -0
- data/lib/roxml/extensions.rb +6 -0
- data/lib/roxml/extensions/array.rb +13 -0
- data/lib/roxml/extensions/array/conversions.rb +12 -0
- data/lib/roxml/extensions/deprecation.rb +33 -0
- data/lib/roxml/extensions/string.rb +6 -0
- data/lib/roxml/extensions/string/conversions.rb +5 -0
- data/lib/roxml/extensions/string/iterators.rb +12 -0
- data/lib/roxml/hash_definition.rb +25 -0
- data/lib/roxml/xml.rb +40 -0
- data/lib/roxml/xml/parsers/libxml.rb +86 -0
- data/lib/roxml/xml/parsers/rexml.rb +84 -0
- data/lib/roxml/xml/references.rb +299 -0
- data/roxml.gemspec +50 -0
- data/spec/definition_spec.rb +490 -0
- data/spec/examples/active_record_spec.rb +40 -0
- data/spec/examples/amazon_spec.rb +53 -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 +33 -0
- data/spec/xml/parser_spec.rb +47 -0
- data/tasks/rspec.rake +21 -0
- data/tasks/test.rake +42 -0
- data/test/bugs/rexml_bugs.rb +15 -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/mocks/dictionaries.rb +57 -0
- data/test/mocks/mocks.rb +279 -0
- data/test/test_helper.rb +45 -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 +76 -0
- data/test/unit/xml_object_test.rb +207 -0
- data/test/unit/xml_required_test.rb +93 -0
- data/test/unit/xml_text_test.rb +71 -0
- data/vendor/override_rake_task/README +30 -0
- data/vendor/override_rake_task/init.rb +1 -0
- data/vendor/override_rake_task/install.rb +46 -0
- data/vendor/override_rake_task/lib/override_rake_task.rb +16 -0
- data/website/index.html +98 -0
- 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
|
data/spec/spec_helper.rb
ADDED
|
@@ -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> < > ' \" & </entities>"
|
|
18
|
+
else
|
|
19
|
+
node.to_s.should == "<entities> < > ' " & </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=""'<>&"/>}
|
|
28
|
+
else
|
|
29
|
+
node.to_s.should == %{<attr_holder entities='"'<>&'/>}
|
|
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 ">", and MUST, for compatibility,
|
|
8
|
+
# be escaped using either ">" 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,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>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<node content="Just junk... really" name="Cartwheel" />
|