This repository has been archived by the owner on Nov 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* reltag extract not working yet (placeholdered) * Only simple examples, not following spec 100% yet * Also includes refactoring microformat map some to avoid class loading issues * Also had to add yaml require for tests to run
- Loading branch information
1 parent
2830c5d
commit a1084ba
Showing
6 changed files
with
247 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
module Prism | ||
module Microformat | ||
class HAtom < POSH | ||
FRIENDLY_NAME = "hAtom" | ||
WIKI_URL = "http://microformats.org/wiki/hatom" | ||
XMDP = 'http://microformats.org/profile/hatom' | ||
|
||
name :hfeed | ||
|
||
search do |doc| | ||
hfeed = doc.css("#{name}") | ||
if hfeed.empty? && !doc.css('.hfeed').empty? | ||
doc | ||
else | ||
hfeed | ||
end | ||
end | ||
|
||
#TODO move to reltags | ||
has_many :category do | ||
search do |node| | ||
node.css('a[rel~="tag"]') | ||
end | ||
extract do |node| | ||
node['href'].split('/').last | ||
end | ||
end | ||
|
||
has_many :hentry do | ||
has_one :entry_title, :entry_summary | ||
|
||
has_one :updated, :published do | ||
extract :typevalue | ||
end | ||
|
||
has_one :author do | ||
extract :hcard | ||
end | ||
|
||
has_one :entry_content do | ||
extract do |node| | ||
node.inner_html.strip | ||
end | ||
end | ||
|
||
#TODO move to reltags | ||
has_many :tags do | ||
search do |node| | ||
node.css('a[rel~="tag"]') | ||
end | ||
extract do |node| | ||
node['href'].split('/').last | ||
end | ||
end | ||
|
||
has_one :bookmark do | ||
search do |node| | ||
node.css('a[rel~="bookmark"]') | ||
end | ||
extract do |node| | ||
node['href'] | ||
end | ||
end | ||
|
||
required! | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<!-- from http://microformats.org/wiki/hatom-examples --> | ||
<body> | ||
<div id="uf"> | ||
<div class="hfeed" id="content"> | ||
<div class="hentry entry" id="post-60"> | ||
<h3 class="entry-title"> | ||
<a href="http://www.microformats.org/blog/..." rel="bookmark" title="...">Wiki Attack</a> | ||
</h3> | ||
<div class="entry-content"> | ||
<p>We had a bit of trouble with ...</p> | ||
<p>We've restored the wiki and ...</p> | ||
<p>If anyone is working to combat said spammers ...</p> | ||
</div> | ||
|
||
<h4 class="tags">Technorati Tags:</h4> | ||
<ul class="tags"> | ||
<li><a href="http://technorati.com/tag/mediawiki" rel="tag">MediaWiki</a></li> | ||
<li><a href="http://technorati.com/tag/microformats" rel="tag">MicroFormats</a></li> | ||
<li><a href="http://technorati.com/tag/spam" rel="tag">Spam</a></li> | ||
</ul> | ||
|
||
<ul class="post-info"> | ||
<li> | ||
<a href="http://www.microformats.org/blog/..." rel="bookmark" | ||
title="..."><abbr class="published" title="2005-10-10T14:07:00-07:00">October 10th, 2005</abbr></a> | ||
</li> | ||
<li> | ||
<address class="vcard author"><a class="url fn" href="http://theryanking.com">Ryan King</a></address> | ||
</li> | ||
<li> | ||
<a href="http://www.microformats.org/blog/...">4 Comments</a> | ||
</li> | ||
</ul> | ||
</div> | ||
|
||
<div class="hentry entry" id="post-59"> | ||
</div> | ||
</div> | ||
</div> | ||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!-- http://microformats.org/wiki/hatom-examples --> | ||
<body> | ||
<div id="uf"> | ||
<div class="hfeed"> | ||
<div class="hentry posts" id="112993192128302715"> | ||
<strong class="entry-title entry-content"> | ||
Nelson's final prayer | ||
</strong> | ||
<span class="entry-content"> | ||
written on the night before Trafalgar:<blockquote>May the Great God, ... heart. | ||
</span> | ||
<div> | ||
<span class="byline">posted by <span class="author vcard"><span class="fn">Natalie</span></span> at | ||
<a rel="bookmark" href="2005_10_16_nataliesolent_archive.html#112993192128302715"> | ||
<abbr class="published" title="2005-10-24t09:49:00-00:00">9:49 PM</abbr></a> | ||
</span> | ||
</div> | ||
</div> | ||
|
||
<div class="hentry posts" id="112993022840118939"> | ||
<strong class="heading content>"I really, truly </strong> | ||
<span class="entry-content"> | ||
didn't go ... view. | ||
</span> | ||
<div> | ||
<span class="byline"> | ||
posted by <span class="author vcard"><span class="fn">Natalie</span></span> at | ||
<a rel="bookmark" href="2005_10_16_nataliesolent_archive.html#112993022840118939"> | ||
<abbr class="published" title="2005-10-24t09:49:00-00:00">9:28 pm</abbr></a> | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
require File.join(File.dirname(File.absolute_path(__FILE__)),'..','test_helper') | ||
|
||
class HAtomTest < Test::Unit::TestCase | ||
@@klass = Prism::Microformat::HAtom | ||
|
||
describe 'first example test' do | ||
def self.before_all | ||
@doc ||= test_fixture('hatom/example1.html') | ||
@hatom ||= @@klass.parse(@doc) | ||
end | ||
|
||
setup do | ||
@hatom ||= self.class.before_all | ||
end | ||
|
||
test 'The title is a singular value' do | ||
hentry = @hatom.hentry | ||
assert_equal "Wiki Attack", hentry[0].entry_title | ||
end | ||
|
||
test 'The content contains html' do | ||
hentry = @hatom.hentry | ||
content = <<-EOS | ||
<p>We had a bit of trouble with ...</p> | ||
<p>We've restored the wiki and ...</p> | ||
<p>If anyone is working to combat said spammers ...</p> | ||
EOS | ||
assert_equal content.strip, hentry[0].entry_content | ||
end | ||
|
||
test 'The published is a time' do | ||
hentry = @hatom.hentry | ||
assert_equal Time.parse('2005-10-10 14:07:00 -0700'), hentry[0].published | ||
end | ||
|
||
test 'The author is an hcard' do | ||
hentry = @hatom.hentry | ||
hcard = hentry[0].author | ||
assert_equal Prism::Microformat::HCard, hcard.class | ||
assert_equal 'Ryan King', hcard.fn | ||
assert_equal 'King', hcard.n[:family_name] | ||
assert_equal 'Ryan', hcard.n[:given_name] | ||
assert_equal 'http://theryanking.com/', hcard.url[0] | ||
end | ||
|
||
test 'The tags are a list of values' do | ||
hentry = @hatom.hentry | ||
assert_equal ['mediawiki', 'microformats', 'spam'], hentry[0].tags | ||
end | ||
|
||
end | ||
|
||
describe 'second example test' do | ||
def self.before_all | ||
@doc ||= test_fixture('hatom/example2.html') | ||
@hatom ||= @@klass.parse(@doc) | ||
end | ||
|
||
setup do | ||
@hatom ||= self.class.before_all | ||
end | ||
|
||
test 'The title is a singular value' do | ||
hentry = @hatom.hentry | ||
assert_equal "Nelson's final prayer", hentry[0].entry_title | ||
end | ||
|
||
test 'The content is an html value' do | ||
hentry = @hatom.hentry | ||
assert_equal "Nelson's final prayer", hentry[0].entry_content | ||
end | ||
|
||
test 'The bookmark is a rel-bookmark' do | ||
hentry = @hatom.hentry | ||
assert_equal "2005_10_16_nataliesolent_archive.html#112993192128302715", hentry[0].bookmark | ||
end | ||
|
||
end | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters