ratom 0.3.5 → 0.3.6
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 +6 -0
- data/lib/atom.rb +7 -5
- data/lib/atom/version.rb +1 -1
- data/lib/atom/xml/parser.rb +15 -2
- data/spec/atom_spec.rb +5 -1
- data/spec/fixtures/complex_single_entry.atom +1 -0
- metadata +2 -2
data/History.txt
CHANGED
data/lib/atom.rb
CHANGED
|
@@ -188,7 +188,7 @@ module Atom # :nodoc:
|
|
|
188
188
|
end
|
|
189
189
|
|
|
190
190
|
def to_xml(nodeonly = true, name = 'content', namespace = nil, namespace_map = Atom::Xml::NamespaceMap.new)
|
|
191
|
-
node = XML::Node.new("#{namespace_map.
|
|
191
|
+
node = XML::Node.new("#{namespace_map.prefix(Atom::NAMESPACE, name)}")
|
|
192
192
|
node << self.to_s
|
|
193
193
|
node
|
|
194
194
|
end
|
|
@@ -222,7 +222,7 @@ module Atom # :nodoc:
|
|
|
222
222
|
# to try and recitfy the situation.
|
|
223
223
|
#
|
|
224
224
|
begin
|
|
225
|
-
node = XML::Node.new("#{namespace_map.
|
|
225
|
+
node = XML::Node.new("#{namespace_map.prefix(Atom::NAMESPACE, name)}")
|
|
226
226
|
node << Iconv.iconv('utf-8', 'utf-8', self.to_s, namespace_map = nil)
|
|
227
227
|
node['type'] = 'html'
|
|
228
228
|
node['xml:lang'] = self.xml_lang
|
|
@@ -257,7 +257,7 @@ module Atom # :nodoc:
|
|
|
257
257
|
end
|
|
258
258
|
|
|
259
259
|
def to_xml(nodeonly = true, name = 'content', namespace = nil, namespace_map = Atom::Xml::NamespaceMap.new)
|
|
260
|
-
node = XML::Node.new("#{namespace_map.
|
|
260
|
+
node = XML::Node.new("#{namespace_map.prefix(Atom::NAMESPACE, name)}")
|
|
261
261
|
node['type'] = 'xhtml'
|
|
262
262
|
node['xml:lang'] = self.xml_lang
|
|
263
263
|
|
|
@@ -342,6 +342,7 @@ module Atom # :nodoc:
|
|
|
342
342
|
# +authors+:: An array of Atom::Person objects that are authors of this feed.
|
|
343
343
|
# +contributors+:: An array of Atom::Person objects that are contributors to this feed.
|
|
344
344
|
# +generator+:: A Atom::Generator.
|
|
345
|
+
# +categories+:: A list of Atom:Category objects for the feed.
|
|
345
346
|
# +rights+:: A string describing the rights associated with this feed.
|
|
346
347
|
# +entries+:: An array of Atom::Entry objects.
|
|
347
348
|
# +links+:: An array of Atom:Link objects. (This is actually an Atom::Links array which is an Array with some sugar).
|
|
@@ -364,6 +365,7 @@ module Atom # :nodoc:
|
|
|
364
365
|
element :updated, :class => Time, :content_only => true
|
|
365
366
|
elements :links
|
|
366
367
|
elements :authors, :contributors, :class => Person
|
|
368
|
+
elements :categories
|
|
367
369
|
elements :entries
|
|
368
370
|
|
|
369
371
|
# Initialize a Feed.
|
|
@@ -377,7 +379,7 @@ module Atom # :nodoc:
|
|
|
377
379
|
# +o+:: An XML Reader or a Hash of attributes.
|
|
378
380
|
#
|
|
379
381
|
def initialize(o = {})
|
|
380
|
-
@links, @entries, @authors, @contributors = Links.new, [], [], []
|
|
382
|
+
@links, @entries, @authors, @contributors, @categories = Links.new, [], [], [], []
|
|
381
383
|
|
|
382
384
|
case o
|
|
383
385
|
when XML::Reader
|
|
@@ -498,11 +500,11 @@ module Atom # :nodoc:
|
|
|
498
500
|
namespace Atom::NAMESPACE
|
|
499
501
|
element :title, :id, :summary
|
|
500
502
|
element :updated, :published, :class => Time, :content_only => true
|
|
501
|
-
element :content, :class => Content
|
|
502
503
|
element :source, :class => Source
|
|
503
504
|
elements :links
|
|
504
505
|
elements :authors, :contributors, :class => Person
|
|
505
506
|
elements :categories, :class => Category
|
|
507
|
+
element :content, :class => Content
|
|
506
508
|
|
|
507
509
|
# Initialize an Entry.
|
|
508
510
|
#
|
data/lib/atom/version.rb
CHANGED
data/lib/atom/xml/parser.rb
CHANGED
|
@@ -32,11 +32,20 @@ end
|
|
|
32
32
|
module Atom
|
|
33
33
|
module Xml # :nodoc:
|
|
34
34
|
class NamespaceMap
|
|
35
|
-
def initialize
|
|
35
|
+
def initialize(default = Atom::NAMESPACE)
|
|
36
|
+
@default = default
|
|
36
37
|
@i = 0
|
|
37
38
|
@map = {}
|
|
38
39
|
end
|
|
39
40
|
|
|
41
|
+
def prefix(ns, element)
|
|
42
|
+
if ns == @default
|
|
43
|
+
element
|
|
44
|
+
else
|
|
45
|
+
"#{get(ns)}:#{element}"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
40
49
|
def get(ns)
|
|
41
50
|
if ns == Atom::NAMESPACE
|
|
42
51
|
@map[ns] = "atom"
|
|
@@ -111,8 +120,12 @@ module Atom
|
|
|
111
120
|
end
|
|
112
121
|
end
|
|
113
122
|
|
|
123
|
+
# There doesn't seem to be a way to set namespaces using libxml-ruby,
|
|
124
|
+
# so ratom has to manage namespace to URI prefixing itself, which
|
|
125
|
+
# makes this method more complicated that it needs to be.
|
|
126
|
+
#
|
|
114
127
|
def to_xml(nodeonly = false, root_name = self.class.name.demodulize.downcase, namespace = nil, namespace_map = nil)
|
|
115
|
-
namespace_map = NamespaceMap.new if namespace_map.nil?
|
|
128
|
+
namespace_map = NamespaceMap.new(self.class.namespace) if namespace_map.nil?
|
|
116
129
|
node = XML::Node.new(root_name)
|
|
117
130
|
node['xmlns'] = self.class.namespace unless nodeonly || !self.class.respond_to?(:namespace)
|
|
118
131
|
|
data/spec/atom_spec.rb
CHANGED
|
@@ -228,6 +228,10 @@ describe Atom do
|
|
|
228
228
|
it "should have an entry" do
|
|
229
229
|
@feed.should have(1).entries
|
|
230
230
|
end
|
|
231
|
+
|
|
232
|
+
it "should have a category" do
|
|
233
|
+
@feed.should have(1).categories
|
|
234
|
+
end
|
|
231
235
|
end
|
|
232
236
|
|
|
233
237
|
describe Atom::Entry do
|
|
@@ -1117,7 +1121,7 @@ describe Atom do
|
|
|
1117
1121
|
|
|
1118
1122
|
describe Atom::Content::Html do
|
|
1119
1123
|
it "should escape ampersands in entities" do
|
|
1120
|
-
Atom::Content::Html.new(" ").to_xml.to_s.should == "<
|
|
1124
|
+
Atom::Content::Html.new(" ").to_xml.to_s.should == "<content type=\"html\">&nbsp;</content>"
|
|
1121
1125
|
end
|
|
1122
1126
|
end
|
|
1123
1127
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ratom
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Peerworks
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2008-05-
|
|
12
|
+
date: 2008-05-16 00:00:00 +09:30
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|