microformats2 1.0.2 → 2.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. data/.gitignore +18 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +8 -0
  4. data/Gemfile +4 -0
  5. data/Guardfile +5 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +117 -26
  8. data/Rakefile +65 -9
  9. data/lib/microformats2.rb +30 -115
  10. data/lib/microformats2/collection.rb +71 -0
  11. data/lib/microformats2/format.rb +101 -0
  12. data/lib/microformats2/format_parser.rb +59 -0
  13. data/lib/microformats2/implied_property/foundation.rb +58 -0
  14. data/lib/microformats2/implied_property/name.rb +34 -0
  15. data/lib/microformats2/implied_property/photo.rb +24 -0
  16. data/lib/microformats2/implied_property/url.rb +20 -0
  17. data/lib/microformats2/property.rb +10 -0
  18. data/lib/microformats2/property/date_time.rb +31 -0
  19. data/lib/microformats2/property/embedded.rb +9 -0
  20. data/lib/microformats2/property/foundation.rb +80 -0
  21. data/lib/microformats2/property/text.rb +16 -0
  22. data/lib/microformats2/property/url.rb +18 -0
  23. data/lib/microformats2/property_parser.rb +54 -0
  24. data/lib/microformats2/version.rb +3 -0
  25. data/microformats2.gemspec +30 -0
  26. data/spec/lib/microformats2/collection_spec.rb +181 -0
  27. data/spec/lib/microformats2/implied_property/name_spec.rb +31 -0
  28. data/spec/lib/microformats2/implied_property/photo_spec.rb +31 -0
  29. data/spec/lib/microformats2/implied_property/url_spec.rb +31 -0
  30. data/spec/lib/microformats2_spec.rb +30 -0
  31. data/spec/spec_helper.rb +10 -0
  32. data/spec/support/cases/microformat2-node.jit.su/h-adr/h-adr-0.html +3 -0
  33. data/spec/support/cases/microformat2-node.jit.su/h-adr/h-adr-0.js +10 -0
  34. data/spec/support/cases/microformat2-node.jit.su/h-adr/h-adr-1.html +10 -0
  35. data/spec/support/cases/microformat2-node.jit.su/h-adr/h-adr-1.js +16 -0
  36. data/spec/support/cases/microformat2-node.jit.su/h-adr/h-adr-2.html +12 -0
  37. data/spec/support/cases/microformat2-node.jit.su/h-adr/h-adr-2.js +16 -0
  38. data/spec/support/cases/microformat2-node.jit.su/h-adr/h-adr-3.html +6 -0
  39. data/spec/support/cases/microformat2-node.jit.su/h-adr/h-adr-3.js +12 -0
  40. data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-0.html +3 -0
  41. data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-0.js +10 -0
  42. data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-1.html +3 -0
  43. data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-1.js +11 -0
  44. data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-2.html +4 -0
  45. data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-2.js +12 -0
  46. data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-3.html +11 -0
  47. data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-3.js +15 -0
  48. data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-4.html +6 -0
  49. data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-4.js +26 -0
  50. data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-5.html +6 -0
  51. data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-5.js +30 -0
  52. data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-6.html +6 -0
  53. data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-6.js +29 -0
  54. data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-7.html +16 -0
  55. data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-7.js +15 -0
  56. data/spec/support/cases/microformat2-node.jit.su/h-entry/h-entry-0.html +4 -0
  57. data/spec/support/cases/microformat2-node.jit.su/h-entry/h-entry-0.js +10 -0
  58. data/spec/support/cases/microformat2-node.jit.su/h-entry/h-entry-1.html +3 -0
  59. data/spec/support/cases/microformat2-node.jit.su/h-entry/h-entry-1.js +11 -0
  60. data/spec/support/cases/microformat2-node.jit.su/h-entry/h-entry-2.html +21 -0
  61. data/spec/support/cases/microformat2-node.jit.su/h-entry/h-entry-2.js +28 -0
  62. data/spec/support/cases/microformat2-node.jit.su/h-entry/h-entry-3.html +22 -0
  63. data/spec/support/cases/microformat2-node.jit.su/h-entry/h-entry-3.js +21 -0
  64. data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-0.html +3 -0
  65. data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-0.js +10 -0
  66. data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-1.html +3 -0
  67. data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-1.js +11 -0
  68. data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-2.html +14 -0
  69. data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-2.js +57 -0
  70. data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-3.html +15 -0
  71. data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-3.js +35 -0
  72. data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-4.html +9 -0
  73. data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-4.js +12 -0
  74. data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-5.html +45 -0
  75. data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-5.js +22 -0
  76. data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-6.html +51 -0
  77. data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-6.js +21 -0
  78. data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-7.html +22 -0
  79. data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-7.js +20 -0
  80. data/spec/support/cases/microformat2-node.jit.su/h-geo/h-geo-0.html +5 -0
  81. data/spec/support/cases/microformat2-node.jit.su/h-geo/h-geo-0.js +10 -0
  82. data/spec/support/cases/microformat2-node.jit.su/h-geo/h-geo-1.html +7 -0
  83. data/spec/support/cases/microformat2-node.jit.su/h-geo/h-geo-1.js +12 -0
  84. data/spec/support/cases/microformat2-node.jit.su/h-geo/h-geo-2.html +10 -0
  85. data/spec/support/cases/microformat2-node.jit.su/h-geo/h-geo-2.js +13 -0
  86. data/spec/support/cases/microformat2-node.jit.su/h-geo/h-geo-3.html +12 -0
  87. data/spec/support/cases/microformat2-node.jit.su/h-geo/h-geo-3.js +12 -0
  88. data/spec/support/cases/microformat2-node.jit.su/h-geo/h-geo-4.html +12 -0
  89. data/spec/support/cases/microformat2-node.jit.su/h-geo/h-geo-4.js +12 -0
  90. data/spec/support/cases/microformat2-node.jit.su/h-geo/h-geo-5.html +6 -0
  91. data/spec/support/cases/microformat2-node.jit.su/h-geo/h-geo-5.js +12 -0
  92. data/spec/support/cases/microformat2-node.jit.su/h-news/h-news-0.html +26 -0
  93. data/spec/support/cases/microformat2-node.jit.su/h-news/h-news-0.js +37 -0
  94. data/spec/support/cases/microformat2-node.jit.su/h-news/h-news-1.html +37 -0
  95. data/spec/support/cases/microformat2-node.jit.su/h-news/h-news-1.js +48 -0
  96. data/spec/support/cases/microformat2-node.jit.su/h-org/h-org-0.html +3 -0
  97. data/spec/support/cases/microformat2-node.jit.su/h-org/h-org-0.js +10 -0
  98. data/spec/support/cases/microformat2-node.jit.su/h-org/h-org-1.html +3 -0
  99. data/spec/support/cases/microformat2-node.jit.su/h-org/h-org-1.js +11 -0
  100. data/spec/support/cases/microformat2-node.jit.su/h-org/h-org-2.html +6 -0
  101. data/spec/support/cases/microformat2-node.jit.su/h-org/h-org-2.js +12 -0
  102. data/spec/support/cases/microformat2-node.jit.su/h-product/h-product-0.html +3 -0
  103. data/spec/support/cases/microformat2-node.jit.su/h-product/h-product-0.js +10 -0
  104. data/spec/support/cases/microformat2-node.jit.su/h-product/h-product-1.html +3 -0
  105. data/spec/support/cases/microformat2-node.jit.su/h-product/h-product-1.js +11 -0
  106. data/spec/support/cases/microformat2-node.jit.su/h-product/h-product-2.html +11 -0
  107. data/spec/support/cases/microformat2-node.jit.su/h-product/h-product-2.js +23 -0
  108. data/spec/support/cases/microformat2-node.jit.su/h-product/h-product-3.html +22 -0
  109. data/spec/support/cases/microformat2-node.jit.su/h-product/h-product-3.js +42 -0
  110. data/spec/support/cases/microformat2-node.jit.su/h-recipe/h-recipe-0.html +9 -0
  111. data/spec/support/cases/microformat2-node.jit.su/h-recipe/h-recipe-0.js +11 -0
  112. data/spec/support/cases/microformat2-node.jit.su/h-recipe/h-recipe-1.html +67 -0
  113. data/spec/support/cases/microformat2-node.jit.su/h-recipe/h-recipe-1.js +51 -0
  114. data/spec/support/cases/microformat2-node.jit.su/h-resume/h-resume-0.html +3 -0
  115. data/spec/support/cases/microformat2-node.jit.su/h-resume/h-resume-0.js +10 -0
  116. data/spec/support/cases/microformat2-node.jit.su/h-resume/h-resume-1.html +20 -0
  117. data/spec/support/cases/microformat2-node.jit.su/h-resume/h-resume-1.js +39 -0
  118. data/spec/support/cases/microformat2-node.jit.su/h-resume/h-resume-2.html +17 -0
  119. data/spec/support/cases/microformat2-node.jit.su/h-resume/h-resume-2.js +54 -0
  120. data/spec/support/cases/microformat2-node.jit.su/h-resume/h-resume-3.html +15 -0
  121. data/spec/support/cases/microformat2-node.jit.su/h-resume/h-resume-3.js +54 -0
  122. data/spec/support/cases/microformat2-node.jit.su/h-resume/h-resume-4.html +15 -0
  123. data/spec/support/cases/microformat2-node.jit.su/h-resume/h-resume-4.js +12 -0
  124. data/spec/support/cases/microformat2-node.jit.su/h-resume/h-resume-5.html +13 -0
  125. data/spec/support/cases/microformat2-node.jit.su/h-resume/h-resume-5.js +27 -0
  126. data/spec/support/cases/microformat2-node.jit.su/h-review-aggregate/h-review-aggregate-0.html +10 -0
  127. data/spec/support/cases/microformat2-node.jit.su/h-review-aggregate/h-review-aggregate-0.js +19 -0
  128. data/spec/support/cases/microformat2-node.jit.su/h-review-aggregate/h-review-aggregate-1.html +20 -0
  129. data/spec/support/cases/microformat2-node.jit.su/h-review-aggregate/h-review-aggregate-1.js +26 -0
  130. data/spec/support/cases/microformat2-node.jit.su/h-review-aggregate/h-review-aggregate-2.html +15 -0
  131. data/spec/support/cases/microformat2-node.jit.su/h-review-aggregate/h-review-aggregate-2.js +23 -0
  132. data/spec/support/cases/microformat2-node.jit.su/h-review/h-review-0.html +3 -0
  133. data/spec/support/cases/microformat2-node.jit.su/h-review/h-review-0.js +10 -0
  134. data/spec/support/cases/microformat2-node.jit.su/h-review/h-review-1.html +3 -0
  135. data/spec/support/cases/microformat2-node.jit.su/h-review/h-review-1.js +11 -0
  136. data/spec/support/cases/microformat2-node.jit.su/h-review/h-review-2.html +3 -0
  137. data/spec/support/cases/microformat2-node.jit.su/h-review/h-review-2.js +11 -0
  138. data/spec/support/cases/microformat2-node.jit.su/h-review/h-review-3.html +6 -0
  139. data/spec/support/cases/microformat2-node.jit.su/h-review/h-review-3.js +19 -0
  140. data/spec/support/cases/microformat2-node.jit.su/h-review/h-review-4.html +8 -0
  141. data/spec/support/cases/microformat2-node.jit.su/h-review/h-review-4.js +20 -0
  142. data/spec/support/cases/microformat2-node.jit.su/h-review/h-review-5.html +24 -0
  143. data/spec/support/cases/microformat2-node.jit.su/h-review/h-review-5.js +37 -0
  144. data/spec/support/cases/microformat2-node.jit.su/includes/includes-0.html +18 -0
  145. data/spec/support/cases/microformat2-node.jit.su/includes/includes-0.js +43 -0
  146. data/spec/support/cases/microformat2-node.jit.su/includes/includes-1.html +26 -0
  147. data/spec/support/cases/microformat2-node.jit.su/includes/includes-1.js +54 -0
  148. data/spec/support/cases/microformat2-node.jit.su/includes/includes-2.html +13 -0
  149. data/spec/support/cases/microformat2-node.jit.su/includes/includes-2.js +20 -0
  150. data/spec/support/cases/microformat2-node.jit.su/includes/includes-3.html +20 -0
  151. data/spec/support/cases/microformat2-node.jit.su/includes/includes-3.js +40 -0
  152. data/spec/support/cases/microformat2-node.jit.su/includes/includes-4.html +23 -0
  153. data/spec/support/cases/microformat2-node.jit.su/includes/includes-4.js +42 -0
  154. data/spec/support/cases/microformat2-node.jit.su/rel/rel-0.html +3 -0
  155. data/spec/support/cases/microformat2-node.jit.su/rel/rel-0.js +10 -0
  156. data/spec/support/cases/microformat2-node.jit.su/rel/rel-1.html +3 -0
  157. data/spec/support/cases/microformat2-node.jit.su/rel/rel-1.js +10 -0
  158. data/spec/support/cases/microformat2-node.jit.su/rel/rel-2.html +12 -0
  159. data/spec/support/cases/microformat2-node.jit.su/rel/rel-2.js +19 -0
  160. data/spec/support/cases/microformat2-node.jit.su/rel/rel-3.html +21 -0
  161. data/spec/support/cases/microformat2-node.jit.su/rel/rel-3.js +26 -0
  162. data/spec/support/cases/microformat2-node.jit.su/rel/rel-4.html +15 -0
  163. data/spec/support/cases/microformat2-node.jit.su/rel/rel-4.js +42 -0
  164. data/spec/support/cases/microformats.org/microformats-2/microformats-2-0.html +2 -0
  165. data/spec/support/cases/microformats.org/microformats-2/microformats-2-0.js +9 -0
  166. data/spec/support/cases/microformats.org/microformats-2/microformats-2-1.html +2 -0
  167. data/spec/support/cases/microformats.org/microformats-2/microformats-2-1.js +10 -0
  168. data/spec/support/cases/microformats.org/microformats-2/microformats-2-2.html +5 -0
  169. data/spec/support/cases/microformats.org/microformats-2/microformats-2-2.js +11 -0
  170. data/spec/support/cases/microformats.org/microformats-2/microformats-2-3.html +17 -0
  171. data/spec/support/cases/microformats.org/microformats-2/microformats-2-3.js +20 -0
  172. data/spec/support/cases/microformats.org/microformats-2/microformats-2-4.html +16 -0
  173. data/spec/support/cases/microformats.org/microformats-2/microformats-2-4.js +24 -0
  174. data/spec/support/cases/microformats.org/microformats-2/microformats-2-5.html +7 -0
  175. data/spec/support/cases/microformats.org/microformats-2/microformats-2-5.js +11 -0
  176. data/spec/support/cases/microformats.org/microformats-2/microformats-2-6.html +9 -0
  177. data/spec/support/cases/microformats.org/microformats-2/microformats-2-6.js +18 -0
  178. data/spec/support/cases/microformats.org/microformats-2/microformats-2-7.html +9 -0
  179. data/spec/support/cases/microformats.org/microformats-2/microformats-2-7.js +18 -0
  180. data/spec/support/cases/microformats.org/microformats-2/microformats-2-8.html +9 -0
  181. data/spec/support/cases/microformats.org/microformats-2/microformats-2-8.js +17 -0
  182. data/spec/support/cases/microformats.org/microformats-2/microformats-2-9.html +9 -0
  183. data/spec/support/cases/microformats.org/microformats-2/microformats-2-9.js +17 -0
  184. data/spec/support/lib/microformats2/implied_property/name-fail.html +60 -0
  185. data/spec/support/lib/microformats2/implied_property/name-pass.html +30 -0
  186. data/spec/support/lib/microformats2/implied_property/photo-fail.html +60 -0
  187. data/spec/support/lib/microformats2/implied_property/photo-pass.html +30 -0
  188. data/spec/support/lib/microformats2/implied_property/url-fail.html +18 -0
  189. data/spec/support/lib/microformats2/implied_property/url-pass.html +12 -0
  190. data/spec/support/lib/microformats2/nested-format-with-property.html +12 -0
  191. data/spec/support/lib/microformats2/nested-format-with-property.js +15 -0
  192. data/spec/support/lib/microformats2/nested-format-without-property.html +13 -0
  193. data/spec/support/lib/microformats2/nested-property.html +12 -0
  194. data/spec/support/lib/microformats2/nested-property.js +9 -0
  195. data/spec/support/lib/microformats2/simple.html +19 -0
  196. data/spec/support/lib/microformats2/simple.js +10 -0
  197. metadata +535 -85
  198. data/.autotest +0 -23
  199. data/.gemtest +0 -0
  200. data/History.txt +0 -19
  201. data/Manifest.txt +0 -10
  202. data/bin/microformats2 +0 -3
  203. data/test/IndieWebCamp.html +0 -351
  204. data/test/simple.html +0 -30
  205. data/test/test_microformats2.rb +0 -185
@@ -0,0 +1,16 @@
1
+ module Microformats2
2
+ module Property
3
+ class Text < Foundation
4
+
5
+ protected
6
+
7
+ def attr_map
8
+ @attr_map = {
9
+ "abbr" => "title",
10
+ "data" => "value",
11
+ "img" => "alt",
12
+ "area" => "alt" }
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ module Microformats2
2
+ module Property
3
+ class Url < Foundation
4
+
5
+ protected
6
+
7
+ def attr_map
8
+ @attr_map = {
9
+ "a" => "href",
10
+ "area" => "href",
11
+ "img" => "src",
12
+ "object" => "data",
13
+ "abbr" => "title",
14
+ "data" => "value" }
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,54 @@
1
+ module Microformats2
2
+ class PropertyParser
3
+ class << self
4
+ def parse(element)
5
+ parse_node(element).flatten.compact
6
+ end
7
+
8
+ def parse_node(node)
9
+ case
10
+ when node.is_a?(Nokogiri::XML::NodeSet) then parse_nodeset(node)
11
+ when node.is_a?(Nokogiri::XML::Element) then [parse_for_properties(node)]
12
+ end
13
+ end
14
+
15
+ def parse_nodeset(nodeset)
16
+ nodeset.map { |node| parse_node(node) }
17
+ end
18
+
19
+ def parse_for_properties(element)
20
+ if property_classes(element).length >= 1
21
+ parse_property(element)
22
+ else
23
+ parse_nodeset(element.children)
24
+ end
25
+ end
26
+
27
+ def parse_property(element)
28
+ property_classes(element).map do |property_class|
29
+ # p-class-name -> p
30
+ prefix = property_class.split("-").first
31
+ # find ruby class for kind of property
32
+ klass = Microformats2::Property::PREFIX_CLASS_MAP[prefix]
33
+
34
+ property = klass.new(element, property_class).parse
35
+ properties = format_classes(element).empty? ? PropertyParser.parse(element.children) : []
36
+
37
+ [property].concat properties
38
+ end
39
+ end
40
+
41
+ def property_classes(element)
42
+ element.attribute("class").to_s.split.select do |html_class|
43
+ html_class =~ Property::CLASS_REG_EXP
44
+ end
45
+ end
46
+
47
+ def format_classes(element)
48
+ element.attribute("class").to_s.split.select do |html_class|
49
+ html_class =~ Format::CLASS_REG_EXP
50
+ end
51
+ end
52
+ end # class << self
53
+ end
54
+ end
@@ -0,0 +1,3 @@
1
+ module Microformats2
2
+ VERSION = "2.0.0.pre1"
3
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'microformats2/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "microformats2"
8
+ gem.version = Microformats2::VERSION
9
+ gem.authors = ["Jessica Lynn Suttles"]
10
+ gem.email = ["jlsuttles@gmail.com"]
11
+ gem.description = %q{parses HTML for microformats and return a collection of dynamically defined Ruby objects}
12
+ gem.summary = %q{microformats2 parser}
13
+ gem.homepage = "https://github.com/G5/microformats2"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_runtime_dependency "nokogiri", "~> 1.5.6"
21
+ gem.add_runtime_dependency "json", "~> 1.7.6"
22
+ gem.add_runtime_dependency "activesupport", "~> 3.2.12"
23
+
24
+ gem.add_development_dependency "rake", "~> 10.0.0"
25
+ gem.add_development_dependency "rspec", "~> 2.11.0"
26
+ gem.add_development_dependency "guard-rspec", "~> 2.1.0"
27
+ gem.add_development_dependency "rb-fsevent", "~> 0.9.1"
28
+ gem.add_development_dependency "simplecov", "~> 0.7.1"
29
+ gem.add_development_dependency "debugger", "~> 1.2.1"
30
+ end
@@ -0,0 +1,181 @@
1
+ require "spec_helper"
2
+ require "microformats2"
3
+
4
+ describe Microformats2::Collection do
5
+ describe "spec/support/lib/microformats2" do
6
+
7
+ describe "simple.html" do
8
+ before do
9
+ html = "spec/support/lib/microformats2/simple.html"
10
+ @collection = Microformats2.parse(html)
11
+ end
12
+ describe "#to_json" do
13
+ it "should match simple.js" do
14
+ json = "spec/support/lib/microformats2/simple.js"
15
+ json = open(json).read
16
+ JSON.parse(@collection.to_json).should == JSON.parse(json)
17
+ end
18
+ end
19
+ describe "'.h-card'" do
20
+ it "assigns all cards to Collection#cards" do
21
+ @collection.cards.first.should be_kind_of HCard
22
+ end
23
+ it "assigns the first card to Collection#card" do
24
+ @collection.card.should be_kind_of HCard
25
+ end
26
+ end
27
+ describe "'.h-card .p-name'" do
28
+ it "assigns all names to HCard#names" do
29
+ @collection.card.names.map(&:to_s).should == ["Jessica Lynn Suttles"]
30
+ end
31
+ it "assigns the first name to HCard#name" do
32
+ @collection.card.name.to_s.should == "Jessica Lynn Suttles"
33
+ end
34
+ it "HCard#name is a Property::Text" do
35
+ @collection.card.name.should be_kind_of Microformats2::Property::Text
36
+ end
37
+ end
38
+ describe "'.h-card .p-url'" do
39
+ it "assigns all urls to HCard#urls" do
40
+ urls = ["http://flickr.com/jlsuttles", "http://twitter.com/jlsuttles"]
41
+ @collection.card.urls.map(&:to_s).should == urls
42
+ end
43
+ it "assigns then first url to HCard#url" do
44
+ @collection.card.url.to_s.should == "http://flickr.com/jlsuttles"
45
+ end
46
+ it "HCard#url is a Property::Url" do
47
+ @collection.card.url.should be_kind_of Microformats2::Property::Url
48
+ end
49
+ end
50
+ describe "'.h-card .p-bday'" do
51
+ it "assigns all bdays to HCard#bdays" do
52
+ @collection.card.bdays.map(&:to_s).should == ["1990-10-15"]
53
+ end
54
+ it "assigns the first bday to HCard#bday" do
55
+ @collection.card.bday.to_s.should == "1990-10-15"
56
+ end
57
+ it "HCard#bday is a Property::DateTime" do
58
+ @collection.card.bday.should be_kind_of Microformats2::Property::DateTime
59
+ end
60
+ it "assigns DateTime object to Property::DateTime#value" do
61
+ @collection.card.bday.value.should be_kind_of DateTime
62
+ @collection.card.bday.value.to_s.should == "1990-10-15T00:00:00+00:00"
63
+ end
64
+ end
65
+ describe "'.h-card .p-content'" do
66
+ it "assigns all contents to HCard#contents" do
67
+ @collection.card.contents.map(&:to_s).should == ["<p>Vegan. Cat lover. Coder.</p>"]
68
+ end
69
+ it "assigns the first content to HCard#content" do
70
+ @collection.card.content.to_s.should == "<p>Vegan. Cat lover. Coder.</p>"
71
+ end
72
+ it "HCard#content is a Property::Embedded" do
73
+ @collection.card.contents.first.should be_kind_of Microformats2::Property::Embedded
74
+ end
75
+ end
76
+ end
77
+
78
+ describe "nested-property.html" do
79
+ before do
80
+ html = "spec/support/lib/microformats2/nested-property.html"
81
+ @collection = Microformats2.parse(html)
82
+ end
83
+ describe "#to_json" do
84
+ it "should match nested-property.js" do
85
+ json = "spec/support/lib/microformats2/nested-property.js"
86
+ json = open(json).read
87
+ JSON.parse(@collection.to_json).should == JSON.parse(json)
88
+ end
89
+ end
90
+ describe "'.h-card'" do
91
+ it "assigns all cards to Collection#cards" do
92
+ @collection.cards.first.should be_kind_of HCard
93
+ end
94
+ it "assigns the first card to Collection#card" do
95
+ @collection.card.should be_kind_of HCard
96
+ end
97
+ end
98
+ describe "'.h-card .p-name'" do
99
+ it "assigns all names to HCard#names" do
100
+ @collection.card.names.map(&:to_s).should == ["jlsuttles"]
101
+ end
102
+ it "assigns the first name to HCard#name" do
103
+ @collection.card.name.to_s.should == "jlsuttles"
104
+ end
105
+ it "HCard#name is a Property::Text" do
106
+ @collection.card.name.should be_kind_of Microformats2::Property::Text
107
+ end
108
+ end
109
+ describe "'.h-card .p-name .p-nickname'" do
110
+ it "assigns all nicknames to HCard#nicknames" do
111
+ @collection.card.nicknames.map(&:to_s).should == ["jlsuttles"]
112
+ end
113
+ it "assigns the first nickname to HCard#nickname" do
114
+ @collection.card.nickname.to_s.should == "jlsuttles"
115
+ end
116
+ it "HCard#nickname is a Property::Text" do
117
+ @collection.card.nickname.should be_kind_of Microformats2::Property::Text
118
+ end
119
+ end
120
+ end
121
+
122
+ describe "nested-format-with-property.html" do
123
+ before do
124
+ html = "spec/support/lib/microformats2/nested-format-with-property.html"
125
+ @collection = Microformats2.parse(html)
126
+ end
127
+ describe "#to_json" do
128
+ it "should match nested-format-with-property.js" do
129
+ json = "spec/support/lib/microformats2/nested-format-with-property.js"
130
+ json = open(json).read
131
+ JSON.parse(@collection.to_json).should == JSON.parse(json)
132
+ end
133
+ end
134
+ describe "'.h-entry'" do
135
+ it "assigns all entrys to Collection#entrys" do
136
+ @collection.entries.first.should be_kind_of HEntry
137
+ end
138
+ it "assigns the first entry to Collection#entry" do
139
+ @collection.entry.should be_kind_of HEntry
140
+ end
141
+ end
142
+ describe "'.h-card .p-author.h-card'" do
143
+ it "assigns all authors to HCard#authors" do
144
+ @collection.entry.authors.map(&:to_s).should == ["Jessica Lynn Suttles"]
145
+ end
146
+ it "assigns the first author to HCard#author" do
147
+ @collection.entry.author.to_s.should == "Jessica Lynn Suttles"
148
+ end
149
+ it "HCard#author is a Property::Text" do
150
+ @collection.entry.author.should be_kind_of Microformats2::Property::Text
151
+ end
152
+ it "assigns all HCard to Property::Text#formats" do
153
+ @collection.entry.author.formats.first.should be_kind_of HCard
154
+ end
155
+ it "assigns the first HCard to Property::Text#format" do
156
+ @collection.entry.author.format.should be_kind_of HCard
157
+ end
158
+ end
159
+ end
160
+ end
161
+
162
+ #
163
+ # these cases were scraped from the internet using `rake specs:update`
164
+ #
165
+ describe "spec/support/cases" do
166
+ cases_dir = "spec/support/cases/*"
167
+ Dir[File.join(cases_dir, "*")].each do |page_dir|
168
+ describe page_dir.split("/")[-2..-1].join("/") do
169
+ Dir[File.join(page_dir, "*")].keep_if { |f| f =~ /([.]html$)/ }.each do |html_file|
170
+ it "#{html_file.split("/").last}" do
171
+ json_file = html_file.gsub(/([.]html$)/, ".js")
172
+ html = open(html_file).read
173
+ json = open(json_file).read
174
+
175
+ JSON.parse(Microformats2.parse(html).to_json).should == JSON.parse(json)
176
+ end
177
+ end
178
+ end
179
+ end
180
+ end
181
+ end
@@ -0,0 +1,31 @@
1
+ require "spec_helper"
2
+ require "microformats2"
3
+
4
+ describe Microformats2::ImpliedProperty::Name do
5
+ describe "spec/support/lib/microformats/implied_property" do
6
+ describe "name-pass.html" do
7
+ html = "spec/support/lib/microformats2/implied_property/name-pass.html"
8
+ collection = Microformats2.parse(html)
9
+ it "should have 6 microformats" do
10
+ collection.all.length.should == 6
11
+ end
12
+ collection.all.each_with_index do |format, index|
13
+ it "implies name to be 'Jessica' in case #{index+1}" do
14
+ format.name.to_s.should == "Jessica"
15
+ end
16
+ end
17
+ end
18
+ describe "name-fail.html" do
19
+ html = "spec/support/lib/microformats2/implied_property/name-fail.html"
20
+ collection = Microformats2.parse(html)
21
+ it "should have 8 microformats" do
22
+ collection.all.length.should == 8
23
+ end
24
+ collection.all.each_with_index do |format, index|
25
+ it "implies name to be '' in case #{index+1}" do
26
+ format.name.to_s.should == ""
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ require "spec_helper"
2
+ require "microformats2"
3
+
4
+ describe Microformats2::ImpliedProperty::Photo do
5
+ describe "spec/support/lib/microformats/implied_property" do
6
+ describe "photo-pass.html" do
7
+ html = "spec/support/lib/microformats2/implied_property/photo-pass.html"
8
+ collection = Microformats2.parse(html)
9
+ it "should have 6 microformats" do
10
+ collection.all.length.should == 6
11
+ end
12
+ collection.all.each_with_index do |format, index|
13
+ it "implies photo to be 'http://gravatar.com/jlsuttles' in case #{index+1}" do
14
+ format.photo.to_s.should == "http://gravatar.com/jlsuttles"
15
+ end
16
+ end
17
+ end
18
+ describe "photo-fail.html" do
19
+ html = "spec/support/lib/microformats2/implied_property/photo-fail.html"
20
+ collection = Microformats2.parse(html)
21
+ it "should have 8 microformats" do
22
+ collection.all.length.should == 8
23
+ end
24
+ collection.all.each_with_index do |format, index|
25
+ it "implies photo to be '' in case #{index+1}" do
26
+ format.photo.to_s.should == ""
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ require "spec_helper"
2
+ require "microformats2"
3
+
4
+ describe Microformats2::ImpliedProperty::Url do
5
+ describe "spec/support/lib/microformats/implied_property" do
6
+ describe "url-pass.html" do
7
+ html = "spec/support/lib/microformats2/implied_property/url-pass.html"
8
+ collection = Microformats2.parse(html)
9
+ it "should have 2 microformats" do
10
+ collection.all.length.should == 2
11
+ end
12
+ collection.all.each_with_index do |format, index|
13
+ it "implies url to be 'http://github.com/jlsuttles' in case #{index+1}" do
14
+ format.url.to_s.should == "http://github.com/jlsuttles"
15
+ end
16
+ end
17
+ end
18
+ describe "url-fail.html" do
19
+ html = "spec/support/lib/microformats2/implied_property/url-fail.html"
20
+ collection = Microformats2.parse(html)
21
+ it "should have 2 microformats" do
22
+ collection.all.length.should == 2
23
+ end
24
+ collection.all.each_with_index do |format, index|
25
+ it "implies url to be '' in case #{index+1}" do
26
+ format.url.to_s.should == ""
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,30 @@
1
+ require "spec_helper"
2
+ require "microformats2"
3
+
4
+ describe Microformats2 do
5
+ before do
6
+ @html = <<-HTML.strip
7
+ <div class="h-card"><p class="p-name">Jessica Lynn Suttles</p></div>
8
+ HTML
9
+ end
10
+
11
+ describe "::parse" do
12
+ it "returns a collection" do
13
+ Microformats2.parse(@html).should be_kind_of Microformats2::Collection
14
+ end
15
+ end
16
+
17
+ describe "::read_html" do
18
+ it "can be a string of html" do
19
+ Microformats2.read_html(@html).should include @html
20
+ end
21
+ it "can be a file path to html" do
22
+ html = "spec/support/lib/microformats2/simple.html"
23
+ Microformats2.read_html(html).should include "<div class=\"h-card\">"
24
+ end
25
+ it "can be a url to html" do
26
+ html = "http://google.com"
27
+ Microformats2.read_html(html).should include "google"
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,10 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'rubygems'
5
+ require 'rspec'
6
+ require 'rspec/autorun'
7
+
8
+ RSpec.configure do |config|
9
+ config.order = "random"
10
+ end