diff --git a/History.txt b/History.txt deleted file mode 100644 index 0958a24..0000000 --- a/History.txt +++ /dev/null @@ -1,19 +0,0 @@ -=== 1.0.2 / 2011-06-28 - -* 2 bug fix - - * parse d-duration as a string not a date - * change "class" to "klass" on elements with "class='p-class'" - -=== 1.0.1 / 2011-06-28 - -* 1 bug fix - - * fixed duplicate microformat problem - -=== 1.0.0 / 2011-06-14 - -* 1 major enhancement - - * Birthday! - diff --git a/Manifest.txt b/Manifest.txt deleted file mode 100644 index d2d8c5b..0000000 --- a/Manifest.txt +++ /dev/null @@ -1,10 +0,0 @@ -.autotest -History.txt -Manifest.txt -README.md -Rakefile -bin/microformats2 -lib/microformats2.rb -test/test_microformats2.rb -test/simple.html -test/IndieWebCamp.html diff --git a/README.md b/README.md index 0f72d75..e32a74c 100644 --- a/README.md +++ b/README.md @@ -1,52 +1,6 @@ +# Microformats # MOVED! For all future versions, go to: + **https://github.com/G5/microformats2** - - - - - -# Microformats - -http://github.com/veganstraightedge/microformats2 - -## DESCRIPTION - -Generic Microformats 2 Extractor - -## FEATURES/PROBLEMS - -* parses and extracts [Microformats 2](http://microformats.org/wiki/microformats-2) syntax -* needs more test cases -* needs better docs -* needs to deal with nested microformats -* needs to deal with class-value pattern - -## SYNOPSIS - - Microformats2.parse(File.open("example.html")) - -## REQUIREMENTS - -* Hoe -* Nokogiri - -## INSTALL - - sudo gem install microformats2 - -## DEVELOPERS - -After checking out the source, run: - - rake newb - -This task will install any missing dependencies, -run the tests/specs, and generate the RDoc. - -## LICENSE - -**PUBLIC DOMAIN.** -Your heart is as free as the air you breathe. -The ground you stand on is liberated territory. diff --git a/Rakefile b/Rakefile deleted file mode 100644 index 2b4a243..0000000 --- a/Rakefile +++ /dev/null @@ -1,13 +0,0 @@ -# -*- ruby -*- - -require 'rubygems' -require 'hoe' - -Hoe.spec 'microformats2' do - developer('Shane Becker', 'veganstraightedge@gmail.com') - extra_deps << ['nokogiri', ">= 0"] - self.readme_file = "README.md" -end - - -# vim: syntax=ruby diff --git a/bin/microformats2 b/bin/microformats2 deleted file mode 100755 index 1b4eff8..0000000 --- a/bin/microformats2 +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env ruby - -abort "you need to write me" diff --git a/lib/microformats2.rb b/lib/microformats2.rb deleted file mode 100644 index db3d05c..0000000 --- a/lib/microformats2.rb +++ /dev/null @@ -1,121 +0,0 @@ -require 'nokogiri' -require 'time' -require 'date' - -module Microformats2 - VERSION = "1.0.2" - - class LoadError < StandardError; end - - 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| - microformat.attribute("class").to_s.split.each do |mf_class| - if mf_class =~ /^h-/ - constant_name = mf_class.gsub("-","_").gsub(/^([a-z])/){$1.upcase}.gsub(/_(.)/) { $1.upcase } - - if Object.const_defined?(constant_name) - klass = Object.const_get(constant_name) - else - klass = Class.new - Object.const_set constant_name, klass - end - - obj = klass.new - - add_properties(microformat, obj) - - microformats[constant_name.downcase.to_sym] << obj - end - end - end - - microformats - end - - def self.add_method(obj, method_name) - unless obj.respond_to?(method_name) - obj.class.class_eval { attr_accessor method_name } - end - - obj - end - - def self.populate_method(obj, method_name, value) - if cur = obj.send(method_name) - if cur.kind_of? Array - cur << value - else - obj.send("#{method_name}=", [cur, value]) - end - else - obj.send("#{method_name}=", value) - end - end - - class Stripper - def transform(property) - property.text.gsub(/\n+/, " ").gsub(/\s+/, " ").strip - end - end - - class URL - def transform(property) - (property.attribute("href") || property.text).to_s - end - end - - class Date - def transform(property) - value = (property.attribute("title") || property.text).to_s - - if value[0..0] =~ /[a-zA-Z]/ - value - else - DateTime.parse(value) - end - end - end - - class TimeThingy - def transform(property) - Time.parse((property.attribute("title") || property.text).to_s) - end - end - - FormatClass = { - "p" => Stripper.new, - "n" => Stripper.new, - "e" => Stripper.new, - "i" => Stripper.new, - "u" => URL.new, - "d" => Date.new, - "t" => TimeThingy.new - } - - def self.add_properties(mf, obj) - FormatClass.each do |letter, trans| - mf.css("*[class*=#{letter}-]").each do |property| - property.attribute("class").to_s.split.each do |css_class| - if css_class[0..1] == "#{letter}-" - css_class = css_class[2..-1].gsub("-","_") - method_name = css_class.gsub("-","_") - value = trans.transform(property) - - if method_name == "class" - method_name = "klass" - end - - add_method(obj, method_name) - populate_method(obj, method_name, value) - end - end - end - end - end -end diff --git a/test/IndieWebCamp.html b/test/IndieWebCamp.html deleted file mode 100644 index 0f74623..0000000 --- a/test/IndieWebCamp.html +++ /dev/null @@ -1,351 +0,0 @@ - - - - - - - - - - - - - - - - - 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/hcalendar.html b/test/hcalendar.html deleted file mode 100644 index 1de7334..0000000 --- a/test/hcalendar.html +++ /dev/null @@ -1,43 +0,0 @@ - - - - -hCalendar test - - - -
-

Barcamp Brighton 1

- -
- 2 day event. -
-
- 8 - - 9 September 2007 -
-
Loaction: Madgex Office, Brighton
-
Barcamp is an ad-hoc gathering born from the desire to share and learn in an open environment.
- - http://www.barcampbrighton.org/ -
This meeting is public.
- -
Created: 1 May 2007
-
Last modified: 2 May 2007
- -
Ref: guid1.example.com
-
Status: Confirmed
- Northern California - -
- Contact: John Doe -
- -
- Managed by: Example Company -
- -
- - - \ No newline at end of file diff --git a/test/simple.html b/test/simple.html deleted file mode 100644 index 714e942..0000000 --- a/test/simple.html +++ /dev/null @@ -1,30 +0,0 @@ - - - Simple hCard - - - -

- - Chris - R. - Messina - -

- -

- - Shane - B - Becker - -

- -

- - Breakfast - Cereal - -

- - diff --git a/test/test_microformats2.rb b/test/test_microformats2.rb deleted file mode 100644 index 5cfbfdb..0000000 --- a/test/test_microformats2.rb +++ /dev/null @@ -1,185 +0,0 @@ -require "test/unit" -require "microformats2" - -class TestMicroformats2 < Test::Unit::TestCase - def test_throw_exception_on_non_string_params - assert_raise Microformats2::LoadError do - 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 - end - - def test_extracts_hcard_from_an_html_file - 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_name_from_tag_with_multiple_classes - result = Microformats2.parse(File.open(File.join(File.dirname(__FILE__), "simple.html"))) - assert_equal "Chris", result[:hcard].first.given_name - end - - def test_extracts_hcalendar_from_an_indiewebcamp_html_file - result = Microformats2.parse(File.open(File.join(File.dirname(__FILE__), "IndieWebCamp.html"))) - assert_equal 1, result[:hevent].length - assert result[:hcard].map { |h| h.name }.include?("Urban Airship") - end - - def test_extracts_dates_in_an_hcalendar_from_an_html_file - result = Microformats2.parse(File.open(File.join(File.dirname(__FILE__), "hcalendar.html"))) - assert_equal result[:hevent].first.dtstart, DateTime.parse("2007-09-08") - end - - def test_extracts_date_durations_as_a_string_from_an_html_file - result = Microformats2.parse(File.open(File.join(File.dirname(__FILE__), "hcalendar.html"))) - assert_equal result[:hevent].first.duration, "P2D" - end - - def test_turns_class_values_of_class_to_klass_from_an_html_file - result = Microformats2.parse(File.open(File.join(File.dirname(__FILE__), "hcalendar.html"))) - assert_equal result[:hevent].first.klass, "public" - end - - def test_extracts_hcalendar_from_an_html_file - result = Microformats2.parse(File.open(File.join(File.dirname(__FILE__), "IndieWebCamp.html"))) - assert_equal 1, result[:hevent].length - assert result[:hcard].map { |h| h.name }.include?("Urban Airship") - end - - def test_extracts_hcard_from_html - hcard = <<-END - - - Simple hCard - - - -

Chris

- - - END - result = Microformats2.parse(hcard) - assert_equal HCard, result[:hcard].first.class - end - - def test_constructs_properties_from_hcard - hcard = <<-END - - - Simple hCard - - - -

- - Chris - R. - Messina - -

- - - 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 - EPOCH! -

- - - 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 - Leaving time -

- - - 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 -

- - - 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 -

- - - END - result = Microformats2.parse(hcard) - mycard = result[:hcard].first - assert_equal "http://factoryjoe.com/", mycard.url - end -end