ratom 0.6.5 → 0.6.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- :patch: 5
2
+ :patch: 6
3
3
  :major: 0
4
4
  :build:
5
5
  :minor: 6
data/lib/atom/pub.rb CHANGED
@@ -60,7 +60,8 @@ module Atom
60
60
  class Categories < DelegateClass(Array)
61
61
  include Atom::Xml::Parseable
62
62
  elements :categories, :class => Atom::Category
63
- attribute :href, :fixed
63
+ attribute :fixed
64
+ uri_attribute :href
64
65
 
65
66
  def initialize(o)
66
67
  super([])
@@ -102,7 +103,7 @@ module Atom
102
103
 
103
104
  class Collection
104
105
  include Atom::Xml::Parseable
105
- attribute :href
106
+ uri_attribute :href
106
107
  element :title, :class => Content, :namespace => Atom::NAMESPACE
107
108
  element :categories, :class => Categories
108
109
  elements :accepts, :content_only => true
@@ -79,11 +79,20 @@ module Atom
79
79
  when XML::Reader::TYPE_ELEMENT
80
80
  if element_specs.include?(xml.local_name) && (self.class.known_namespaces + [Atom::NAMESPACE, Atom::Pub::NAMESPACE]).include?(xml.namespace_uri)
81
81
  element_specs[xml.local_name].parse(self, xml)
82
- elsif attributes.any?
82
+ elsif attributes.any? || uri_attributes.any?
83
83
  while (xml.move_to_next_attribute == 1)
84
84
  if attributes.include?(xml.name)
85
85
  # Support attribute names with namespace prefixes
86
- self.send("#{xml.name.sub(/:/, '_')}=", xml.value)
86
+ self.send("#{accessor_name(xml.name)}=", xml.value)
87
+ elsif uri_attributes.include?(xml.name)
88
+ value = if xml.base_uri
89
+ @base_uri = xml.base_uri
90
+ raw_uri = URI.parse(xml.value)
91
+ (raw_uri.relative? ? URI.parse(xml.base_uri) + raw_uri : raw_uri).to_s
92
+ else
93
+ xml.value
94
+ end
95
+ self.send("#{accessor_name(xml.name)}=", value)
87
96
  elsif self.respond_to?(:simple_extensions)
88
97
  self[xml.namespace_uri, xml.local_name].as_attribute = true
89
98
  self[xml.namespace_uri, xml.local_name] << xml.value
@@ -106,15 +115,21 @@ module Atom
106
115
  def current_node_is?(xml, element, ns = nil)
107
116
  xml.node_type == XML::Reader::TYPE_ELEMENT && xml.local_name == element && (ns.nil? || ns == xml.namespace_uri)
108
117
  end
118
+
119
+ def accessor_name(name)
120
+ name.to_s.sub(/:/, '_').to_sym
121
+ end
109
122
 
110
123
  def Parseable.included(o)
111
124
  o.class_eval do
112
125
  def o.ordered_element_specs; @ordered_element_specs ||= []; end
113
126
  def o.element_specs; @element_specs ||= {}; end
114
127
  def o.attributes; @attributes ||= []; end
128
+ def o.uri_attributes; @uri_attributes ||= []; end
115
129
  def element_specs; self.class.element_specs; end
116
130
  def ordered_element_specs; self.class.ordered_element_specs; end
117
131
  def attributes; self.class.attributes; end
132
+ def uri_attributes; self.class.uri_attributes; end
118
133
  def o.namespace(ns = @namespace); @namespace = ns; end
119
134
  def o.add_extension_namespace(ns, url); self.extensions_namespaces[ns.to_s] = url; end
120
135
  def o.extensions_namespaces; @extensions_namespaces ||= {} end
@@ -173,8 +188,8 @@ module Atom
173
188
  end
174
189
  end
175
190
 
176
- self.class.attributes.each do |attribute|
177
- if value = self.send("#{attribute.sub(/:/, '_')}")
191
+ (self.class.attributes + self.class.uri_attributes).each do |attribute|
192
+ if value = self.send(accessor_name(attribute))
178
193
  if value != 0
179
194
  node[attribute] = value.to_s
180
195
  end
@@ -249,6 +264,14 @@ module Atom
249
264
  self.attributes << name.to_s
250
265
  end
251
266
  end
267
+
268
+ def uri_attribute(*names)
269
+ attr_accessor :base_uri
270
+ names.each do |name|
271
+ attr_accessor name.to_s.sub(/:/, '_').to_sym
272
+ self.uri_attributes << name.to_s
273
+ end
274
+ end
252
275
 
253
276
  def loadable!(&error_handler)
254
277
  class_name = self.name
data/lib/atom.rb CHANGED
@@ -713,7 +713,8 @@ module Atom # :nodoc:
713
713
  end
714
714
 
715
715
  include Xml::Parseable
716
- attribute :href, :rel, :type, :length, :hreflang, :title
716
+ attribute :rel, :type, :length, :hreflang, :title
717
+ uri_attribute :href
717
718
 
718
719
  # Create a link.
719
720
  #
data/spec/app/service.xml CHANGED
@@ -7,7 +7,7 @@
7
7
  href="http://example.org/blog/main" >
8
8
  <atom:title>My Blog Entries</atom:title>
9
9
  <categories
10
- href="http://example.com/cats/forMain.cats" />
10
+ href="http://example.org/cats/forMain.cats" />
11
11
  </collection>
12
12
  <collection
13
13
  href="http://example.org/blog/pic" >
@@ -0,0 +1,37 @@
1
+ <?xml version="1.0" encoding='utf-8'?>
2
+ <service xmlns="http://www.w3.org/2007/app"
3
+ xmlns:atom="http://www.w3.org/2005/Atom"
4
+ xml:base="http://example.org/">
5
+ <workspace>
6
+ <atom:title>Main Site</atom:title>
7
+ <collection
8
+ href="/blog/main" >
9
+ <atom:title>My Blog Entries</atom:title>
10
+ <categories
11
+ href="/cats/forMain.cats" />
12
+ </collection>
13
+ <collection
14
+ href="http://example.org/blog/pic" >
15
+ <atom:title>Pictures</atom:title>
16
+ <accept>image/png</accept>
17
+ <accept>image/jpeg</accept>
18
+ <accept>image/gif</accept>
19
+ </collection>
20
+ </workspace>
21
+ <workspace>
22
+ <atom:title>Sidebar Blog</atom:title>
23
+ <collection
24
+ href="http://example.org/sidebar/list" >
25
+ <atom:title>Remaindered Links</atom:title>
26
+ <accept>application/atom+xml;type=entry</accept>
27
+ <categories fixed="yes">
28
+ <atom:category
29
+ scheme="http://example.org/extra-cats/"
30
+ term="joke" />
31
+ <atom:category
32
+ scheme="http://example.org/extra-cats/"
33
+ term="serious" />
34
+ </categories>
35
+ </collection>
36
+ </workspace>
37
+ </service>
@@ -34,7 +34,7 @@ shared_examples_for 'parser of spec/app/service.xml' do
34
34
  end
35
35
 
36
36
  it "should have a href on categories" do
37
- @collection1.categories.href.should == "http://example.com/cats/forMain.cats"
37
+ @collection1.categories.href.should == "http://example.org/cats/forMain.cats"
38
38
  @collection1.categories.fixed?.should be_false
39
39
  end
40
40
 
@@ -152,6 +152,19 @@ describe Atom::Pub do
152
152
 
153
153
  it_should_behave_like 'parser of spec/app/service.xml'
154
154
  end
155
+
156
+ describe "load service with xml:base" do
157
+ before(:all) do
158
+ @service = Atom::Pub::Service.load_service(File.open('spec/app/service_xml_base.xml'))
159
+ @workspace = @service.workspaces.first
160
+ @workspace2 = @service.workspaces[1]
161
+ @collection1 = @workspace.collections.first
162
+ @collection2 = @workspace.collections[1]
163
+ @collection3 = @workspace2.collections.first
164
+ end
165
+
166
+ it_should_behave_like 'parser of spec/app/service.xml'
167
+ end
155
168
 
156
169
  describe "load_service with authentication" do
157
170
  it "should pass credentials to the server" do
data/spec/atom_spec.rb CHANGED
@@ -265,7 +265,28 @@ describe Atom do
265
265
  @feed.should have(1).categories
266
266
  end
267
267
  end
268
-
268
+
269
+ describe "FeedWithXmlBase" do
270
+ before(:all) do
271
+ @feed = Atom::Feed.load_feed(File.open('spec/conformance/xmlbase.atom'))
272
+ end
273
+
274
+ subject { @feed }
275
+
276
+ its(:title) { should == "xml:base support tests" }
277
+ it { should have(16).entries }
278
+
279
+ it "should resolve all alternate links to the same location" do
280
+ @feed.entries.each do |entry|
281
+ entry.links.first.href.should == "http://example.org/tests/base/result.html"
282
+ end
283
+ end
284
+
285
+ it "should resolve all links in content to what their label says" do
286
+ pending "support xml:base in content XHTML"
287
+ end
288
+ end
289
+
269
290
  describe Atom::Entry do
270
291
  before(:each) do
271
292
  @entry = @feed.entries.first
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 6
8
- - 5
9
- version: 0.6.5
8
+ - 6
9
+ version: 0.6.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Peerworks
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-04-07 00:00:00 +09:30
18
+ date: 2010-04-22 00:00:00 +09:30
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -67,6 +67,7 @@ files:
67
67
  - lib/atom/xml/parser.rb
68
68
  - spec/app/member_entry.atom
69
69
  - spec/app/service.xml
70
+ - spec/app/service_xml_base.xml
70
71
  - spec/atom/pub_spec.rb
71
72
  - spec/atom_spec.rb
72
73
  - spec/conformance/baseuri.atom