ratom 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +8 -0
- data/config/hoe.rb +1 -1
- data/lib/atom.rb +48 -23
- data/lib/atom/version.rb +2 -2
- data/lib/atom/xml/parser.rb +5 -5
- data/spec/atom_spec.rb +68 -14
- data/spec/conformance/linktests.xml +10 -0
- metadata +3 -3
data/History.txt
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
== 0.6.0 2009-19-03
|
2
|
+
|
3
|
+
* Now depends on libxml-ruby 1.1.2.
|
4
|
+
* Added support for hreflang on links. (David Arango)
|
5
|
+
* Update to work with latest version of libxml-ruby. (oortle & me)
|
6
|
+
* Content::Text and Content::Xhtml can now be created with String's like Content::Html.
|
7
|
+
* Make sure Atom::Generator outputs the generator name as the text of the element.
|
8
|
+
|
1
9
|
== 0.5.2 2008-12-06
|
2
10
|
|
3
11
|
* Remove whitespace modification in content. (dlisboa)
|
data/config/hoe.rb
CHANGED
@@ -60,7 +60,7 @@ hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
|
60
60
|
# == Optional
|
61
61
|
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
62
62
|
# An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
|
63
|
-
p.extra_deps = [['libxml-ruby', '>=
|
63
|
+
p.extra_deps = [['libxml-ruby', '>= 1.1.2']]
|
64
64
|
|
65
65
|
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
66
66
|
|
data/lib/atom.rb
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
require 'forwardable'
|
9
9
|
require 'delegate'
|
10
10
|
require 'rubygems'
|
11
|
-
gem 'libxml-ruby', '>=
|
11
|
+
gem 'libxml-ruby', '>= 1.1.2'
|
12
12
|
require 'xml/libxml'
|
13
13
|
require 'atom/xml/parser.rb'
|
14
14
|
|
@@ -84,6 +84,14 @@ module Atom # :nodoc:
|
|
84
84
|
|
85
85
|
yield(self) if block_given?
|
86
86
|
end
|
87
|
+
|
88
|
+
def to_xml(nodeonly = true, name = 'generator', namespace = nil, namespace_map = Atom::Xml::NamespaceMap.new)
|
89
|
+
node = XML::Node.new("#{namespace_map.prefix(Atom::NAMESPACE, name)}")
|
90
|
+
node << @name if @name
|
91
|
+
node['uri'] = @uri if @uri
|
92
|
+
node['version'] = @version if @version
|
93
|
+
node
|
94
|
+
end
|
87
95
|
end
|
88
96
|
|
89
97
|
# Represents a Category as defined by the Atom Syndication Format specification.
|
@@ -185,9 +193,15 @@ module Atom # :nodoc:
|
|
185
193
|
# Text content within an Atom document.
|
186
194
|
class Text < Base
|
187
195
|
attribute :type, :'xml:lang'
|
188
|
-
def initialize(
|
189
|
-
|
190
|
-
|
196
|
+
def initialize(o)
|
197
|
+
case o
|
198
|
+
when String
|
199
|
+
super(o)
|
200
|
+
@type = "text"
|
201
|
+
when XML::Reader
|
202
|
+
super(o.read_string)
|
203
|
+
parse(o, :once => true)
|
204
|
+
end
|
191
205
|
end
|
192
206
|
|
193
207
|
def to_xml(nodeonly = true, name = 'content', namespace = nil, namespace_map = Atom::Xml::NamespaceMap.new)
|
@@ -241,22 +255,29 @@ module Atom # :nodoc:
|
|
241
255
|
XHTML = 'http://www.w3.org/1999/xhtml'
|
242
256
|
attribute :type, :'xml:lang'
|
243
257
|
|
244
|
-
def initialize(
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
258
|
+
def initialize(o)
|
259
|
+
case o
|
260
|
+
when String
|
261
|
+
super(o)
|
262
|
+
@type = "xhtml"
|
263
|
+
when XML::Reader
|
264
|
+
super("")
|
265
|
+
xml = o
|
266
|
+
parse(xml, :once => true)
|
267
|
+
starting_depth = xml.depth
|
268
|
+
|
269
|
+
# Get the next element - should be a div according to the atom spec
|
270
|
+
while xml.read && xml.node_type != XML::Reader::TYPE_ELEMENT; end
|
271
|
+
|
272
|
+
if xml.local_name == 'div' && xml.namespace_uri == XHTML
|
273
|
+
set_content(xml.read_inner_xml.strip.gsub(/\s+/, ' '))
|
274
|
+
else
|
275
|
+
set_content(xml.read_outer_xml)
|
276
|
+
end
|
277
|
+
|
278
|
+
# get back to the end of the element we were created with
|
279
|
+
while xml.read == 1 && xml.depth > starting_depth; end
|
256
280
|
end
|
257
|
-
|
258
|
-
# get back to the end of the element we were created with
|
259
|
-
while xml.read == 1 && xml.depth > starting_depth; end
|
260
281
|
end
|
261
282
|
|
262
283
|
def to_xml(nodeonly = true, name = 'content', namespace = nil, namespace_map = Atom::Xml::NamespaceMap.new)
|
@@ -533,7 +554,7 @@ module Atom # :nodoc:
|
|
533
554
|
o.read
|
534
555
|
parse(o)
|
535
556
|
else
|
536
|
-
raise
|
557
|
+
raise ParseError, "Entry created with node other than atom:entry: #{o.name}"
|
537
558
|
end
|
538
559
|
when Hash
|
539
560
|
o.each do |k,v|
|
@@ -573,7 +594,11 @@ module Atom # :nodoc:
|
|
573
594
|
#
|
574
595
|
# Returns the first link with rel == 'alternate' that matches the given type.
|
575
596
|
def alternate(type = nil)
|
576
|
-
detect { |link|
|
597
|
+
detect { |link|
|
598
|
+
(link.rel.nil? || link.rel == Link::Rel::ALTERNATE) && (type.nil? || type == link.type) && (link.hreflang.nil?)
|
599
|
+
} || detect { |link|
|
600
|
+
(link.rel.nil? || link.rel == Link::Rel::ALTERNATE) && (type.nil? || type == link.type)
|
601
|
+
}
|
577
602
|
end
|
578
603
|
|
579
604
|
# Get all alternates.
|
@@ -654,7 +679,7 @@ module Atom # :nodoc:
|
|
654
679
|
end
|
655
680
|
|
656
681
|
include Xml::Parseable
|
657
|
-
attribute :href, :rel, :type, :length
|
682
|
+
attribute :href, :rel, :type, :length, :hreflang
|
658
683
|
|
659
684
|
# Create a link.
|
660
685
|
#
|
@@ -669,7 +694,7 @@ module Atom # :nodoc:
|
|
669
694
|
raise ArgumentError, "Link created with node other than atom:link: #{o.name}"
|
670
695
|
end
|
671
696
|
when Hash
|
672
|
-
[:href, :rel, :type, :length].each do |attr|
|
697
|
+
[:href, :rel, :type, :length, :hreflang].each do |attr|
|
673
698
|
self.send("#{attr}=", o[attr])
|
674
699
|
end
|
675
700
|
else
|
data/lib/atom/version.rb
CHANGED
data/lib/atom/xml/parser.rb
CHANGED
@@ -261,9 +261,9 @@ module Atom
|
|
261
261
|
xml =
|
262
262
|
case o
|
263
263
|
when String
|
264
|
-
XML::Reader.
|
264
|
+
XML::Reader.string(o)
|
265
265
|
when IO
|
266
|
-
XML::Reader.
|
266
|
+
XML::Reader.io(o)
|
267
267
|
when URI
|
268
268
|
raise ArgumentError, "#{class_name}.load only handles http URIs" if o.scheme != 'http'
|
269
269
|
response = nil
|
@@ -283,7 +283,7 @@ module Atom
|
|
283
283
|
end
|
284
284
|
case response
|
285
285
|
when Net::HTTPSuccess
|
286
|
-
XML::Reader.
|
286
|
+
XML::Reader.string(response.body)
|
287
287
|
when nil
|
288
288
|
raise ArgumentError.new("nil response to #{o}")
|
289
289
|
else
|
@@ -294,9 +294,9 @@ module Atom
|
|
294
294
|
end
|
295
295
|
|
296
296
|
if error_handler
|
297
|
-
|
297
|
+
XML::Error.set_handler(&error_handler)
|
298
298
|
else
|
299
|
-
|
299
|
+
XML::Error.set_handler do |reader, message, severity, base, line|
|
300
300
|
if severity == XML::Reader::SEVERITY_ERROR
|
301
301
|
raise ParseError, "#{message} at #{line} in #{o}"
|
302
302
|
end
|
data/spec/atom_spec.rb
CHANGED
@@ -654,6 +654,20 @@ describe Atom do
|
|
654
654
|
@entry.links.map{|l| l.href }.should include('http://www.snellspace.com/public/linktests/example')
|
655
655
|
end
|
656
656
|
end
|
657
|
+
|
658
|
+
describe 'linktest9' do
|
659
|
+
before(:all) do
|
660
|
+
@entry = @entries[8]
|
661
|
+
end
|
662
|
+
|
663
|
+
it "should parse all links" do
|
664
|
+
@entry.should have(3).links
|
665
|
+
end
|
666
|
+
|
667
|
+
it "should pick the alternate without hreflang" do
|
668
|
+
@entry.alternate.href.should == 'http://www.snellspace.com/public/linktests/alternate'
|
669
|
+
end
|
670
|
+
end
|
657
671
|
end
|
658
672
|
|
659
673
|
describe 'ordertest.atom' do
|
@@ -1071,21 +1085,40 @@ describe Atom do
|
|
1071
1085
|
|
1072
1086
|
describe 'single custom_extensions' do
|
1073
1087
|
before(:all) do
|
1074
|
-
Atom::Entry.add_extension_namespace :custom, "http://custom.namespace"
|
1075
|
-
Atom::Entry.element "custom:
|
1088
|
+
Atom::Entry.add_extension_namespace :custom, "http://single.custom.namespace"
|
1089
|
+
Atom::Entry.element "custom:singleproperty", :class => Atom::Extensions::Property
|
1076
1090
|
@entry = Atom::Entry.load_entry(File.open('spec/fixtures/entry_with_single_custom_extension.atom'))
|
1077
1091
|
end
|
1078
1092
|
|
1079
1093
|
it "should load single custom extensions for entry" do
|
1080
|
-
@entry.
|
1094
|
+
@entry.custom_singleproperty.should_not be_nil
|
1081
1095
|
end
|
1082
1096
|
|
1083
1097
|
it "should load correct data for custom extensions for entry" do
|
1084
|
-
@entry.
|
1085
|
-
@entry.
|
1098
|
+
@entry.custom_singleproperty.name.should == 'foo'
|
1099
|
+
@entry.custom_singleproperty.value.should == 'bar'
|
1086
1100
|
end
|
1087
1101
|
end
|
1088
|
-
|
1102
|
+
|
1103
|
+
describe 'write_support' do
|
1104
|
+
# FIXME this example depends on "custom_extensions" for configuring Atom::Entry
|
1105
|
+
before(:all) do
|
1106
|
+
@entry = Atom::Entry.new
|
1107
|
+
@entry.ns_alias_property << Atom::Extensions::Property.new('ratom', 'rocks')
|
1108
|
+
@entry.ns_alias_property << Atom::Extensions::Property.new('custom extensions', 'also rock')
|
1109
|
+
@node = @entry.to_xml(true)
|
1110
|
+
end
|
1111
|
+
|
1112
|
+
it "should_write_custom_extensions_on_to_xml" do
|
1113
|
+
@node.children.size.should == 2
|
1114
|
+
ratom, custom_extensions = @node.children
|
1115
|
+
ratom.attributes["name"].should == "ratom"
|
1116
|
+
ratom.attributes["value"].should == "rocks"
|
1117
|
+
custom_extensions.attributes["name"].should == "custom extensions"
|
1118
|
+
custom_extensions.attributes["value"].should == "also rock"
|
1119
|
+
end
|
1120
|
+
end
|
1121
|
+
|
1089
1122
|
describe Atom::Link do
|
1090
1123
|
before(:each) do
|
1091
1124
|
@href = 'http://example.org/next'
|
@@ -1185,6 +1218,22 @@ describe Atom do
|
|
1185
1218
|
end
|
1186
1219
|
end
|
1187
1220
|
|
1221
|
+
describe Atom::Content::Text do
|
1222
|
+
it "should be createable from a string" do
|
1223
|
+
txt = Atom::Content::Text.new("This is some text")
|
1224
|
+
txt.should == "This is some text"
|
1225
|
+
txt.type.should == "text"
|
1226
|
+
end
|
1227
|
+
end
|
1228
|
+
|
1229
|
+
describe Atom::Content::Xhtml do
|
1230
|
+
it "should be createable from a string" do
|
1231
|
+
txt = Atom::Content::Xhtml.new("<p>This is some text</p>")
|
1232
|
+
txt.should == "<p>This is some text</p>"
|
1233
|
+
txt.type.should == "xhtml"
|
1234
|
+
end
|
1235
|
+
end
|
1236
|
+
|
1188
1237
|
describe 'Atom::Category initializer' do
|
1189
1238
|
it "should create a empty category" do
|
1190
1239
|
lambda { Atom::Category.new }.should_not raise_error
|
@@ -1233,18 +1282,23 @@ describe Atom do
|
|
1233
1282
|
end
|
1234
1283
|
|
1235
1284
|
it "should create from a hash" do
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1285
|
+
generator = Atom::Generator.new(:name => 'generator', :uri => 'http://generator')
|
1286
|
+
generator.name.should == 'generator'
|
1287
|
+
generator.uri.should == 'http://generator'
|
1239
1288
|
end
|
1240
1289
|
|
1241
1290
|
it "should create from a block" do
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1291
|
+
generator = Atom::Generator.new do |generator|
|
1292
|
+
generator.name = 'generator'
|
1293
|
+
generator.uri = 'http://generator'
|
1245
1294
|
end
|
1246
|
-
|
1247
|
-
|
1295
|
+
generator.name.should == 'generator'
|
1296
|
+
generator.uri.should == 'http://generator'
|
1297
|
+
end
|
1298
|
+
|
1299
|
+
it "should output the name as the text of the generator element" do
|
1300
|
+
generator = Atom::Generator.new({:name => "My Generator"})
|
1301
|
+
generator.to_xml(true).to_s.should == "<generator>My Generator</generator>"
|
1248
1302
|
end
|
1249
1303
|
end
|
1250
1304
|
end
|
@@ -90,4 +90,14 @@
|
|
90
90
|
<link href="http://www.snellspace.com/public/linktests/alternate" />
|
91
91
|
</entry>
|
92
92
|
|
93
|
+
<entry>
|
94
|
+
<id>tag:snellspace.com,2006:/atom/conformance/linktest/8</id>
|
95
|
+
<title>Entry with links in different languages</title>
|
96
|
+
<updated>2005-01-18T15:00:06Z</updated>
|
97
|
+
<summary>The aggregator should pick the second link as alternate.</summary>
|
98
|
+
<link rel="alternate" hreflang="es" href="http://www.snellspace.com/es/public/linktests/alternate" />
|
99
|
+
<link rel="alternate" href="http://www.snellspace.com/public/linktests/alternate" />
|
100
|
+
<link rel="alternate" hreflang="cat" href="http://www.snellspace.com/cat/public/linktests/alternate" />
|
101
|
+
</entry>
|
102
|
+
|
93
103
|
</feed>
|
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.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peerworks
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date:
|
13
|
+
date: 2009-03-19 00:00:00 +10:30
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
requirements:
|
22
22
|
- - ">="
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version:
|
24
|
+
version: 1.1.2
|
25
25
|
version:
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: hoe
|