diff --git a/lib/microformats2.rb b/lib/microformats2.rb index 642519d..425c5d8 100644 --- a/lib/microformats2.rb +++ b/lib/microformats2.rb @@ -10,9 +10,12 @@ module Microformats2 def self.parse(html) raise LoadError, "argument must be a String or File" unless [String, File].include?(html.class) + html = html.read if IO === html + doc = Nokogiri::HTML(html) microformats = Hash.new{|hash, key| hash[key] = Array.new} - doc.css("*[class^=h-]").each do |microformat| + + doc.css("*[class|=h]").each do |microformat| constant_name = classify(microformat.attribute("class").to_s.gsub("-","_")) if Object.const_defined?(constant_name) @@ -33,7 +36,7 @@ module Microformats2 microformats[constant_name.downcase.to_sym] << obj end - return microformats + microformats end def self.add_method(obj, method_name) diff --git a/test/IndieWebCamp.html b/test/IndieWebCamp.html new file mode 100644 index 0000000..0f74623 --- /dev/null +++ b/test/IndieWebCamp.html @@ -0,0 +1,351 @@ + + + + + + + + + + + + + + + + + IndieWebCamp + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + +
+ + +
+
IndieWebCamp is a 2-day dev camp in Portland, Oregon focused on building a more open Web.
+ + + + + + +
+ + + +
+ +
+ +
+ + +
+
Resources
+ +
+ + + + +
+ + +
+ + +
+ + +

Main Page

+
+
+ +


+

+
+

Contents

+ +
+

[edit] IndieWebCamp

+
+

Rather than posting content on many third-party silos of data, we should all begin owning the data we're creating. Publish short status updates on your own domain, and syndicate to Twitter. Publish photos on your own domain, syndicate to Flickr, etc, etc. +

This is the basis of the "Indie Web" movement (see why for more). We'll get together for a weekend to talk about what has been done in the field, and what still needs to be done. There will be workshops and breakout sessions. +

+
+

Planners: Tantek Çelik, Aaron Parecki, Amber Case, and Crystal Beasley. Want to help? Sign up to volunteer!. +

+

[edit] Session Notes

+

See the Schedule to read and add session notes. Click on the session title to add notes to the page. To see all session notes, see Category:Session Notes +

+

[edit] When

+

IndieWebCamp was on 2011-06-25 and 2011-06-26. See the Schedule for more details. Note: OSBridge was June 21-24 immediately beforehand, consider attending that as well. +

+

[edit] Where

+

Urban Airship, 334 NW 11th Ave., Portland, Oregon. +

Urban Airship is graciously providing the space for IndieWebCamp. +

+

[edit] Travel

+

Flights: If you're flying from the SF/Bay Area to Portland (PDX), Alaska Airlines and Southwest Airlines are recommended and have frequent flights to PDX. +

+

[edit] Who

+

To get on the guest list, log in to this wiki with your personal OpenID and add yourself! +

IndieWebCamp is for active builders only in order to focus the limited time we have on productive real world discussions and code/design/ux sharing that will help us move forward. +

Attendees must have a personal URL enabled with OpenID, or be an apprentice to someone who has one in order to attend. +

+
+

[edit] What

+ +

[edit] Why

+ +

[edit] How

+ +

[edit] More

+ + + + + + + +
+
+
+ +
+
+ + +
+ + + +
+
+ +
+
+ + + + + + +
+
+
+
+ + + + diff --git a/test/test_microformats2.rb b/test/test_microformats2.rb index 694c756..78e1583 100644 --- a/test/test_microformats2.rb +++ b/test/test_microformats2.rb @@ -7,12 +7,12 @@ class TestMicroformats2 < Test::Unit::TestCase Microformats2.parse(nil) end end - + def test_returns_hash_of_microformat_objects result = Microformats2.parse("A String") assert_equal Hash, result.class end - + def test_only_parse_microformats result = Microformats2.parse("

Something

") assert_equal 0, result.size @@ -30,8 +30,10 @@ class TestMicroformats2 < Test::Unit::TestCase END + result = Microformats2.parse(File.open(File.join(File.dirname(__FILE__), "simple.html"))) assert_equal HCard, result[:hcard].first.class + assert_equal 2, result[:hcard].length end def test_extracts_hcard_from_html @@ -40,7 +42,7 @@ class TestMicroformats2 < Test::Unit::TestCase Simple hCard - +

Chris

@@ -49,14 +51,14 @@ class TestMicroformats2 < Test::Unit::TestCase result = Microformats2.parse(hcard) assert_equal HCard, result[:hcard].first.class end - + def test_constructs_properties_from_hcard hcard = <<-END Simple hCard - +

@@ -70,20 +72,20 @@ class TestMicroformats2 < Test::Unit::TestCase END result = Microformats2.parse(hcard) mycard = result[:hcard].first - + assert_equal "Chris", mycard.given_name assert_equal "R.", mycard.additional_name assert_equal "Messina", mycard.family_name assert_equal "Chris R. Messina", mycard.fn end - + def test_constructs_dates hcard = <<-END Simple hCard - +

1979-09-18 @@ -94,18 +96,18 @@ class TestMicroformats2 < Test::Unit::TestCase END result = Microformats2.parse(hcard) mycard = result[:hcard].first - + assert_equal DateTime.parse("1979-09-18"), mycard.bday assert_equal DateTime.parse("1970-01-01"), mycard.epoch end - + def test_constructs_times hcard = <<-END Simple hCard - +

09:30 @@ -116,18 +118,18 @@ class TestMicroformats2 < Test::Unit::TestCase END result = Microformats2.parse(hcard) mycard = result[:hcard].first - + assert_equal Time.parse("09:30"), mycard.start assert_equal Time.parse("06:00"), mycard.end end - + def test_ignores_pattern_matches_not_at_the_beginning_of_class hcard = <<-END Simple hCard - +

Chris @@ -137,18 +139,18 @@ class TestMicroformats2 < Test::Unit::TestCase END result = Microformats2.parse(hcard) mycard = result[:hcard].first - + assert_equal "Chris", mycard.n_x assert mycard.n_x.is_a?(String) end - + def test_constructs_urls_from_hcard hcard = <<-END Simple hCard - +

Chris