ratom 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.3.6 2008-05-15
2
+
3
+ * Added categories to feeds.
4
+ * Make sure atom:content appears at the end of a atom:entry.
5
+ * Don't use namespace prefixes on content unless we really have to.
6
+
1
7
  == 0.3.5 2008-05-03
2
8
 
3
9
  * Make sure atom:entries appears last.
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.get(Atom::NAMESPACE)}:#{name}")
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.get(Atom::NAMESPACE)}:#{name}")
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.get(Atom::NAMESPACE)}:#{name}")
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
@@ -2,7 +2,7 @@ module Atom #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 3
5
- TINY = 5
5
+ TINY = 6
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -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("&nbsp;").to_xml.to_s.should == "<atom:content type=\"html\">&amp;nbsp;</atom:content>"
1124
+ Atom::Content::Html.new("&nbsp;").to_xml.to_s.should == "<content type=\"html\">&amp;nbsp;</content>"
1121
1125
  end
1122
1126
  end
1123
1127
 
@@ -15,6 +15,7 @@
15
15
  <generator uri="http://www.example.com/" version="1.0">
16
16
  Example Toolkit
17
17
  </generator>
18
+ <category term="atom" scheme="http://example.org" label="Atom" />
18
19
  <entry>
19
20
  <title>Atom draft-07 snapshot</title>
20
21
  <link rel="alternate" type="text/html"
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.5
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-03 00:00:00 +09:30
12
+ date: 2008-05-16 00:00:00 +09:30
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency