ratom 0.3.4 → 0.3.5

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 CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.3.5 2008-05-03
2
+
3
+ * Make sure atom:entries appears last.
4
+ * Better examples in the documentation. Docs for Feed and Entry list attributes.
5
+ * Gave Feeds authors and contributors.
6
+ * Fixed a couple warnings.
7
+
1
8
  == 0.3.4 2008-04-21
2
9
 
3
10
  * Remove useless variable warning. (Sam Roberts)
data/README.txt CHANGED
@@ -46,23 +46,67 @@ And then iterate over the entries in the feed using:
46
46
  # do cool stuff
47
47
  end
48
48
 
49
- To construct a Feed
49
+ To construct the following example Feed is from the Atom spec:
50
50
 
51
- feed = Atom::Feed.new do |feed|
52
- feed.title = "My Cool Feed"
53
- feed.id = "http://example.com/my_feed.atom"
54
- feed.updated = Time.now
51
+ <?xml version="1.0" encoding="utf-8"?>
52
+ <feed xmlns="http://www.w3.org/2005/Atom">
53
+
54
+ <title>Example Feed</title>
55
+ <link href="http://example.org/"/>
56
+ <updated>2003-12-13T18:30:02Z</updated>
57
+ <author>
58
+ <name>John Doe</name>
59
+ </author>
60
+ <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
61
+
62
+ <entry>
63
+ <title>Atom-Powered Robots Run Amok</title>
64
+ <link href="http://example.org/2003/12/13/atom03"/>
65
+ <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
66
+ <updated>2003-12-13T18:30:02Z</updated>
67
+ <summary>Some text.</summary>
68
+ </entry>
69
+
70
+ </feed>
71
+
72
+ To build this in rAtom we would do:
73
+
74
+ feed = Atom::Feed.new do |f|
75
+ f.title = "Example Feed"
76
+ f.links << Atom::Link.new(:href => "http://example.org/")
77
+ f.updated = Time.parse('2003-12-13T18:30:02Z')
78
+ f.authors << Atom::Person.new(:name => 'John Doe')
79
+ f.id = "urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6"
80
+ f.entries << Atom::Entry.new do |e|
81
+ e.title = "Atom-Powered Robots Run Amok"
82
+ e.links << Atom::Link.new(:href => "http://example.org/2003/12/13/atom03")
83
+ e.id = "urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a"
84
+ e.updated = Time.parse('2003-12-13T18:30:02Z')
85
+ e.summary = "Some text."
86
+ end
55
87
  end
56
88
 
57
- To output a Feed as XML use to_xml
89
+ To output the Feed as XML use to_xml
58
90
 
59
91
  > puts feed.to_xml
60
92
  <?xml version="1.0"?>
61
93
  <feed xmlns="http://www.w3.org/2005/Atom">
62
- <title>My Cool Feed</title>
63
- <id>http://example.com/my_feed.atom</id>
64
- <updated>2008-03-03T23:19:44+10:30</updated>
94
+ <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
95
+ <title>Example Feed</title>
96
+ <updated>2003-12-13T18:30:02Z</updated>
97
+ <link href="http://example.org/"/>
98
+ <author>
99
+ <name>John Doe</name>
100
+ </author>
101
+ <entry>
102
+ <title>Atom-Powered Robots Run Amok</title>
103
+ <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
104
+ <summary>Some text.</summary>
105
+ <updated>2003-12-13T18:30:02Z</updated>
106
+ <link href="http://example.org/2003/12/13/atom03"/>
107
+ </entry>
65
108
  </feed>
109
+
66
110
 
67
111
  See Feed and Entry for details on the methods and attributes of those classes.
68
112
 
data/lib/atom.rb CHANGED
@@ -36,7 +36,7 @@ module Atom # :nodoc:
36
36
  # +localname+:: The local name of the extension element.
37
37
  #
38
38
  def [](ns, localname)
39
- if @simple_extensions.nil?
39
+ if !defined?(@simple_extensions) || @simple_extensions.nil?
40
40
  @simple_extensions = {}
41
41
  end
42
42
 
@@ -238,7 +238,8 @@ module Atom # :nodoc:
238
238
  XHTML = 'http://www.w3.org/1999/xhtml'
239
239
  attribute :type, :'xml:lang'
240
240
 
241
- def initialize(xml)
241
+ def initialize(xml)
242
+ super("")
242
243
  parse(xml, :once => true)
243
244
  starting_depth = xml.depth
244
245
 
@@ -246,9 +247,9 @@ module Atom # :nodoc:
246
247
  while xml.read == 1 && xml.node_type != XML::Reader::TYPE_ELEMENT; end
247
248
 
248
249
  if xml.local_name == 'div' && xml.namespace_uri == XHTML
249
- super(xml.read_inner_xml.strip.gsub(/\s+/, ' '))
250
+ set_content(xml.read_inner_xml.strip.gsub(/\s+/, ' '))
250
251
  else
251
- super(xml.read_outer_xml)
252
+ set_content(xml.read_outer_xml)
252
253
  end
253
254
 
254
255
  # get back to the end of the element we were created with
@@ -330,8 +331,24 @@ module Atom # :nodoc:
330
331
  #
331
332
  # A feed can be converted to XML using, the to_xml method that returns a valid atom document in a String.
332
333
  #
334
+ # == Attributes
335
+ #
336
+ # A feed has the following attributes:
337
+ #
338
+ # +id+:: A unique id for the feed.
339
+ # +updated+:: The Time the feed was updated.
340
+ # +title+:: The title of the feed.
341
+ # +subtitle+:: The subtitle of the feed.
342
+ # +authors+:: An array of Atom::Person objects that are authors of this feed.
343
+ # +contributors+:: An array of Atom::Person objects that are contributors to this feed.
344
+ # +generator+:: A Atom::Generator.
345
+ # +rights+:: A string describing the rights associated with this feed.
346
+ # +entries+:: An array of Atom::Entry objects.
347
+ # +links+:: An array of Atom:Link objects. (This is actually an Atom::Links array which is an Array with some sugar).
348
+ #
333
349
  # == References
334
350
  # See also http://www.atomenabled.org/developers/syndication/atom-format-spec.php#element.feed
351
+ #
335
352
  class Feed
336
353
  include Xml::Parseable
337
354
  include SimpleExtensions
@@ -344,8 +361,10 @@ module Atom # :nodoc:
344
361
  element :id, :rights
345
362
  element :generator, :class => Generator
346
363
  element :title, :subtitle, :class => Content
347
- element :updated, :published, :class => Time, :content_only => true
348
- elements :links, :entries
364
+ element :updated, :class => Time, :content_only => true
365
+ elements :links
366
+ elements :authors, :contributors, :class => Person
367
+ elements :entries
349
368
 
350
369
  # Initialize a Feed.
351
370
  #
@@ -358,7 +377,7 @@ module Atom # :nodoc:
358
377
  # +o+:: An XML Reader or a Hash of attributes.
359
378
  #
360
379
  def initialize(o = {})
361
- @links, @entries = Links.new, []
380
+ @links, @entries, @authors, @contributors = Links.new, [], [], []
362
381
 
363
382
  case o
364
383
  when XML::Reader
@@ -448,8 +467,27 @@ module Atom # :nodoc:
448
467
  #
449
468
  # A Entry can be converted to XML using, the to_xml method that returns a valid atom entry document in a String.
450
469
  #
470
+ # == Attributes
471
+ #
472
+ # An entry has the following attributes:
473
+ #
474
+ # +id+:: A unique id for the entry.
475
+ # +updated+:: The Time the entry was updated.
476
+ # +published+:: The Time the entry was published.
477
+ # +title+:: The title of the entry.
478
+ # +summary+:: A short textual summary of the item.
479
+ # +authors+:: An array of Atom::Person objects that are authors of this entry.
480
+ # +contributors+:: An array of Atom::Person objects that are contributors to this entry.
481
+ # +rights+:: A string describing the rights associated with this entry.
482
+ # +links+:: An array of Atom:Link objects. (This is actually an Atom::Links array which is an Array with some sugar).
483
+ # +source+:: Metadata of a feed that was the source of this item, for feed aggregators, etc.
484
+ # +categories+:: Array of Atom::Categories.
485
+ # +content+:: The content of the entry. This will be one of Atom::Content::Text, Atom::Content:Html or Atom::Content::Xhtml.
486
+ #
451
487
  # == References
452
- # See also http://www.atomenabled.org/developers/syndication/atom-format-spec.php#element.entry
488
+ # See also http://www.atomenabled.org/developers/syndication/atom-format-spec.php#element.entry for more detailed
489
+ # definitions of the attributes.
490
+ #
453
491
  class Entry
454
492
  include Xml::Parseable
455
493
  include SimpleExtensions
@@ -632,6 +670,7 @@ module Atom # :nodoc:
632
670
  end
633
671
  end
634
672
 
673
+ remove_method :length=
635
674
  def length=(v)
636
675
  @length = v.to_i
637
676
  end
data/lib/atom/pub.rb CHANGED
@@ -62,6 +62,7 @@ module Atom
62
62
  parse(o)
63
63
  end
64
64
 
65
+ remove_method :categories
65
66
  def categories; self; end
66
67
  end
67
68
 
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 = 4
5
+ TINY = 5
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -88,9 +88,11 @@ module Atom
88
88
 
89
89
  def Parseable.included(o)
90
90
  o.class_eval do
91
+ def o.ordered_element_specs; @ordered_element_specs ||= []; end
91
92
  def o.element_specs; @element_specs ||= {}; end
92
93
  def o.attributes; @attributes ||= []; end
93
94
  def element_specs; self.class.element_specs; end
95
+ def ordered_element_specs; self.class.ordered_element_specs; end
94
96
  def attributes; self.class.attributes; end
95
97
  def o.namespace(ns = @namespace); @namespace = ns; end
96
98
  end
@@ -113,29 +115,29 @@ module Atom
113
115
  namespace_map = NamespaceMap.new if namespace_map.nil?
114
116
  node = XML::Node.new(root_name)
115
117
  node['xmlns'] = self.class.namespace unless nodeonly || !self.class.respond_to?(:namespace)
116
-
117
- self.class.element_specs.values.select {|s| s.single? }.each do |spec|
118
- if attribute = self.send(spec.attribute)
119
- if attribute.respond_to?(:to_xml)
120
- node << attribute.to_xml(true, spec.name, spec.options[:namespace], namespace_map)
121
- else
122
- n = XML::Node.new(spec.name)
123
- n['xmlns'] = spec.options[:namespace]
124
- n << (attribute.is_a?(Time)? attribute.xmlschema : attribute.to_s)
125
- node << n
118
+
119
+ self.class.ordered_element_specs.each do |spec|
120
+ if spec.single?
121
+ if attribute = self.send(spec.attribute)
122
+ if attribute.respond_to?(:to_xml)
123
+ node << attribute.to_xml(true, spec.name, spec.options[:namespace], namespace_map)
124
+ else
125
+ n = XML::Node.new(spec.name)
126
+ n['xmlns'] = spec.options[:namespace]
127
+ n << (attribute.is_a?(Time)? attribute.xmlschema : attribute.to_s)
128
+ node << n
129
+ end
126
130
  end
127
- end
128
- end
129
-
130
- self.class.element_specs.values.select {|s| !s.single? }.each do |spec|
131
- self.send(spec.attribute).each do |attribute|
132
- if attribute.respond_to?(:to_xml)
133
- node << attribute.to_xml(true, spec.name.singularize, nil, namespace_map)
134
- else
135
- n = XML::Node.new(spec.name.singularize)
136
- n['xmlns'] = spec.options[:namespace]
137
- n << attribute.to_s
138
- node << n
131
+ else
132
+ self.send(spec.attribute).each do |attribute|
133
+ if attribute.respond_to?(:to_xml)
134
+ node << attribute.to_xml(true, spec.name.singularize, nil, namespace_map)
135
+ else
136
+ n = XML::Node.new(spec.name.singularize)
137
+ n['xmlns'] = spec.options[:namespace]
138
+ n << attribute.to_s
139
+ node << n
140
+ end
139
141
  end
140
142
  end
141
143
  end
@@ -186,7 +188,7 @@ module Atom
186
188
 
187
189
  names.each do |name|
188
190
  attr_accessor name
189
- self.element_specs[name.to_s] = ParseSpec.new(name, options)
191
+ self.ordered_element_specs << self.element_specs[name.to_s] = ParseSpec.new(name, options)
190
192
  end
191
193
  end
192
194
 
@@ -196,7 +198,7 @@ module Atom
196
198
 
197
199
  names.each do |name|
198
200
  attr_accessor name
199
- self.element_specs[name.to_s.singularize] = ParseSpec.new(name, options)
201
+ self.ordered_element_specs << self.element_specs[name.to_s.singularize] = ParseSpec.new(name, options)
200
202
  end
201
203
  end
202
204
 
data/spec/atom_spec.rb CHANGED
@@ -42,6 +42,14 @@ shared_examples_for 'simple_single_entry.atom attributes' do
42
42
  @feed.alternate.href.should == 'http://example.org/'
43
43
  end
44
44
 
45
+ it "should have 1 author" do
46
+ @feed.should have(1).authors
47
+ end
48
+
49
+ it "should have 'John Doe' as the author's name" do
50
+ @feed.authors.first.name.should == "John Doe"
51
+ end
52
+
45
53
  it "should parse title" do
46
54
  @entry.title.should == 'Atom-Powered Robots Run Amok'
47
55
  end
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
4
+ version: 0.3.5
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-04-21 00:00:00 +09:30
12
+ date: 2008-05-03 00:00:00 +09:30
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency