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 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
@@ -1,7 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
3
 
4
- version = '0.2.4'
4
+ version = '0.2.5'
5
5
  svn_repo = 'svn+ssh://chris@errtheblog.com/svn/projects/mofo'
6
6
 
7
7
  begin
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
@@ -22,7 +22,10 @@ class XFN < Microformat
22
22
  attr_accessor :links
23
23
 
24
24
  def self.find_occurences(doc)
25
- @occurences ||= XFN.new(doc)
25
+ case doc
26
+ when Hpricot::Doc then @occurences = XFN.new(doc)
27
+ else @occurences
28
+ end
26
29
  end
27
30
 
28
31
  class << self
data/site/index.html CHANGED
@@ -62,7 +62,7 @@ $ sudo gem install mofo -y
62
62
  $ irb -rubygems
63
63
  &gt;&gt; require 'mofo'
64
64
  =&gt; true
65
- &gt;&gt; fireball = HCard.find 'http://flickr.com/people/gruber/'
65
+ &gt;&gt; fireball = hCard.find 'http://flickr.com/people/gruber/'
66
66
  =&gt; #&lt;HCard:0x6db898 ...&gt;
67
67
  &gt;&gt; fireball.properties
68
68
  =&gt; ["fn", "logo", "url", "n", "adr", "title", "nickname"]
@@ -147,7 +147,7 @@ How'd we parse this, tho?
147
147
  $ irb -rubygems
148
148
  &gt;&gt; require 'mofo'
149
149
  =&gt; true
150
- &gt;&gt; post = HEntry.find 'http://milesofstyle.org/posts/351-megadeth-show-last-night'
150
+ &gt;&gt; post = hEntry.find 'http://milesofstyle.org/posts/351-megadeth-show-last-night'
151
151
  =&gt; #&lt;HEntry:0x6db898 ... &gt;
152
152
  &gt;&gt; post.entry_title
153
153
  =&gt; "Megadeth Show Last Night"
@@ -165,7 +165,7 @@ $ irb -rubygems
165
165
  =&gt; "Went to a show last night. Megadeth. It was alright."
166
166
  </pre>
167
167
  <p>
168
- That's, like, stupid easy. If HEntry.find gets back more than one hEntry, you'll get an array.
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
- &gt;&gt; messina = HCard.find 'http://www.flickr.com/people/factoryjoe/'
209
+ &gt;&gt; messina = hCard.find 'http://www.flickr.com/people/factoryjoe/'
210
210
  =&gt; #&lt;HCard:0x125eb5c ...&gt;
211
211
  &gt;&gt; messina.properties
212
212
  =&gt; ["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
- &gt;&gt; events = HCalendar.find 'http://upcoming.org'
229
+ &gt;&gt; events = hCalendar.find 'http://upcoming.org'
230
230
  =&gt; [#&lt;HCalendar:0x131d304 ...&gt; ... ]
231
231
  &gt;&gt; events.size
232
232
  =&gt; 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
- &gt;&gt; wine = HReview.find 'http://corkd.com/wine/view/1772'
243
+ &gt;&gt; wine = hReview.find 'http://corkd.com/wine/view/1772'
244
244
  =&gt; [#&lt;HReview:0x156c3f8 ...&gt; ...]
245
245
  &gt;&gt; wine.size
246
246
  =&gt; 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
- &gt;&gt; post = HEntry.find 'http://errtheblog.com'
259
+ &gt;&gt; post = hEntry.find 'http://errtheblog.com'
260
260
  =&gt; #&lt;HEntry:0x169309c ...&gt;
261
261
  &gt;&gt; post.properties
262
262
  =&gt; ["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
- &gt;&gt; crunch = HResume.find 'http://www.linkedin.com/in/michaelarrington'
275
+ &gt;&gt; crunch = hResume.find 'http://www.linkedin.com/in/michaelarrington'
276
276
  =&gt; #&lt;HResume:0x129d370 ...&gt;
277
277
  &gt;&gt; crunch.properties
278
278
  =&gt; ["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/trunk vendor/plugins/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/trunk
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/mofo/browser">http://require.errtheblog.com/mofo/browser</a></li>
368
- <li>SVN: svn://errtheblog.com/svn/mofo/trunk</li>
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[one two]
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.4
7
- date: 2007-04-30 00:00:00 -07:00
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