Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/demimismo/ratom into demimi…
Browse files Browse the repository at this point in the history
…smo/master
  • Loading branch information
seangeo committed Mar 18, 2009
2 parents 7a97a70 + 2e29f20 commit ebdfa32
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/atom.rb
Expand Up @@ -573,7 +573,11 @@ def initialize
#
# Returns the first link with rel == 'alternate' that matches the given type.
def alternate(type = nil)
detect { |link| (link.rel.nil? || link.rel == Link::Rel::ALTERNATE) && (type.nil? || type == link.type) }
detect { |link|
(link.rel.nil? || link.rel == Link::Rel::ALTERNATE) && (type.nil? || type == link.type) && (link.hreflang.nil?)
} || detect { |link|
(link.rel.nil? || link.rel == Link::Rel::ALTERNATE) && (type.nil? || type == link.type)
}
end

# Get all alternates.
Expand Down Expand Up @@ -654,7 +658,7 @@ module Rel # :nodoc:
end

include Xml::Parseable
attribute :href, :rel, :type, :length
attribute :href, :rel, :type, :length, :hreflang

# Create a link.
#
Expand All @@ -669,7 +673,7 @@ def initialize(o)
raise ArgumentError, "Link created with node other than atom:link: #{o.name}"
end
when Hash
[:href, :rel, :type, :length].each do |attr|
[:href, :rel, :type, :length, :hreflang].each do |attr|
self.send("#{attr}=", o[attr])
end
else
Expand Down
14 changes: 14 additions & 0 deletions spec/atom_spec.rb
Expand Up @@ -654,6 +654,20 @@
@entry.links.map{|l| l.href }.should include('http://www.snellspace.com/public/linktests/example')
end
end

describe 'linktest9' do
before(:all) do
@entry = @entries[8]
end

it "should parse all links" do
@entry.should have(3).links
end

it "should pick the alternate without hreflang" do
@entry.alternate.href.should == 'http://www.snellspace.com/public/linktests/alternate'
end
end
end

describe 'ordertest.atom' do
Expand Down
10 changes: 10 additions & 0 deletions spec/conformance/linktests.xml
Expand Up @@ -90,4 +90,14 @@
<link href="http://www.snellspace.com/public/linktests/alternate" />
</entry>

<entry>
<id>tag:snellspace.com,2006:/atom/conformance/linktest/8</id>
<title>Entry with links in different languages</title>
<updated>2005-01-18T15:00:06Z</updated>
<summary>The aggregator should pick the second link as alternate.</summary>
<link rel="alternate" hreflang="es" href="http://www.snellspace.com/es/public/linktests/alternate" />
<link rel="alternate" href="http://www.snellspace.com/public/linktests/alternate" />
<link rel="alternate" hreflang="cat" href="http://www.snellspace.com/cat/public/linktests/alternate" />
</entry>

</feed>

0 comments on commit ebdfa32

Please sign in to comment.