doxo-roxml 2.5.3

Sign up to get free protection for your applications and to get access to all the features.
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
data/History.txt ADDED
@@ -0,0 +1,279 @@
1
+ == 3.0 ???
2
+
3
+ * major enhancements
4
+
5
+ * Remove previously deprecated functionality
6
+ * Error on any unrecognized options
7
+ * Normalize hash declaration syntax:
8
+ * for :key => '@string', string is taken to be the :from argument
9
+ * for :key => {:from => '@string', :as => Type}, the arguments are just the same as a regular declaration
10
+
11
+ * minor enhancements
12
+
13
+ * Include 't' and 'f' in the list of possible boolean values, since rails uses them
14
+ * Remove :attrs hash syntax. Not particularly helpful & somewhat obfuscatory. Use :key, :value instead.
15
+ * Default attrs ending in '_at' to DateTime. This can be overriden via :as
16
+ * Default attrs ending in '_on' to Date. This can be overriden via :as
17
+
18
+ == 2.5.3 (March 22, 2009)
19
+
20
+ * minor enhancement
21
+
22
+ * Work around apparently unintentional breaking change in libxml-ruby 1.1.3
23
+
24
+ == 2.5.2 (March 12, 2009)
25
+
26
+ * minor enhancements
27
+
28
+ * Remove dependency on an Object#try which conflicted with ActiveSupport 2.3's version
29
+ * Document the :to_xml option for attr references
30
+ * Require active_support directly, as it's less brittle and plays nicer with other libraries
31
+
32
+ == 2.5.1 (March 2, 2009)
33
+
34
+ * minor enhancements
35
+
36
+ * Add Document#save to REXML support, complete with XMLDecl output
37
+
38
+ * bug fixes
39
+
40
+ * rexml support has been fixed
41
+ * the first example in the readme was broken and has been fixed
42
+
43
+ == 2.5.0 (February 24, 2009)
44
+
45
+ * major enhancements
46
+
47
+ * support for mapping ActiveRecord classes. See examples/active_record.rb.
48
+ * .from_xml will now use the setter for the declared variable, if one is available,
49
+ rather than directly setting the instance variable
50
+ * All declaration type arguments are now supported via the :as parameter, e.g. :as => [MyType]. Other uses are deprecated.
51
+ * All xml source path arguments are now supported via the :from and :in parameters, e.g. :from => :attr or :from => '@MyAttr'. Other uses are deprecated.
52
+ * All other options are presented separately, e.g. :cdata => true rather than :as => :cdata. Other uses are deprecated.
53
+
54
+ * minor enhancements
55
+
56
+ * .xml_attr declaration declares neither a reader nor a writer. With it you're left to your own devices.
57
+ * You can use literal [] for the [:text] object type declaration,
58
+ though they should be used in the :as parameter: :as => []
59
+ * You can use [] with your :as declarations. e.g. :as => [Float] is
60
+ equivalent to the old :as => [Float, :array]
61
+ * Show the actual call point of a deprecation, rather than some internal path
62
+ * Add support for BigDecimal and Fixnum as block shorthands [James Healy]
63
+ * Update libxml support to 0.9.6, and add it as a dependency, to ensure correct versioning, and
64
+ as it's an order of magnitude faster than rexml
65
+
66
+ * breaking changes
67
+
68
+ * :else option only applies to instances created via .from_xml
69
+ * On .from_xml, #initialize is now called with the *initialization_args before extracting attributes from the xml.
70
+ * #xml_initialize has been replaced with the #after_parse callback, which takes no arguments.
71
+ * .xml_accessor will overwrite the setter for this variable if it has already been defined. Use .xml_reader or .xml_attr,
72
+ or define your writer later, if this is not the behavior you want.
73
+
74
+ * deprecations
75
+
76
+ * Use :cdata => true rather than :as => :cdata
77
+ * Use literal [] around your regular object type, rather than :as => :array
78
+ * Use :from => :content rather than the :content object declaration type
79
+ * Specifying an unknown symbol or Class for :as will raise in 3.0
80
+ * Specifying :as with anything other than a type argument e.g. :bool, Float, [Date],
81
+ will not be supported in 3.0
82
+ * Use :from => :attr or :from => '@attribute_name' rather than the :attr
83
+ object declaration type
84
+ * Passing any type declaration outside the :as parameter is deprecated
85
+ * In 3.0, attributes ending in _on and _at will default to :as => Date and DateTime, respectively,
86
+ rather than :text
87
+ * Deprecated hash :attrs declaration syntax in favor of {:key => '@attr1', :value => '@attr2'}
88
+ * Deprecated hash {Type => 'name'} declaration syntax in favor of {:as => Type, :from => 'name}
89
+ * Deprecated String#to_utf and #to_latin.
90
+
91
+ * bug fixes
92
+
93
+ * xml_accessor now properly handles punctuation, such that the writer appears without '?' for boolean attributes
94
+ * text node contents are no longer truncated when '&' are present in the contents
95
+ * When using :as => Integer or Float, don't raise on missing element [James Healy]
96
+
97
+ == 2.4.3 (February 1, 2009)
98
+
99
+ * 1 bug fix
100
+
101
+ * Fix roxml to work in ruby 1.8.6, which has been broken since the removal of
102
+ extensions in version 2.4.1. Thanks Pat! [Pat Nakajima]
103
+
104
+ == 2.4.2 (January 31, 2009)
105
+
106
+ * 1 major enhancement
107
+
108
+ * xml_namespace for declaring Class-level, inheritable default namespaces.
109
+
110
+ * 4 minor enhancements
111
+
112
+ * add :as => Time, DateTime, and Date support
113
+ * support Pathname, IO and URI objects as #from_xml arguments
114
+ * :as => :bool now supports all capitalizations of 'true', 'false', 'yes', 'no', as well as '1' and '0'
115
+ * For basic types (:as => Integer, Float, Date, &c.), interpret empty strings just
116
+ as missing elements (by returning nil), rather than raising. Raise behavior can be
117
+ accessed by supplying your own block or using the :required option.
118
+
119
+ * 3 bug fixes
120
+
121
+ * Arrays of attrs or elements :as => :bool weren't previously supported. An oversight.
122
+ * Don't apply xml_convention if name is explicitly set
123
+ * Protect xpath operators : and / from modification via String#camelcase & such
124
+
125
+ == 2.4.1 (January 28, 2009)
126
+
127
+ * 3 minor enhancements
128
+
129
+ * remove dependency on 'extensions' gem, as we weren't using it much and it
130
+ was causing problems for some
131
+ * deprecate the 'xml' declaration in favor of the more explicit 'xml_reference'
132
+ declaration. Reorder params to make for cleaner 3.0 transition.
133
+ * deprecate '#tag_name' in favor of 'self.class.tag_name', as it's a class-specific value
134
+
135
+ == 2.4.0 (January 15, 2009)
136
+
137
+ * 1 major enhancement
138
+
139
+ * Add xml_convention to enable easy defaulting to common naming formats, such as camel-case and
140
+ underscored [Ben Woosley]
141
+
142
+ * 6 minor enhancements
143
+
144
+ * Add :frozen option for freezing values on parse [Ben Woosley]
145
+ * Attempt to minimize node creation by better matching wrappers [Ben Woosley]
146
+ * Preserve hash values where a single key maps to multiple values, return them as an array rather
147
+ any single one of them at random (as in group_by rather than index_by) [Ben Woosley]
148
+ * Deprecate #xml_name? as it's only used for triggering the xml_name warning [Ben Woosley]
149
+ * REXML parser ignores whitespace, which doesn't matter to us anyway [Ben Woosley]
150
+ * xml_name is inherited by default [Ben Woosley]
151
+
152
+ * 2 bug fixes
153
+
154
+ * Don't detect objects which define their own empty? as being absent for the purposes
155
+ of :default and :required [Ben Woosley]
156
+ * Sub-objects pick up their parent's attributes, even if they're added after
157
+ the child's use [Ben Woosley]
158
+
159
+ == 2.3.2 (December 11, 2008)
160
+
161
+ * Fix that both false and nil values were excluded from to_xml output, when only nil values should be [Ben Woosley]
162
+
163
+ == 2.3.1 (December 9, 2008)
164
+
165
+ * Add missing dependencies to extensions/enumerable and Symbol.to_proc,
166
+ which are as-yet inexplicably pre-included on my system... [Ben Woosley, Per Melin]
167
+
168
+ == 2.3 (December 7, 2008)
169
+
170
+ * Fix a bug in the application of blocks to array types [Ben Woosley]
171
+
172
+ * Objects now inherit xml attributes from their parents, as they should [Ben Woosley, Per Melin]
173
+
174
+ * Add #xml_initialize, which is called at the end of #from_xml, after the xml attributes
175
+ are set. Deprecate the half-baked xml_construct in it's favor. [Ben Woosley]
176
+
177
+ * Fix a bug in the handling of empty Hash types [Ben Woosley]
178
+
179
+ * Implement automatic bool-ification when the accessor name ends with ?. [Ben Woosley]
180
+
181
+ * Add missing dependency ActiveSupport [Ben Woosley]
182
+
183
+ * Remove support for installing as a rails plugin [Ben Woosley]
184
+
185
+ * Fix a bug where xml_construct was using the refs' names rather than their accessor names for comparison [Ben Woosley]
186
+
187
+ * Significantly reduce our footprint by selectively including smaller parts of ActiveSupport and Extensions.
188
+ This avoids problems such as the conflict between ActiveSupport's #to_json and the JSON gem's #to_json.
189
+ Thanks to Per Melin for reporting this problem. [Ben Woosley]
190
+
191
+ * Rationalize sub-element xml naming by enforcing the following precedence for the containing xml of an object:
192
+ :from of parent, xml_name of child, parent's accessor name. The previous fallback did not include xml_name.
193
+ This new behavior is more consistent, explicit, predictable, and DRY, but it is a breaking change, so a warning
194
+ is printed to alert others of this behavior change. ROXML::SILENCE_XML_NAME_WARNING may be used to deactivate this
195
+ warning. [Ben Woosley, James W. Thompson, Delynn Berry]
196
+
197
+ == 2.2 (November 2, 2008)
198
+
199
+ * fix gem dependencies [James Healy]
200
+
201
+ * Add block shorthands for Float and Integer, which precede the block argume if present [Ben Woosley]
202
+
203
+ * Add :required option to throw on absence [Ben Woosley]
204
+
205
+ * Deprecate the non-specific #parse in favor of #from_xml [Ben Woosley]
206
+
207
+ * Fix a bug whereby the default value was carrying over information from one object to another [James Healy, Ben Woosley]
208
+
209
+ * Fix support for :in on :attr elements [Ben Woosley]
210
+
211
+ * Deprecate Array#to_h in favor of Array#to_hash [Ben Woosley]
212
+
213
+ * Deprecate Object#to_latin and Object#to_utf in favor of the same methods on String [Ben Woosley]
214
+
215
+ == 2.1 (October 3, 2008)
216
+
217
+ * rake test now uses the default parser selection [Ben Woosley]
218
+
219
+ * Added rcov code coverage for tests [Anders Engström]
220
+
221
+ * Accommodate that libxml requires you to name the default namespace when available [Ben Woosley]
222
+
223
+ * Enable optional selection of a parser through the early definition of ROXML::XML_PARSER
224
+ [Ben Woosley]
225
+
226
+ * Enable fallback to the REXML parser if LibXML is unavailable [Ben Woosley]
227
+
228
+ == 2.0 (September 20, 2008)
229
+
230
+ * :text_content becomes simply :content, and is joined by :name [Ben Woosley]
231
+
232
+ * Allow hash mapping from node names and contents: [Ben Woosley]
233
+
234
+ xml_reader :name, {:key => :name,
235
+ :value => :content}, :in => 'container'
236
+
237
+ * Allow supplying a default via the :else option [Ben Woosley]
238
+
239
+ * Allow hash mapping of text and attr elements: [Ben Woosley]
240
+
241
+ xml_reader :name, {:key => {:text => 'key_name'},
242
+ :value => {:attr => 'attr_name'}}, :in => 'container'
243
+
244
+ * Allow 'xml_reader :name, [Type]' as an alternative to 'xml_reader :name, Type, :as => :array'
245
+ [Ben Woosley]
246
+
247
+ * Allow attaching a block for manipulating a value on fetch: [Ben Woosley]
248
+
249
+ xml_accessor :count, :attr => 'my_int' do |val|
250
+ Integer(val)
251
+ end
252
+
253
+ * Collapse xml_attr, xml_text and xml_object into a single api: xml, patterned after the standard
254
+ attr, and offer xml_reader and xml_accessor as well. Remove the :readonly arg in the process
255
+ [Ben Woosley]
256
+
257
+ * Attach string extensions (#to_latin, #to_utf) to Object rather than String, so we don't have to
258
+ call #to_s first every time [Ben Woosley]
259
+
260
+ * Allow a ROXML object to call its constructor on initialization with the xml_construct function
261
+ [Ben Woosley]
262
+
263
+ * Use symbols (e.g. :text_content) rather than TAG_CONSTANTS (e.g. TEXT_CONTENT) for readability
264
+ [Ben Woosley]
265
+
266
+ * Use named arguments (e.g. :as, :in) rather than positional for clarity,
267
+ position-independence, and invisible exclusion [Ben Woosley]
268
+
269
+ * Split out rails_plugin_package_task_gem [Ben Woosley]
270
+
271
+ * Increase testing significantly, particularly on new functionality & to_xml [Ben Woosley]
272
+
273
+ == 1.2 (October 10, 2007)
274
+
275
+ * Fix a bug such that the TEXT_CONTENT tag is no longer also READ_ONLY [Russ Olsen]
276
+
277
+ == 1.1 (September 24, 2006)
278
+
279
+ * Initial design & development [Zak Mandhro & Anders Engstrom]
data/MIT-LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2004-2009 by Ben Woosley, Zak Mandhro and Anders Engstrom
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software
6
+ and associated documentation files (the "Software"), to deal in the Software without restriction,
7
+ including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
+ and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
9
+ subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or substantial
12
+ portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15
+ LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
16
+ EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
18
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest.txt ADDED
@@ -0,0 +1,103 @@
1
+ History.txt
2
+ MIT-LICENSE
3
+ Manifest.txt
4
+ README.rdoc
5
+ Rakefile
6
+ TODO
7
+ config/website.yml
8
+ examples/active_record.rb
9
+ examples/amazon.rb
10
+ examples/current_weather.rb
11
+ examples/dashed_elements.rb
12
+ examples/library.rb
13
+ examples/posts.rb
14
+ examples/twitter.rb
15
+ examples/xml/active_record.xml
16
+ examples/xml/amazon.xml
17
+ examples/xml/current_weather.xml
18
+ examples/xml/dashed_elements.xml
19
+ examples/xml/posts.xml
20
+ examples/xml/twitter.xml
21
+ lib/roxml.rb
22
+ lib/roxml/definition.rb
23
+ lib/roxml/extensions.rb
24
+ lib/roxml/extensions/array.rb
25
+ lib/roxml/extensions/array/conversions.rb
26
+ lib/roxml/extensions/deprecation.rb
27
+ lib/roxml/extensions/string.rb
28
+ lib/roxml/extensions/string/conversions.rb
29
+ lib/roxml/extensions/string/iterators.rb
30
+ lib/roxml/hash_definition.rb
31
+ lib/roxml/xml.rb
32
+ lib/roxml/xml/parsers/libxml.rb
33
+ lib/roxml/xml/parsers/rexml.rb
34
+ lib/roxml/xml/references.rb
35
+ roxml.gemspec
36
+ spec/definition_spec.rb
37
+ spec/examples/active_record_spec.rb
38
+ spec/examples/amazon_spec.rb
39
+ spec/examples/current_weather_spec.rb
40
+ spec/examples/dashed_elements_spec.rb
41
+ spec/examples/library_spec.rb
42
+ spec/examples/post_spec.rb
43
+ spec/examples/twitter_spec.rb
44
+ spec/roxml_spec.rb
45
+ spec/shared_specs.rb
46
+ spec/spec.opts
47
+ spec/spec_helper.rb
48
+ spec/xml/parser_spec.rb
49
+ tasks/rspec.rake
50
+ tasks/test.rake
51
+ test/bugs/rexml_bugs.rb
52
+ test/fixtures/book_malformed.xml
53
+ test/fixtures/book_pair.xml
54
+ test/fixtures/book_text_with_attribute.xml
55
+ test/fixtures/book_valid.xml
56
+ test/fixtures/book_with_authors.xml
57
+ test/fixtures/book_with_contributions.xml
58
+ test/fixtures/book_with_contributors.xml
59
+ test/fixtures/book_with_contributors_attrs.xml
60
+ test/fixtures/book_with_default_namespace.xml
61
+ test/fixtures/book_with_depth.xml
62
+ test/fixtures/book_with_octal_pages.xml
63
+ test/fixtures/book_with_publisher.xml
64
+ test/fixtures/book_with_wrapped_attr.xml
65
+ test/fixtures/dictionary_of_attr_name_clashes.xml
66
+ test/fixtures/dictionary_of_attrs.xml
67
+ test/fixtures/dictionary_of_guarded_names.xml
68
+ test/fixtures/dictionary_of_mixeds.xml
69
+ test/fixtures/dictionary_of_name_clashes.xml
70
+ test/fixtures/dictionary_of_names.xml
71
+ test/fixtures/dictionary_of_texts.xml
72
+ test/fixtures/library.xml
73
+ test/fixtures/library_uppercase.xml
74
+ test/fixtures/muffins.xml
75
+ test/fixtures/nameless_ageless_youth.xml
76
+ test/fixtures/node_with_attr_name_conflicts.xml
77
+ test/fixtures/node_with_name_conflicts.xml
78
+ test/fixtures/numerology.xml
79
+ test/fixtures/person.xml
80
+ test/fixtures/person_with_guarded_mothers.xml
81
+ test/fixtures/person_with_mothers.xml
82
+ test/mocks/dictionaries.rb
83
+ test/mocks/mocks.rb
84
+ test/test_helper.rb
85
+ test/unit/definition_test.rb
86
+ test/unit/deprecations_test.rb
87
+ test/unit/to_xml_test.rb
88
+ test/unit/xml_attribute_test.rb
89
+ test/unit/xml_block_test.rb
90
+ test/unit/xml_bool_test.rb
91
+ test/unit/xml_convention_test.rb
92
+ test/unit/xml_hash_test.rb
93
+ test/unit/xml_initialize_test.rb
94
+ test/unit/xml_name_test.rb
95
+ test/unit/xml_namespace_test.rb
96
+ test/unit/xml_object_test.rb
97
+ test/unit/xml_required_test.rb
98
+ test/unit/xml_text_test.rb
99
+ vendor/override_rake_task/README
100
+ vendor/override_rake_task/init.rb
101
+ vendor/override_rake_task/install.rb
102
+ vendor/override_rake_task/lib/override_rake_task.rb
103
+ website/index.html
data/README.rdoc ADDED
@@ -0,0 +1,158 @@
1
+ ROXML Ruby Object to XML mapping library.
2
+
3
+ For more information visit:
4
+
5
+ http://roxml.rubyforge.org/rdoc/
6
+ http://empact.github.com/roxml/
7
+ http://rubyforge.org/projects/roxml/
8
+
9
+ Progress on this project is (more or less) tracked at:
10
+
11
+ http://www.pivotaltracker.com/project/4109
12
+
13
+
14
+ =Quick Start Guide
15
+
16
+ This is a short usage example. See ROXML::ClassMethods::Declarations and packaged test cases for more information.
17
+
18
+ ==Basic Mapping
19
+
20
+ Consider an XML document representing a Library containing a number of Books. You
21
+ can map this structure to Ruby classes that provide addition useful behavior. With
22
+ ROXML, you can annotate the Ruby classes as follows:
23
+
24
+ class Book
25
+ include ROXML
26
+
27
+ xml_accessor :isbn, :from => "@ISBN" # attribute with name 'ISBN'
28
+ xml_accessor :title
29
+ xml_accessor :description, :cdata => true # text node with cdata protection
30
+ xml_accessor :author
31
+ end
32
+
33
+ class Library
34
+ include ROXML
35
+
36
+ xml_accessor :name, :from => "NAME", :cdata => true
37
+ 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
38
+ end
39
+
40
+ To create a library and put a number of books in it we could run the following code:
41
+
42
+ book = Book.new
43
+ book.isbn = "0201710897"
44
+ book.title = "The PickAxe"
45
+ book.description = "Best Ruby book out there!"
46
+ book.author = "David Thomas, Andrew Hunt, Dave Thomas"
47
+
48
+ lib = Library.new
49
+ lib.name = "Favorite Books"
50
+ lib.books = [book]
51
+
52
+ To save this information to an XML file:
53
+
54
+ doc = ROXML::XML::Document.new
55
+ doc.root = lib.to_xml
56
+ doc.save("library.xml")
57
+
58
+ To later populate the library object from the XML file:
59
+
60
+ lib = Library.from_xml(File.read("library.xml"))
61
+
62
+ Similarly, to do a one-to-one mapping between XML objects, such as book and publisher,
63
+ you would add a reference to another ROXML class. For example:
64
+
65
+ <book isbn="0974514055">
66
+ <title>Programming Ruby - 2nd Edition</title>
67
+ <description>Second edition of the great book.</description>
68
+ <publisher>
69
+ <name>Pragmatic Bookshelf</name>
70
+ </publisher>
71
+ </book>
72
+
73
+ can be mapped using the following code:
74
+
75
+ class Publisher
76
+ include ROXML
77
+
78
+ xml_accessor :name
79
+
80
+ # other important functionality
81
+ end
82
+
83
+ class BookWithPublisher
84
+ include ROXML
85
+
86
+ xml_name 'book'
87
+ xml_reader :publisher, :as => Publisher
88
+
89
+ # or, alternatively, if no class is needed to hang functionality on:
90
+ # xml_reader :publisher, :from => 'name', :in => 'publisher'
91
+ end
92
+
93
+ Note: In the above example, _xml_name_ annotation tells ROXML to set the element
94
+ name to "book" for mapping to XML. The default is XML element name is the class name in lowercase; "bookwithpublisher"
95
+ in this case.
96
+
97
+ == Manipulation
98
+
99
+ Extending the above examples, say you want to parse a book's page count and have it available as an Integer.
100
+ In such a case, you can extend any object with a block to manipulate it's value at parse time. For example:
101
+
102
+ class Dog
103
+ include ROXML
104
+
105
+ xml_reader(:age, :from => '@human_years', :as => Integer) {|years| years * 7 }
106
+ end
107
+
108
+ The result of the block above is stored, rather than the actual value parsed from the document.
109
+
110
+ == Construction
111
+
112
+ Object life-cycle is as follows: .from_xml is called with a first argument representing the xml
113
+ in file, string, or path form, and with optional initialization_args following.
114
+
115
+ Firt .new and thus #initialize, is called with those same initialization_args, or no args if none
116
+ are present. Then the object is populated with the attribute values from xml. Then the
117
+ #after_parse callback is called, with no arguments.
118
+
119
+ In #after_parse you can ensure that your object initialization is complete, including initialization which
120
+ requires more than one variable in concert.
121
+
122
+ E.g.:
123
+
124
+ class Measurement
125
+ include ROXML
126
+
127
+ xml_reader :units, :from => :attr
128
+ xml_reader :value, :from => :content
129
+
130
+ def initialize(value = 0, units = 'meters')
131
+ to_metric
132
+ end
133
+
134
+ private
135
+ def after_parse
136
+ # xml attributes of self are already valid
137
+ to_metric
138
+ end
139
+
140
+ def to_metric
141
+ # translate units & value into metric, for example
142
+ end
143
+ end
144
+
145
+ One important use of this approach is to make ROXML object which may or may not include an xml backing,
146
+ which may be used via _new_ construction as well as _from_xml_ construction.
147
+
148
+ == Selecting a parser
149
+
150
+ By default, ROXML will use LibXML if it is available, or otherwise REXML. If you'd like to
151
+ explicitly require one or the other, you may do the following:
152
+
153
+ module ROXML
154
+ XML_PARSER = 'libxml' # or 'rexml'
155
+ end
156
+ require 'roxml'
157
+
158
+ For more information on available annotations, see ROXML::ClassMethods::Declarations