microformats2 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +13 -0
- data/README.md +2 -0
- data/lib/microformats2.rb +13 -3
- data/test/test_microformats2.rb +21 -0
- metadata +3 -3
data/History.txt
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
=== 1.0.2 / 2011-06-28
|
2
|
+
|
3
|
+
* 2 bug fix
|
4
|
+
|
5
|
+
* parse d-duration as a string not a date
|
6
|
+
* change "class" to "klass" on elements with "class='p-class'"
|
7
|
+
|
8
|
+
=== 1.0.1 / 2011-06-28
|
9
|
+
|
10
|
+
* 1 bug fix
|
11
|
+
|
12
|
+
* fixed duplicate microformat problem
|
13
|
+
|
1
14
|
=== 1.0.0 / 2011-06-14
|
2
15
|
|
3
16
|
* 1 major enhancement
|
data/README.md
CHANGED
@@ -11,6 +11,8 @@ Generic Microformats 2 Extractor
|
|
11
11
|
* parses and extracts [Microformats 2](http://microformats.org/wiki/microformats-2) syntax
|
12
12
|
* needs more test cases
|
13
13
|
* needs better docs
|
14
|
+
* needs to deal with nested microformats
|
15
|
+
* needs to deal with class-value pattern
|
14
16
|
|
15
17
|
## SYNOPSIS
|
16
18
|
|
data/lib/microformats2.rb
CHANGED
@@ -3,7 +3,7 @@ require 'time'
|
|
3
3
|
require 'date'
|
4
4
|
|
5
5
|
module Microformats2
|
6
|
-
VERSION = "1.0.
|
6
|
+
VERSION = "1.0.2"
|
7
7
|
|
8
8
|
class LoadError < StandardError; end
|
9
9
|
|
@@ -66,13 +66,19 @@ module Microformats2
|
|
66
66
|
|
67
67
|
class URL
|
68
68
|
def transform(property)
|
69
|
-
property.attribute("href").to_s
|
69
|
+
(property.attribute("href") || property.text).to_s
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
73
|
class Date
|
74
74
|
def transform(property)
|
75
|
-
|
75
|
+
value = (property.attribute("title") || property.text).to_s
|
76
|
+
|
77
|
+
if value[0..0] =~ /[a-zA-Z]/
|
78
|
+
value
|
79
|
+
else
|
80
|
+
DateTime.parse(value)
|
81
|
+
end
|
76
82
|
end
|
77
83
|
end
|
78
84
|
|
@@ -100,6 +106,10 @@ module Microformats2
|
|
100
106
|
css_class = css_class[2..-1].gsub("-","_")
|
101
107
|
method_name = css_class.gsub("-","_")
|
102
108
|
value = trans.transform(property)
|
109
|
+
|
110
|
+
if method_name == "class"
|
111
|
+
method_name = "klass"
|
112
|
+
end
|
103
113
|
|
104
114
|
add_method(obj, method_name)
|
105
115
|
populate_method(obj, method_name, value)
|
data/test/test_microformats2.rb
CHANGED
@@ -29,6 +29,27 @@ class TestMicroformats2 < Test::Unit::TestCase
|
|
29
29
|
assert_equal "Chris", result[:hcard].first.given_name
|
30
30
|
end
|
31
31
|
|
32
|
+
def test_extracts_hcalendar_from_an_indiewebcamp_html_file
|
33
|
+
result = Microformats2.parse(File.open(File.join(File.dirname(__FILE__), "IndieWebCamp.html")))
|
34
|
+
assert_equal 1, result[:hevent].length
|
35
|
+
assert result[:hcard].map { |h| h.name }.include?("Urban Airship")
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_extracts_dates_in_an_hcalendar_from_an_html_file
|
39
|
+
result = Microformats2.parse(File.open(File.join(File.dirname(__FILE__), "hcalendar.html")))
|
40
|
+
assert_equal result[:hevent].first.dtstart, DateTime.parse("2007-09-08")
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_extracts_date_durations_as_a_string_from_an_html_file
|
44
|
+
result = Microformats2.parse(File.open(File.join(File.dirname(__FILE__), "hcalendar.html")))
|
45
|
+
assert_equal result[:hevent].first.duration, "P2D"
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_turns_class_values_of_class_to_klass_from_an_html_file
|
49
|
+
result = Microformats2.parse(File.open(File.join(File.dirname(__FILE__), "hcalendar.html")))
|
50
|
+
assert_equal result[:hevent].first.klass, "public"
|
51
|
+
end
|
52
|
+
|
32
53
|
def test_extracts_hcalendar_from_an_html_file
|
33
54
|
result = Microformats2.parse(File.open(File.join(File.dirname(__FILE__), "IndieWebCamp.html")))
|
34
55
|
assert_equal 1, result[:hevent].length
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: microformats2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 2
|
10
|
+
version: 1.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Shane Becker
|