roxml 2.5.0 → 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +11 -0
- data/Manifest.txt +2 -0
- data/README.rdoc +31 -16
- data/Rakefile +3 -1
- data/examples/active_record.rb +2 -1
- data/examples/library.rb +40 -0
- data/lib/roxml.rb +2 -2
- data/lib/roxml/xml/parsers/libxml.rb +5 -0
- data/lib/roxml/xml/parsers/rexml.rb +16 -5
- data/lib/roxml/xml/references.rb +2 -2
- data/roxml.gemspec +10 -4
- data/spec/examples/active_record_spec.rb +2 -5
- data/spec/examples/library_spec.rb +41 -0
- data/spec/xml/parser_spec.rb +27 -2
- data/test/test_helper.rb +1 -1
- data/test/unit/xml_namespace_test.rb +1 -0
- metadata +23 -1
data/History.txt
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
== 2.5.1 (March 2, 2009)
|
2
|
+
|
3
|
+
* minor enhancements
|
4
|
+
|
5
|
+
* Add Document#save to REXML support, complete with XMLDecl output
|
6
|
+
|
7
|
+
* bug fixes
|
8
|
+
|
9
|
+
* rexml support has been fixed
|
10
|
+
* the first example in the readme was broken and has been fixed
|
11
|
+
|
1
12
|
== 2.5.0 (February 24, 2009)
|
2
13
|
|
3
14
|
* major enhancements
|
data/Manifest.txt
CHANGED
@@ -9,6 +9,7 @@ examples/active_record.rb
|
|
9
9
|
examples/amazon.rb
|
10
10
|
examples/current_weather.rb
|
11
11
|
examples/dashed_elements.rb
|
12
|
+
examples/library.rb
|
12
13
|
examples/posts.rb
|
13
14
|
examples/twitter.rb
|
14
15
|
examples/xml/active_record.xml
|
@@ -38,6 +39,7 @@ spec/examples/active_record_spec.rb
|
|
38
39
|
spec/examples/amazon_spec.rb
|
39
40
|
spec/examples/current_weather_spec.rb
|
40
41
|
spec/examples/dashed_elements_spec.rb
|
42
|
+
spec/examples/library_spec.rb
|
41
43
|
spec/examples/post_spec.rb
|
42
44
|
spec/examples/twitter_spec.rb
|
43
45
|
spec/roxml_spec.rb
|
data/README.rdoc
CHANGED
@@ -14,36 +14,36 @@ ROXML, you can annotate the Ruby classes as follows:
|
|
14
14
|
class Book
|
15
15
|
include ROXML
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
xml_accessor :isbn, :from => "@ISBN" # attribute with name 'ISBN'
|
18
|
+
xml_accessor :title
|
19
|
+
xml_accessor :description, :cdata => true # text node with cdata protection
|
20
|
+
xml_accessor :author
|
21
21
|
end
|
22
22
|
|
23
23
|
class Library
|
24
24
|
include ROXML
|
25
25
|
|
26
26
|
xml_accessor :name, :from => "NAME", :cdata => true
|
27
|
-
xml_accessor :books, :as => [Book]
|
27
|
+
xml_accessor :books, :as => [Book] # by default roxml searches for books for in <book> child nodes, then, if none are present, in ./books/book children
|
28
28
|
end
|
29
29
|
|
30
30
|
To create a library and put a number of books in it we could run the following code:
|
31
31
|
|
32
|
-
book = Book.new
|
32
|
+
book = Book.new
|
33
33
|
book.isbn = "0201710897"
|
34
34
|
book.title = "The PickAxe"
|
35
35
|
book.description = "Best Ruby book out there!"
|
36
36
|
book.author = "David Thomas, Andrew Hunt, Dave Thomas"
|
37
37
|
|
38
|
-
lib = Library.new
|
38
|
+
lib = Library.new
|
39
39
|
lib.name = "Favorite Books"
|
40
|
-
lib
|
40
|
+
lib.books = [book]
|
41
41
|
|
42
42
|
To save this information to an XML file:
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
doc = ROXML::XML::Document.new
|
45
|
+
doc.root = lib.to_xml
|
46
|
+
doc.save("library.xml")
|
47
47
|
|
48
48
|
To later populate the library object from the XML file:
|
49
49
|
|
@@ -62,11 +62,22 @@ you would add a reference to another ROXML class. For example:
|
|
62
62
|
|
63
63
|
can be mapped using the following code:
|
64
64
|
|
65
|
+
class Publisher
|
66
|
+
include ROXML
|
67
|
+
|
68
|
+
xml_accessor :name
|
69
|
+
|
70
|
+
# other important functionality
|
71
|
+
end
|
72
|
+
|
65
73
|
class BookWithPublisher
|
66
74
|
include ROXML
|
67
75
|
|
68
|
-
xml_name
|
76
|
+
xml_name 'book'
|
69
77
|
xml_reader :publisher, :as => Publisher
|
78
|
+
|
79
|
+
# or, alternatively, if no class is needed to hang functionality on:
|
80
|
+
# xml_reader :publisher, :from => 'name', :in => 'publisher'
|
70
81
|
end
|
71
82
|
|
72
83
|
Note: In the above example, _xml_name_ annotation tells ROXML to set the element
|
@@ -88,10 +99,14 @@ The result of the block above is stored, rather than the actual value parsed fro
|
|
88
99
|
|
89
100
|
== Construction
|
90
101
|
|
91
|
-
Object
|
92
|
-
|
93
|
-
|
94
|
-
|
102
|
+
Object life-cycle is as follows: .from_xml is called with a first argument representing the xml
|
103
|
+
in file, string, or path form, and with optional initialization_args following.
|
104
|
+
|
105
|
+
Firt .new and thus #initialize, is called with those same initialization_args, or no args if none
|
106
|
+
are present. Then the object is populated with the attribute values from xml. Then the
|
107
|
+
#after_parse callback is called, with no arguments.
|
108
|
+
|
109
|
+
In #after_parse you can ensure that your object initialization is complete, including initialization which
|
95
110
|
requires more than one variable in concert.
|
96
111
|
|
97
112
|
E.g.:
|
data/Rakefile
CHANGED
@@ -20,7 +20,9 @@ $hoe = Hoe.new('roxml', ROXML::VERSION) do |p|
|
|
20
20
|
['libxml-ruby', '>= 0.8.6']
|
21
21
|
]
|
22
22
|
p.extra_dev_deps = [
|
23
|
-
['newgem', ">= #{::Newgem::VERSION}"]
|
23
|
+
['newgem', ">= #{::Newgem::VERSION}"],
|
24
|
+
['sqlite3-ruby', '>= 1.2.4' ],
|
25
|
+
['activerecord', '>= 2.2.2' ]
|
24
26
|
]
|
25
27
|
|
26
28
|
p.summary = "Ruby Object to XML mapping library"
|
data/examples/active_record.rb
CHANGED
@@ -3,9 +3,10 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec/spec_helper')
|
|
3
3
|
require 'sqlite3'
|
4
4
|
require 'activerecord'
|
5
5
|
|
6
|
+
DB_PATH = File.join(File.dirname(__FILE__), 'active_record.sqlite3')
|
6
7
|
ActiveRecord::Base.establish_connection(
|
7
8
|
:adapter => 'sqlite3',
|
8
|
-
:database =>
|
9
|
+
:database => DB_PATH
|
9
10
|
)
|
10
11
|
|
11
12
|
class Waypoint < ActiveRecord::Base
|
data/examples/library.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
class Publisher
|
2
|
+
include ROXML
|
3
|
+
|
4
|
+
xml_accessor :name
|
5
|
+
|
6
|
+
def initialize(name = nil)
|
7
|
+
@name = name
|
8
|
+
end
|
9
|
+
|
10
|
+
def ==(other)
|
11
|
+
name == other.name
|
12
|
+
end
|
13
|
+
|
14
|
+
# other important functionality
|
15
|
+
end
|
16
|
+
|
17
|
+
class Novel
|
18
|
+
include ROXML
|
19
|
+
|
20
|
+
xml_accessor :isbn, :from => "@ISBN" # attribute with name 'ISBN'
|
21
|
+
xml_accessor :title
|
22
|
+
xml_accessor :description, :cdata => true # text node with cdata protection
|
23
|
+
xml_accessor :author
|
24
|
+
xml_accessor :publisher, :as => Publisher # singular object reference for illustrative purposes.
|
25
|
+
|
26
|
+
def ==(other)
|
27
|
+
self.class.roxml_attrs.map(&:accessor).all? {|attr| send(attr) == other.send(attr) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Library
|
32
|
+
include ROXML
|
33
|
+
|
34
|
+
xml_accessor :name, :from => "NAME", :cdata => true
|
35
|
+
xml_accessor :novels, :as => [Novel] # by default roxml searches for books for in <novel> children, then, if none are present, in ./novels/novel children
|
36
|
+
|
37
|
+
def ==(other)
|
38
|
+
name == other.name && novels == other.novels
|
39
|
+
end
|
40
|
+
end
|
data/lib/roxml.rb
CHANGED
@@ -8,7 +8,7 @@ require 'uri'
|
|
8
8
|
end
|
9
9
|
|
10
10
|
module ROXML # :nodoc:
|
11
|
-
VERSION = '2.5.
|
11
|
+
VERSION = '2.5.1'
|
12
12
|
|
13
13
|
def self.included(base) # :nodoc:
|
14
14
|
base.extend ClassMethods::Accessors,
|
@@ -79,7 +79,7 @@ module ROXML # :nodoc:
|
|
79
79
|
module Conversions
|
80
80
|
# Returns a LibXML::XML::Node or a REXML::Element representing this object
|
81
81
|
def to_xml(name = nil)
|
82
|
-
returning XML::Node.new(name || self.class.tag_name) do |root|
|
82
|
+
returning XML::Node.new((name || self.class.tag_name).to_s) do |root|
|
83
83
|
self.class.roxml_attrs.each do |attr|
|
84
84
|
ref = attr.to_ref(self)
|
85
85
|
v = ref.to_xml
|
@@ -5,16 +5,20 @@ module ROXML
|
|
5
5
|
Document = REXML::Document
|
6
6
|
Node = REXML::Element
|
7
7
|
|
8
|
+
module Error
|
9
|
+
def self.reset_handler
|
10
|
+
# noop
|
11
|
+
end
|
12
|
+
end
|
13
|
+
[REXML::ParseException, REXML::UndefinedNamespaceException, REXML::Validation::ValidationException].each do |exception|
|
14
|
+
exception.send(:include, Error)
|
15
|
+
end
|
16
|
+
|
8
17
|
class Node
|
9
18
|
class << self
|
10
19
|
def new_cdata(content)
|
11
20
|
REXML::CData.new(content)
|
12
21
|
end
|
13
|
-
|
14
|
-
def new(name)
|
15
|
-
name = name.id2name if name.is_a? Symbol
|
16
|
-
REXML::Element.new(name)
|
17
|
-
end
|
18
22
|
end
|
19
23
|
|
20
24
|
alias_attribute :content, :text
|
@@ -68,6 +72,13 @@ module ROXML
|
|
68
72
|
raise ArgumentError, "Root is already defined" if root
|
69
73
|
add(node)
|
70
74
|
end
|
75
|
+
|
76
|
+
def save(destination, opts = {:formatter => REXML::Formatters::Default.new})
|
77
|
+
self << REXML::XMLDecl.new unless xml_decl != REXML::XMLDecl.default # always output xml declaration
|
78
|
+
File.open(destination, "w") do |f|
|
79
|
+
opts[:formatter].write(self, f)
|
80
|
+
end
|
81
|
+
end
|
71
82
|
end
|
72
83
|
end
|
73
84
|
end
|
data/lib/roxml/xml/references.rb
CHANGED
@@ -89,7 +89,7 @@ module ROXML
|
|
89
89
|
if child = xml.children.find {|c| c.name == wrapper }
|
90
90
|
return child
|
91
91
|
end
|
92
|
-
xml.child_add(XML::Node.new(wrapper))
|
92
|
+
xml.child_add(XML::Node.new(wrapper.to_s))
|
93
93
|
end
|
94
94
|
|
95
95
|
def nodes_in(xml)
|
@@ -192,7 +192,7 @@ module ROXML
|
|
192
192
|
if cdata?
|
193
193
|
dest.child_add(XML::Node.new_cdata(value.to_s.to_utf_without_deprecation))
|
194
194
|
else
|
195
|
-
dest.content =
|
195
|
+
dest.content = value.to_s.to_utf_without_deprecation
|
196
196
|
end
|
197
197
|
end
|
198
198
|
end
|
data/roxml.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{roxml}
|
5
|
-
s.version = "2.5.
|
5
|
+
s.version = "2.5.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Ben Woosley", "Zak Mandhro", "Anders Engstrom", "Russ Olsen"]
|
9
|
-
s.date = %q{2009-02
|
9
|
+
s.date = %q{2009-03-02}
|
10
10
|
s.description = %q{ROXML is a Ruby library designed to make it easier for Ruby developers to work with XML. Using simple annotations, it enables Ruby classes to be mapped to XML. ROXML takes care of the marshalling and unmarshalling of mapped attributes so that developers can focus on building first-class Ruby classes. As a result, ROXML simplifies the development of RESTful applications, Web Services, and XML-RPC.}
|
11
11
|
s.email = %q{ben.woosley@gmail.com}
|
12
12
|
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
|
13
|
-
s.files = ["History.txt", "MIT-LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "TODO", "config/website.yml", "examples/active_record.rb", "examples/amazon.rb", "examples/current_weather.rb", "examples/dashed_elements.rb", "examples/posts.rb", "examples/twitter.rb", "examples/xml/active_record.xml", "examples/xml/amazon.xml", "examples/xml/current_weather.xml", "examples/xml/dashed_elements.xml", "examples/xml/posts.xml", "examples/xml/twitter.xml", "lib/roxml.rb", "lib/roxml/definition.rb", "lib/roxml/extensions.rb", "lib/roxml/extensions/active_support.rb", "lib/roxml/extensions/array.rb", "lib/roxml/extensions/array/conversions.rb", "lib/roxml/extensions/deprecation.rb", "lib/roxml/extensions/string.rb", "lib/roxml/extensions/string/conversions.rb", "lib/roxml/extensions/string/iterators.rb", "lib/roxml/hash_definition.rb", "lib/roxml/xml.rb", "lib/roxml/xml/parsers/libxml.rb", "lib/roxml/xml/parsers/rexml.rb", "lib/roxml/xml/references.rb", "roxml.gemspec", "spec/definition_spec.rb", "spec/examples/active_record_spec.rb", "spec/examples/amazon_spec.rb", "spec/examples/current_weather_spec.rb", "spec/examples/dashed_elements_spec.rb", "spec/examples/post_spec.rb", "spec/examples/twitter_spec.rb", "spec/roxml_spec.rb", "spec/shared_specs.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/string_spec.rb", "spec/xml/parser_spec.rb", "tasks/rspec.rake", "tasks/test.rake", "test/bugs/rexml_bugs.rb", "test/fixtures/book_malformed.xml", "test/fixtures/book_pair.xml", "test/fixtures/book_text_with_attribute.xml", "test/fixtures/book_valid.xml", "test/fixtures/book_with_authors.xml", "test/fixtures/book_with_contributions.xml", "test/fixtures/book_with_contributors.xml", "test/fixtures/book_with_contributors_attrs.xml", "test/fixtures/book_with_default_namespace.xml", "test/fixtures/book_with_depth.xml", "test/fixtures/book_with_octal_pages.xml", "test/fixtures/book_with_publisher.xml", "test/fixtures/book_with_wrapped_attr.xml", "test/fixtures/dictionary_of_attr_name_clashes.xml", "test/fixtures/dictionary_of_attrs.xml", "test/fixtures/dictionary_of_guarded_names.xml", "test/fixtures/dictionary_of_mixeds.xml", "test/fixtures/dictionary_of_name_clashes.xml", "test/fixtures/dictionary_of_names.xml", "test/fixtures/dictionary_of_texts.xml", "test/fixtures/library.xml", "test/fixtures/library_uppercase.xml", "test/fixtures/muffins.xml", "test/fixtures/nameless_ageless_youth.xml", "test/fixtures/node_with_attr_name_conflicts.xml", "test/fixtures/node_with_name_conflicts.xml", "test/fixtures/numerology.xml", "test/fixtures/person.xml", "test/fixtures/person_with_guarded_mothers.xml", "test/fixtures/person_with_mothers.xml", "test/mocks/dictionaries.rb", "test/mocks/mocks.rb", "test/release/dependencies_test.rb", "test/test_helper.rb", "test/unit/definition_test.rb", "test/unit/deprecations_test.rb", "test/unit/to_xml_test.rb", "test/unit/xml_attribute_test.rb", "test/unit/xml_block_test.rb", "test/unit/xml_bool_test.rb", "test/unit/xml_construct_test.rb", "test/unit/xml_convention_test.rb", "test/unit/xml_hash_test.rb", "test/unit/xml_initialize_test.rb", "test/unit/xml_name_test.rb", "test/unit/xml_namespace_test.rb", "test/unit/xml_object_test.rb", "test/unit/xml_required_test.rb", "test/unit/xml_text_test.rb", "vendor/override_rake_task/README", "vendor/override_rake_task/init.rb", "vendor/override_rake_task/install.rb", "vendor/override_rake_task/lib/override_rake_task.rb", "website/index.html"]
|
13
|
+
s.files = ["History.txt", "MIT-LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "TODO", "config/website.yml", "examples/active_record.rb", "examples/amazon.rb", "examples/current_weather.rb", "examples/dashed_elements.rb", "examples/library.rb", "examples/posts.rb", "examples/twitter.rb", "examples/xml/active_record.xml", "examples/xml/amazon.xml", "examples/xml/current_weather.xml", "examples/xml/dashed_elements.xml", "examples/xml/posts.xml", "examples/xml/twitter.xml", "lib/roxml.rb", "lib/roxml/definition.rb", "lib/roxml/extensions.rb", "lib/roxml/extensions/active_support.rb", "lib/roxml/extensions/array.rb", "lib/roxml/extensions/array/conversions.rb", "lib/roxml/extensions/deprecation.rb", "lib/roxml/extensions/string.rb", "lib/roxml/extensions/string/conversions.rb", "lib/roxml/extensions/string/iterators.rb", "lib/roxml/hash_definition.rb", "lib/roxml/xml.rb", "lib/roxml/xml/parsers/libxml.rb", "lib/roxml/xml/parsers/rexml.rb", "lib/roxml/xml/references.rb", "roxml.gemspec", "spec/definition_spec.rb", "spec/examples/active_record_spec.rb", "spec/examples/amazon_spec.rb", "spec/examples/current_weather_spec.rb", "spec/examples/dashed_elements_spec.rb", "spec/examples/library_spec.rb", "spec/examples/post_spec.rb", "spec/examples/twitter_spec.rb", "spec/roxml_spec.rb", "spec/shared_specs.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/string_spec.rb", "spec/xml/parser_spec.rb", "tasks/rspec.rake", "tasks/test.rake", "test/bugs/rexml_bugs.rb", "test/fixtures/book_malformed.xml", "test/fixtures/book_pair.xml", "test/fixtures/book_text_with_attribute.xml", "test/fixtures/book_valid.xml", "test/fixtures/book_with_authors.xml", "test/fixtures/book_with_contributions.xml", "test/fixtures/book_with_contributors.xml", "test/fixtures/book_with_contributors_attrs.xml", "test/fixtures/book_with_default_namespace.xml", "test/fixtures/book_with_depth.xml", "test/fixtures/book_with_octal_pages.xml", "test/fixtures/book_with_publisher.xml", "test/fixtures/book_with_wrapped_attr.xml", "test/fixtures/dictionary_of_attr_name_clashes.xml", "test/fixtures/dictionary_of_attrs.xml", "test/fixtures/dictionary_of_guarded_names.xml", "test/fixtures/dictionary_of_mixeds.xml", "test/fixtures/dictionary_of_name_clashes.xml", "test/fixtures/dictionary_of_names.xml", "test/fixtures/dictionary_of_texts.xml", "test/fixtures/library.xml", "test/fixtures/library_uppercase.xml", "test/fixtures/muffins.xml", "test/fixtures/nameless_ageless_youth.xml", "test/fixtures/node_with_attr_name_conflicts.xml", "test/fixtures/node_with_name_conflicts.xml", "test/fixtures/numerology.xml", "test/fixtures/person.xml", "test/fixtures/person_with_guarded_mothers.xml", "test/fixtures/person_with_mothers.xml", "test/mocks/dictionaries.rb", "test/mocks/mocks.rb", "test/release/dependencies_test.rb", "test/test_helper.rb", "test/unit/definition_test.rb", "test/unit/deprecations_test.rb", "test/unit/to_xml_test.rb", "test/unit/xml_attribute_test.rb", "test/unit/xml_block_test.rb", "test/unit/xml_bool_test.rb", "test/unit/xml_construct_test.rb", "test/unit/xml_convention_test.rb", "test/unit/xml_hash_test.rb", "test/unit/xml_initialize_test.rb", "test/unit/xml_name_test.rb", "test/unit/xml_namespace_test.rb", "test/unit/xml_object_test.rb", "test/unit/xml_required_test.rb", "test/unit/xml_text_test.rb", "vendor/override_rake_task/README", "vendor/override_rake_task/init.rb", "vendor/override_rake_task/install.rb", "vendor/override_rake_task/lib/override_rake_task.rb", "website/index.html"]
|
14
14
|
s.has_rdoc = true
|
15
15
|
s.homepage = %q{http://roxml.rubyforge.org}
|
16
16
|
s.rdoc_options = ["--main", "README.rdoc"]
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.rubyforge_project = %q{roxml}
|
19
19
|
s.rubygems_version = %q{1.3.1}
|
20
20
|
s.summary = %q{Ruby Object to XML mapping library}
|
21
|
-
s.test_files = ["test/unit/
|
21
|
+
s.test_files = ["test/unit/definition_test.rb", "test/unit/deprecations_test.rb", "test/unit/to_xml_test.rb", "test/unit/xml_attribute_test.rb", "test/unit/xml_block_test.rb", "test/unit/xml_bool_test.rb", "test/unit/xml_construct_test.rb", "test/unit/xml_convention_test.rb", "test/unit/xml_hash_test.rb", "test/unit/xml_initialize_test.rb", "test/unit/xml_name_test.rb", "test/unit/xml_namespace_test.rb", "test/unit/xml_object_test.rb", "test/unit/xml_required_test.rb", "test/unit/xml_text_test.rb"]
|
22
22
|
|
23
23
|
if s.respond_to? :specification_version then
|
24
24
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
@@ -28,17 +28,23 @@ Gem::Specification.new do |s|
|
|
28
28
|
s.add_runtime_dependency(%q<activesupport>, [">= 2.1.0"])
|
29
29
|
s.add_runtime_dependency(%q<libxml-ruby>, [">= 0.8.6"])
|
30
30
|
s.add_development_dependency(%q<newgem>, [">= 1.2.3"])
|
31
|
+
s.add_development_dependency(%q<sqlite3-ruby>, [">= 1.2.4"])
|
32
|
+
s.add_development_dependency(%q<activerecord>, [">= 2.2.2"])
|
31
33
|
s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
|
32
34
|
else
|
33
35
|
s.add_dependency(%q<activesupport>, [">= 2.1.0"])
|
34
36
|
s.add_dependency(%q<libxml-ruby>, [">= 0.8.6"])
|
35
37
|
s.add_dependency(%q<newgem>, [">= 1.2.3"])
|
38
|
+
s.add_dependency(%q<sqlite3-ruby>, [">= 1.2.4"])
|
39
|
+
s.add_dependency(%q<activerecord>, [">= 2.2.2"])
|
36
40
|
s.add_dependency(%q<hoe>, [">= 1.8.0"])
|
37
41
|
end
|
38
42
|
else
|
39
43
|
s.add_dependency(%q<activesupport>, [">= 2.1.0"])
|
40
44
|
s.add_dependency(%q<libxml-ruby>, [">= 0.8.6"])
|
41
45
|
s.add_dependency(%q<newgem>, [">= 1.2.3"])
|
46
|
+
s.add_dependency(%q<sqlite3-ruby>, [">= 1.2.4"])
|
47
|
+
s.add_dependency(%q<activerecord>, [">= 2.2.2"])
|
42
48
|
s.add_dependency(%q<hoe>, [">= 1.8.0"])
|
43
49
|
end
|
44
50
|
end
|
@@ -6,11 +6,8 @@ describe ROXML, "under ActiveRecord" do
|
|
6
6
|
@route = Route.from_xml(xml_for('active_record'))
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
if File.exists?(db)
|
12
|
-
FileUtils.rm(db)
|
13
|
-
end
|
9
|
+
before(:all) do
|
10
|
+
FileUtils.rm(DB_PATH) if File.exists?(DB_PATH)
|
14
11
|
end
|
15
12
|
|
16
13
|
it "should be parsed" do
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require example('library')
|
3
|
+
|
4
|
+
describe Library do
|
5
|
+
before :all do
|
6
|
+
book = Novel.new
|
7
|
+
book.isbn = "0201710897"
|
8
|
+
book.title = "The PickAxe"
|
9
|
+
book.description = "Best Ruby book out there!"
|
10
|
+
book.author = "David Thomas, Andrew Hunt, Dave Thomas"
|
11
|
+
book.publisher = Publisher.new('Addison Wesley Longman, Inc.')
|
12
|
+
|
13
|
+
@lib = Library.new
|
14
|
+
@lib.name = "Favorite Books"
|
15
|
+
@lib.novels = [book]
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#to_xml" do
|
19
|
+
it "should contain the expected information" do
|
20
|
+
@lib.to_xml.should == ROXML::XML::Parser.parse(%{<library><NAME><![CDATA[Favorite Books]]></NAME><novel ISBN='0201710897'><title>The PickAxe</title><description><![CDATA[Best Ruby book out there!]]></description><author>David Thomas, Andrew Hunt, Dave Thomas</author><publisher><name>Addison Wesley Longman, Inc.</name></publisher></novel></library>}).root
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when written to a file" do
|
24
|
+
before :all do
|
25
|
+
@doc = ROXML::XML::Document.new
|
26
|
+
@doc.root = @lib.to_xml
|
27
|
+
@doc.save("spec/examples/library.xml")
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should be contain the expected xml" do
|
31
|
+
ROXML::XML::Parser.parse(File.read("spec/examples/library.xml")).to_s.should == ROXML::XML::Parser.parse(%{<?xml version="1.0"?><library><NAME><![CDATA[Favorite Books]]></NAME><novel ISBN='0201710897'><title>The PickAxe</title><description><![CDATA[Best Ruby book out there!]]></description><author>David Thomas, Andrew Hunt, Dave Thomas</author><publisher><name>Addison Wesley Longman, Inc.</name></publisher></novel></library>}).to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should be re-parsable via .from_xml" do
|
35
|
+
File.open("spec/examples/library.xml") do |file|
|
36
|
+
Library.from_xml(file).should == @lib
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/spec/xml/parser_spec.rb
CHANGED
@@ -11,12 +11,37 @@ describe ROXML::XML::Parser do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should escape invalid characters on output to text node" do
|
14
|
-
ROXML::XML::Node.new("entities"
|
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
|
15
21
|
end
|
16
22
|
|
17
23
|
it "should esape invalid characters for attribute name" do
|
18
24
|
node = ROXML::XML::Node.new("attr_holder")
|
19
25
|
node.attributes["entities"] = "\"'<>&"
|
20
|
-
|
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
|
21
46
|
end
|
22
47
|
end
|
data/test/test_helper.rb
CHANGED
@@ -34,6 +34,7 @@ class TestDefaultXMLNamespaces < Test::Unit::TestCase
|
|
34
34
|
assert_equal "Yeah, content", xml.find_first('ns:node', 'ns:http://defaultnamespace.org').content
|
35
35
|
assert_equal nil, xml.find_first('ns:node/subnode', 'ns:http://defaultnamespace.org')
|
36
36
|
assert_equal "Another", xml.find_first('ns:node/ns:subnode', 'ns:http://defaultnamespace.org').content
|
37
|
+
rescue LoadError
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roxml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.5.
|
4
|
+
version: 2.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Woosley
|
@@ -45,6 +45,26 @@ dependencies:
|
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: 1.2.3
|
47
47
|
version:
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: sqlite3-ruby
|
50
|
+
type: :development
|
51
|
+
version_requirement:
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.2.4
|
57
|
+
version:
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: activerecord
|
60
|
+
type: :development
|
61
|
+
version_requirement:
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 2.2.2
|
67
|
+
version:
|
48
68
|
- !ruby/object:Gem::Dependency
|
49
69
|
name: hoe
|
50
70
|
type: :development
|
@@ -77,6 +97,7 @@ files:
|
|
77
97
|
- examples/amazon.rb
|
78
98
|
- examples/current_weather.rb
|
79
99
|
- examples/dashed_elements.rb
|
100
|
+
- examples/library.rb
|
80
101
|
- examples/posts.rb
|
81
102
|
- examples/twitter.rb
|
82
103
|
- examples/xml/active_record.xml
|
@@ -106,6 +127,7 @@ files:
|
|
106
127
|
- spec/examples/amazon_spec.rb
|
107
128
|
- spec/examples/current_weather_spec.rb
|
108
129
|
- spec/examples/dashed_elements_spec.rb
|
130
|
+
- spec/examples/library_spec.rb
|
109
131
|
- spec/examples/post_spec.rb
|
110
132
|
- spec/examples/twitter_spec.rb
|
111
133
|
- spec/roxml_spec.rb
|