mofo 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +8 -0
- data/Rakefile +1 -1
- data/lib/microformat.rb +19 -1
- data/lib/mofo/xfn.rb +4 -1
- data/site/index.html +12 -12
- data/test/ext_test.rb +24 -1
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
= 0.2.5
|
2
|
+
- Added ability to find ALL microformats on a page using Microformat.find.
|
3
|
+
Only searches using loaded microformat classes, so make sure to just require 'mofo'
|
4
|
+
- Added cute aliases for H* classes, e.g. hCard.find(:first => 'url') and hResume.find('resume.html')
|
5
|
+
|
6
|
+
= 0.2.4
|
7
|
+
- Fixed mofo to not choke on broken URL attributes
|
8
|
+
|
1
9
|
= 0.2.3
|
2
10
|
- Moved to Echoe
|
3
11
|
- Added feature of figuring out the base URL for relative URLs
|
data/Rakefile
CHANGED
data/lib/microformat.rb
CHANGED
@@ -1,12 +1,16 @@
|
|
1
|
-
%w(rubygems hpricot microformat/string microformat/array open-uri ostruct timeout).each { |f| require f }
|
1
|
+
%w(rubygems set hpricot microformat/string microformat/array open-uri ostruct timeout).each { |f| require f }
|
2
2
|
gem 'hpricot', '>=0.4.59'
|
3
3
|
|
4
4
|
class Microformat
|
5
5
|
module Base
|
6
|
+
@@subclasses = Set.new
|
7
|
+
|
6
8
|
##
|
7
9
|
# The Gateway
|
8
10
|
#
|
9
11
|
def find(*args)
|
12
|
+
return find_in_children(*args) if self == Microformat
|
13
|
+
|
10
14
|
target, @options = args
|
11
15
|
@options ||= target.is_a?(Hash) ? target : {}
|
12
16
|
[:first, :all].each { |key| target = @options[key] if @options[key] }
|
@@ -31,6 +35,13 @@ class Microformat
|
|
31
35
|
end
|
32
36
|
end
|
33
37
|
|
38
|
+
def find_in_children(*args)
|
39
|
+
@@subclasses.map do |klass|
|
40
|
+
klass.find(*args)
|
41
|
+
end.flatten
|
42
|
+
end
|
43
|
+
|
44
|
+
# i have no idea what the hell this is doing
|
34
45
|
names_and_keys = proc do |attributes|
|
35
46
|
attributes.map do |att|
|
36
47
|
att.respond_to?(:keys) ? att.keys.first : att
|
@@ -59,10 +70,17 @@ class Microformat
|
|
59
70
|
alias :after_finds :after_find
|
60
71
|
|
61
72
|
def inherited(klass)
|
73
|
+
@@subclasses << klass
|
74
|
+
define_cute_class_name(klass)
|
62
75
|
klass.instance_variable_set(:@container, klass.name.downcase)
|
63
76
|
klass.instance_variable_set(:@attributes, Hash.new([]))
|
64
77
|
end
|
65
78
|
|
79
|
+
def define_cute_class_name(klass)
|
80
|
+
return unless (name = klass.name) =~ /^H/
|
81
|
+
Object.send(:define_method, name.sub(/^H/, 'h')) { klass }
|
82
|
+
end
|
83
|
+
|
66
84
|
def collector
|
67
85
|
collector = Hash.new([])
|
68
86
|
def collector.method_missing(method, *classes)
|
data/lib/mofo/xfn.rb
CHANGED
data/site/index.html
CHANGED
@@ -62,7 +62,7 @@ $ sudo gem install mofo -y
|
|
62
62
|
$ irb -rubygems
|
63
63
|
>> require 'mofo'
|
64
64
|
=> true
|
65
|
-
>> fireball =
|
65
|
+
>> fireball = hCard.find 'http://flickr.com/people/gruber/'
|
66
66
|
=> #<HCard:0x6db898 ...>
|
67
67
|
>> fireball.properties
|
68
68
|
=> ["fn", "logo", "url", "n", "adr", "title", "nickname"]
|
@@ -147,7 +147,7 @@ How'd we parse this, tho?
|
|
147
147
|
$ irb -rubygems
|
148
148
|
>> require 'mofo'
|
149
149
|
=> true
|
150
|
-
>> post =
|
150
|
+
>> post = hEntry.find 'http://milesofstyle.org/posts/351-megadeth-show-last-night'
|
151
151
|
=> #<HEntry:0x6db898 ... >
|
152
152
|
>> post.entry_title
|
153
153
|
=> "Megadeth Show Last Night"
|
@@ -165,7 +165,7 @@ $ irb -rubygems
|
|
165
165
|
=> "Went to a show last night. Megadeth. It was alright."
|
166
166
|
</pre>
|
167
167
|
<p>
|
168
|
-
That's, like, stupid easy. If
|
168
|
+
That's, like, stupid easy. If hEntry.find gets back more than one hEntry, you'll get an array.
|
169
169
|
</p>
|
170
170
|
|
171
171
|
<h3 id="find">Mofo#find</h3>
|
@@ -206,7 +206,7 @@ That's it.
|
|
206
206
|
|
207
207
|
<p><strong>hCard</strong> - <a href="http://microformats.org/wiki/hcard">http://microformats.org/wiki/hcard</a></p>
|
208
208
|
<pre>
|
209
|
-
>> messina =
|
209
|
+
>> messina = hCard.find 'http://www.flickr.com/people/factoryjoe/'
|
210
210
|
=> #<HCard:0x125eb5c ...>
|
211
211
|
>> messina.properties
|
212
212
|
=> ["fn", "note", "logo", "url", "n", "adr", "title", "nickname"]
|
@@ -226,7 +226,7 @@ That's it.
|
|
226
226
|
|
227
227
|
<p><strong>hCalendar</strong> - <a href="http://microformats.org/wiki/hcalendar">http://microformats.org/wiki/hcalendar</a></p>
|
228
228
|
<pre>
|
229
|
-
>> events =
|
229
|
+
>> events = hCalendar.find 'http://upcoming.org'
|
230
230
|
=> [#<HCalendar:0x131d304 ...> ... ]
|
231
231
|
>> events.size
|
232
232
|
=> 17
|
@@ -240,7 +240,7 @@ That's it.
|
|
240
240
|
|
241
241
|
<p><strong>hReview</strong> - <a href="http://microformats.org/wiki/hreview">http://microformats.org/wiki/hreview</a></p>
|
242
242
|
<pre>
|
243
|
-
>> wine =
|
243
|
+
>> wine = hReview.find 'http://corkd.com/wine/view/1772'
|
244
244
|
=> [#<HReview:0x156c3f8 ...> ...]
|
245
245
|
>> wine.size
|
246
246
|
=> 7
|
@@ -256,7 +256,7 @@ That's it.
|
|
256
256
|
|
257
257
|
<p><strong>hEntry</strong> - <a href="http://microformats.org/wiki/hatom">http://microformats.org/wiki/hatom</a></p>
|
258
258
|
<pre>
|
259
|
-
>> post =
|
259
|
+
>> post = hEntry.find 'http://errtheblog.com'
|
260
260
|
=> #<HEntry:0x169309c ...>
|
261
261
|
>> post.properties
|
262
262
|
=> ["published", "entry_title", "author", "entry_content", "bookmark", "tags"]
|
@@ -272,7 +272,7 @@ That's it.
|
|
272
272
|
|
273
273
|
<p><strong>hResume</strong> - <a href="http://microformats.org/wiki/hresume">http://microformats.org/wiki/hresume</a></p>
|
274
274
|
<pre>
|
275
|
-
>> crunch =
|
275
|
+
>> crunch = hResume.find 'http://www.linkedin.com/in/michaelarrington'
|
276
276
|
=> #<HResume:0x129d370 ...>
|
277
277
|
>> crunch.properties
|
278
278
|
=> ["summary", "education", "experience", "contact"]
|
@@ -349,7 +349,7 @@ Install with <a href="http://www.rubyinside.com/advent2006/12-piston.html">Pisto
|
|
349
349
|
</p>
|
350
350
|
|
351
351
|
<pre>
|
352
|
-
$ piston import svn://errtheblog.com/svn/mofo
|
352
|
+
$ piston import svn://errtheblog.com/svn/projects/mofo vendor/plugins/mofo
|
353
353
|
</pre>
|
354
354
|
|
355
355
|
<p>
|
@@ -357,15 +357,15 @@ Install with SVN:
|
|
357
357
|
</p>
|
358
358
|
|
359
359
|
<pre>
|
360
|
-
$ ./script/plugin install -x svn://errtheblog.com/svn/mofo
|
360
|
+
$ ./script/plugin install -x svn://errtheblog.com/svn/projects/mofo
|
361
361
|
</pre>
|
362
362
|
|
363
363
|
<h3 id="touch">Get in Touch</h3>
|
364
364
|
|
365
365
|
<ul>
|
366
366
|
<li>Me: chris[at]ozmm[dot]org (chris wanstrath)</li>
|
367
|
-
<li>Trac: <a href="http://require.errtheblog.com/
|
368
|
-
<li>SVN: svn://errtheblog.com/svn/mofo
|
367
|
+
<li>Trac: <a href="http://require.errtheblog.com/projects/browser/mofo">http://require.errtheblog.com/projects/browser/mofo</a></li>
|
368
|
+
<li>SVN: svn://errtheblog.com/svn/projects/mofo</li>
|
369
369
|
</ul>
|
370
370
|
</div>
|
371
371
|
|
data/test/ext_test.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper'
|
2
2
|
require 'microformat/string'
|
3
3
|
require 'microformat/array'
|
4
|
+
require 'mofo/hcard'
|
5
|
+
require 'mofo/hcalendar'
|
6
|
+
require 'mofo/hentry'
|
4
7
|
|
5
8
|
context "A string should be coercable into" do
|
6
9
|
specify "an integer" do
|
@@ -32,7 +35,7 @@ end
|
|
32
35
|
|
33
36
|
context "An array sent first_or_self" do
|
34
37
|
setup do
|
35
|
-
@array = %w
|
38
|
+
@array = %w(one two)
|
36
39
|
end
|
37
40
|
|
38
41
|
specify "should return itself if it has more than one element" do
|
@@ -44,3 +47,23 @@ context "An array sent first_or_self" do
|
|
44
47
|
@array.first_or_self.should.be.an.instance_of String
|
45
48
|
end
|
46
49
|
end
|
50
|
+
|
51
|
+
context "Any defined h* microformat" do
|
52
|
+
specify "should have a lowercase h* method, for fun" do
|
53
|
+
hCard.should.equal HCard
|
54
|
+
hCalendar.should.equal HCalendar
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "Searching a page with multiple uformats using Microformat.find" do
|
59
|
+
setup do
|
60
|
+
$multi_formats ||= Microformat.find(fixture(:chowhound))
|
61
|
+
end
|
62
|
+
|
63
|
+
specify "should find all the instances of the different microformats" do
|
64
|
+
$multi_formats.should.be.an.instance_of Array
|
65
|
+
classes = $multi_formats.map { |i| i.class }
|
66
|
+
classes.should.include HEntry
|
67
|
+
classes.should.include HCard
|
68
|
+
end
|
69
|
+
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: mofo
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.2.5
|
7
|
+
date: 2007-05-07 00:00:00 -07:00
|
8
8
|
summary: mofo is a ruby microformat parser
|
9
9
|
require_paths:
|
10
10
|
- lib
|