adds support for nested formats

This commit is contained in:
Jessica Lynn Suttles 2013-02-06 12:15:07 -08:00
parent 9fae5c7248
commit c013f48a03
7 changed files with 181 additions and 102 deletions

View file

@ -2,7 +2,7 @@ require "spec_helper"
require "microformats2"
describe Microformats2::Collection do
describe "with simple h-card" do
describe "with simple .h-card" do
before do
html = "spec/support/simple_hcard.html"
@collection = Microformats2.parse(html)
@ -13,29 +13,68 @@ describe Microformats2::Collection do
@collection.h_card.should be_kind_of HCard
end
it "assigns .h-card .p-name to HCard#name" do
@collection.h_card.name.should == "Jessica Lynn Suttles"
@collection.h_card.name.value.should == "Jessica Lynn Suttles"
end
it "assigns .h-card .u-url to HCard#url" do
@collection.h_card.url.should == "http://twitter.com/jlsuttles"
it "assigns both .h-card .u-url to HCard#url" do
urls = ["http://flickr.com/jlsuttles", "http://twitter.com/jlsuttles"]
@collection.h_card.url.map(&:value).should == urls
end
it "assings .h-card .dt-bday to HCard#bday" do
@collection.h_card.bday.should be_kind_of DateTime
@collection.h_card.bday.to_s.should == "1990-10-15T20:45:33-08:00"
@collection.h_card.bday.value.should be_kind_of DateTime
@collection.h_card.bday.value.to_s.should == "1990-10-15T20:45:33-08:00"
end
it "assigns .h-card .e-content to HCard#content" do
@collection.h_card.content.should == "Vegan. Cat lover. Coder."
@collection.h_card.content.value.should == "Vegan. Cat lover. Coder."
end
end
describe "#to_hash" do
it "returns the correct Hash" do
hash = {
:items => [{ :type => ["h-card"],
:items => [{
:type => ["h-card"],
:properties => {
:url => "http://twitter.com/jlsuttles",
:name => "Jessica Lynn Suttles",
:bday => "1990-10-15T20:45:33-08:00",
:content => "Vegan. Cat lover. Coder."
:url => ["http://flickr.com/jlsuttles", "http://twitter.com/jlsuttles"],
:name => ["Jessica Lynn Suttles"],
:bday => ["1990-10-15T20:45:33-08:00"],
:content => ["Vegan. Cat lover. Coder."]
}
}]
}
@collection.to_hash.should == hash
end
end
end
describe "with .h-entry .p-author.h-card nested" do
before do
html = "spec/support/nested_hentry.html"
@collection = Microformats2.parse(html)
end
describe "#parse" do
it "creates ruby class HEntry" do
@collection.h_entry.should be_kind_of HEntry
end
it "assigns .h-entry .p-author to HEntry#author" do
@collection.h_entry.author.value.should == "Jessica Lynn Suttles"
end
end
describe "#to_hash" do
it "returns the correct Hash" do
hash = {
:items => [{
:type => ["h-entry"],
:properties => {
:author => [{
:value => "Jessica Lynn Suttles",
:type => ["h-card", "h-org"],
:properties => {
:url => ["http://twitter.com/jlsuttles"],
:name => ["Jessica Lynn Suttles"]
}
}]
}
}]
}

View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<body>
<div class="h-entry">
<div class="p-author h-card h-org">
<a href="http://twitter.com/jlsuttles" class="u-url p-name">
Jessica Lynn Suttles
</a>
</div>
</div>
</body>
</html>

View file

@ -1,10 +1,13 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<!DOCTYPE html>
<html>
<body>
<div class="h-card">
<a href="http://twitter.com/jlsuttles" class="u-url p-name">
<a href="http://flickr.com/jlsuttles" class="u-url p-name">
Jessica Lynn Suttles
</a>
<a href="http://twitter.com/jlsuttles" class="u-url">
@jlsuttles
</a>
<time class="dt-bday" datetime="1990-10-15T20:45:33-08:00">
October 15, 1990
</time>