xommelier 0.1.11 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/xommelier/atom/feed.rb +1 -1
- data/lib/xommelier/version.rb +1 -1
- data/lib/xommelier/xml/element/serialization.rb +19 -15
- data/lib/xommelier/xml/element/structure.rb +1 -1
- data/spec/fixtures/multi_namespace_feed.atom.xml +2 -2
- data/spec/fixtures/nested_atom.xml +1 -1
- data/spec/fixtures/simple_feed.atom.xml +2 -2
- data/spec/functional/atom_feed_building_spec.rb +5 -0
- data/spec/lib/xommelier_spec.rb +1 -1
- metadata +2 -2
data/lib/xommelier/atom/feed.rb
CHANGED
data/lib/xommelier/version.rb
CHANGED
@@ -63,11 +63,12 @@ module Xommelier
|
|
63
63
|
element_name = options.delete(:element_name) { self.element_name }
|
64
64
|
element_name = element_name.to_s
|
65
65
|
element_name << '_' if %w(text class id).include?(element_name)
|
66
|
+
xmlns = options[:ns] || self.xmlns
|
66
67
|
if options[:builder] # Non-root element
|
67
68
|
builder = options.delete(:builder)
|
68
69
|
attribute_values = {}
|
69
70
|
namespaces = builder.doc.namespaces
|
70
|
-
prefix = builder.doc.namespaces.key(xmlns.uri)[6..-1].presence
|
71
|
+
prefix = options[:prefix] || builder.doc.namespaces.key(xmlns.uri)[6..-1].presence
|
71
72
|
else # Root element
|
72
73
|
builder = Nokogiri::XML::Builder.new(options)
|
73
74
|
attribute_values = children_namespaces.inject({xmlns: xmlns.uri}) do |hash, ns|
|
@@ -83,7 +84,8 @@ module Xommelier
|
|
83
84
|
attributes.each do |name, value|
|
84
85
|
attribute_options = attribute_options(name)
|
85
86
|
attribute_name = attribute_options[:attribute_name]
|
86
|
-
|
87
|
+
ns = attribute_options[:ns]
|
88
|
+
if ns.uri != current_xmlns
|
87
89
|
if ns.as == :xml
|
88
90
|
attribute_name = "xml:#{attribute_options[:attribute_name]}"
|
89
91
|
elsif attr_prefix = namespaces.key(ns.uri).try(:[], 6..-1).presence
|
@@ -94,13 +96,12 @@ module Xommelier
|
|
94
96
|
end
|
95
97
|
@_xml_node = (prefix ? builder[prefix] : builder).
|
96
98
|
send(element_name, attribute_values) do |xml|
|
97
|
-
elements.each do |name,
|
98
|
-
|
99
|
-
|
100
|
-
value,
|
101
|
-
|
102
|
-
|
103
|
-
)
|
99
|
+
self.class.elements.each do |name, element_options|
|
100
|
+
value = elements.fetch(name, options[:default])
|
101
|
+
if value
|
102
|
+
serialize_element(name, value, xml,
|
103
|
+
element_options.merge(overriden_xmlns: xmlns))
|
104
|
+
end
|
104
105
|
end
|
105
106
|
xml.text(@text) if respond_to?(:text)
|
106
107
|
end.instance_variable_get(:@node)
|
@@ -183,19 +184,22 @@ module Xommelier
|
|
183
184
|
end
|
184
185
|
|
185
186
|
def serialize_element(name, value, xml, options = {})
|
186
|
-
prefix = if options[:ns].try(:!=, xmlns)
|
187
|
-
xml.doc.namespaces.key(options[:ns].uri)[6..-1].presence
|
188
|
-
else
|
189
|
-
nil
|
190
|
-
end
|
191
187
|
case options[:count]
|
192
188
|
when :any, :many
|
193
189
|
single_element = options.merge(count: :one)
|
194
190
|
value.each { |item| serialize_element(name, item, xml, single_element) }
|
195
191
|
else
|
192
|
+
xmlns = options[:overriden_xmlns] || self.xmlns
|
193
|
+
prefix = if options[:prefix]
|
194
|
+
options[:prefix]
|
195
|
+
elsif options[:ns].try(:!=, xmlns)
|
196
|
+
xml.doc.namespaces.key(options[:ns].uri)[6..-1].presence
|
197
|
+
else
|
198
|
+
nil
|
199
|
+
end
|
196
200
|
case value
|
197
201
|
when Xommelier::Xml::Element
|
198
|
-
value.to_xommelier(builder: xml, element_name: options[:element_name])
|
202
|
+
value.to_xommelier(builder: xml, element_name: options[:element_name], prefix: prefix, ns: options[:ns])
|
199
203
|
else
|
200
204
|
element_name = options[:element_name].to_s
|
201
205
|
element_name << '_' if %w(text class id).include?(element_name)
|
@@ -2,14 +2,14 @@
|
|
2
2
|
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0">
|
3
3
|
<id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
|
4
4
|
<title>Example Feed</title>
|
5
|
-
<link href="http://example.org/"/>
|
6
5
|
<updated>2003-12-13T18:30:02Z</updated>
|
7
6
|
<author>
|
8
7
|
<name>John Doe</name>
|
9
8
|
</author>
|
9
|
+
<link href="http://example.org/"/>
|
10
10
|
<entry>
|
11
|
-
<title>Atom-Powered Robots Run Amok</title>
|
12
11
|
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
|
12
|
+
<title>Atom-Powered Robots Run Amok</title>
|
13
13
|
<updated>2003-12-13T18:30:02Z</updated>
|
14
14
|
<summary>Some text.</summary>
|
15
15
|
<link href="http://example.org/2003/12/13/atom03"/>
|
@@ -1,12 +1,12 @@
|
|
1
1
|
<?xml version="1.0" encoding="utf-8"?>
|
2
2
|
<feed xmlns="http://www.w3.org/2005/Atom">
|
3
3
|
<title>Xommelier nest elements</title>
|
4
|
+
<updated>2012-04-04T04:04:00Z</updated>
|
4
5
|
<subtitle>Xommelier is able to build complex objects from very nested hash</subtitle>
|
5
6
|
<author>
|
6
7
|
<name>Alexander</name>
|
7
8
|
<email>al@semyonov.us</email>
|
8
9
|
</author>
|
9
|
-
<updated>2012-04-04T04:04:00Z</updated>
|
10
10
|
<contributor>
|
11
11
|
<name>Artyom</name>
|
12
12
|
<email>sevenov@gmail.com</email>
|
@@ -2,14 +2,14 @@
|
|
2
2
|
<feed xmlns="http://www.w3.org/2005/Atom">
|
3
3
|
<id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
|
4
4
|
<title>Example Feed</title>
|
5
|
-
<link href="http://example.org/"/>
|
6
5
|
<updated>2003-12-13T18:30:02Z</updated>
|
7
6
|
<author>
|
8
7
|
<name>John Doe</name>
|
9
8
|
</author>
|
9
|
+
<link href="http://example.org/"/>
|
10
10
|
<entry>
|
11
|
-
<title>Atom-Powered Robots Run Amok</title>
|
12
11
|
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
|
12
|
+
<title>Atom-Powered Robots Run Amok</title>
|
13
13
|
<updated>2003-12-13T18:30:02Z</updated>
|
14
14
|
<summary>Some text.</summary>
|
15
15
|
<link href="http://example.org/2003/12/13/atom03"/>
|
@@ -29,6 +29,11 @@ describe 'Atom feed building' do
|
|
29
29
|
it { feed.should be_valid }
|
30
30
|
|
31
31
|
it { should == load_xml_file('simple_feed.atom').read }
|
32
|
+
it do
|
33
|
+
rng.validate(parsed_xml).each do |error|
|
34
|
+
pp error
|
35
|
+
end
|
36
|
+
end
|
32
37
|
it('should conform to RelaxNG schema') { rng.valid?(parsed_xml).should == true }
|
33
38
|
it('should conform to XML Schema') { xsd.valid?(parsed_xml).should == true }
|
34
39
|
end
|
data/spec/lib/xommelier_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xommelier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.12
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|