microformats 0.3 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (353) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +4 -0
  5. data/Gemfile +4 -0
  6. data/Guardfile +5 -0
  7. data/LICENSE.md +36 -0
  8. data/README.md +228 -0
  9. data/Rakefile +7 -25
  10. data/lib/microformats.rb +25 -9
  11. data/lib/microformats/absolute_uri.rb +30 -0
  12. data/lib/microformats/format_parser.rb +343 -0
  13. data/lib/microformats/parser.rb +105 -0
  14. data/lib/microformats/parser_core.rb +343 -0
  15. data/lib/microformats/property_parser.rb +122 -0
  16. data/lib/microformats/results/collection.rb +121 -0
  17. data/lib/microformats/results/parser_result.rb +111 -0
  18. data/lib/microformats/results/property_set.rb +87 -0
  19. data/lib/microformats/time_property_parser.rb +161 -0
  20. data/lib/microformats/version.rb +3 -0
  21. data/microformats.gemspec +37 -0
  22. data/spec/lib/microformats/absolute_uri_spec.rb +48 -0
  23. data/spec/lib/microformats/parser_spec.rb +72 -0
  24. data/spec/lib/microformats_spec.rb +33 -0
  25. data/spec/spec_helper.rb +10 -0
  26. data/spec/support/cases/microformats.org/microformats-2/microformats-2-0.html +2 -0
  27. data/spec/support/cases/microformats.org/microformats-2/microformats-2-0.js +9 -0
  28. data/spec/support/cases/microformats.org/microformats-2/microformats-2-1.html +2 -0
  29. data/spec/support/cases/microformats.org/microformats-2/microformats-2-1.js +10 -0
  30. data/spec/support/cases/microformats.org/microformats-2/microformats-2-2.html +5 -0
  31. data/spec/support/cases/microformats.org/microformats-2/microformats-2-2.js +11 -0
  32. data/spec/support/cases/microformats.org/microformats-2/microformats-2-3.html +17 -0
  33. data/spec/support/cases/microformats.org/microformats-2/microformats-2-3.js +20 -0
  34. data/spec/support/cases/microformats.org/microformats-2/microformats-2-4.html +16 -0
  35. data/spec/support/cases/microformats.org/microformats-2/microformats-2-4.js +24 -0
  36. data/spec/support/cases/microformats.org/microformats-2/microformats-2-5.html +7 -0
  37. data/spec/support/cases/microformats.org/microformats-2/microformats-2-5.js +11 -0
  38. data/spec/support/cases/microformats.org/microformats-2/microformats-2-6.html +9 -0
  39. data/spec/support/cases/microformats.org/microformats-2/microformats-2-6.js +18 -0
  40. data/spec/support/cases/microformats.org/microformats-2/microformats-2-7.html +9 -0
  41. data/spec/support/cases/microformats.org/microformats-2/microformats-2-7.js +18 -0
  42. data/spec/support/cases/microformats.org/microformats-2/microformats-2-8.html +9 -0
  43. data/spec/support/cases/microformats.org/microformats-2/microformats-2-8.js +17 -0
  44. data/spec/support/cases/microformats.org/microformats-2/microformats-2-9.html +9 -0
  45. data/spec/support/cases/microformats.org/microformats-2/microformats-2-9.js +17 -0
  46. data/spec/support/lib/microformats/implied_property/name-fail.html +60 -0
  47. data/spec/support/lib/microformats/implied_property/name-pass.html +30 -0
  48. data/spec/support/lib/microformats/implied_property/photo-fail.html +60 -0
  49. data/spec/support/lib/microformats/implied_property/photo-pass.html +30 -0
  50. data/spec/support/lib/microformats/implied_property/url-fail.html +18 -0
  51. data/spec/support/lib/microformats/implied_property/url-pass.html +12 -0
  52. data/spec/support/lib/microformats/implied_property/url-relative.html +13 -0
  53. data/spec/support/lib/microformats/implied_property/url-unnormalized.html +12 -0
  54. data/spec/support/lib/microformats/nested-format-with-property-of-same-name.html +13 -0
  55. data/spec/support/lib/microformats/nested-format-with-property-of-same-name.js +16 -0
  56. data/spec/support/lib/microformats/nested-format-with-property.html +12 -0
  57. data/spec/support/lib/microformats/nested-format-with-property.js +16 -0
  58. data/spec/support/lib/microformats/nested-format-without-property.html +13 -0
  59. data/spec/support/lib/microformats/nested-property.html +12 -0
  60. data/spec/support/lib/microformats/nested-property.js +10 -0
  61. data/spec/support/lib/microformats/rels-that-drop-the-base.html +11 -0
  62. data/spec/support/lib/microformats/rels-with-unnormalized-urls.html +11 -0
  63. data/spec/support/lib/microformats/rels.html +12 -0
  64. data/spec/support/lib/microformats/rels.js +13 -0
  65. data/spec/support/lib/microformats/simple.html +23 -0
  66. data/spec/support/lib/microformats/simple.js +11 -0
  67. data/vendor/tests/.gitignore +25 -0
  68. data/vendor/tests/LICENSE.md +36 -0
  69. data/vendor/tests/README.md +48 -0
  70. data/vendor/tests/app.js +84 -0
  71. data/vendor/tests/composer.json +5 -0
  72. data/vendor/tests/css/testsuite.css +159 -0
  73. data/vendor/tests/interface.js +18 -0
  74. data/vendor/tests/package.json +27 -0
  75. data/vendor/tests/tests/microformats-mixed/h-card/change-log.html +63 -0
  76. data/vendor/tests/tests/microformats-mixed/h-card/mixedpropertries.html +14 -0
  77. data/vendor/tests/tests/microformats-mixed/h-card/mixedpropertries.json +22 -0
  78. data/vendor/tests/tests/microformats-mixed/h-card/tworoots.html +1 -0
  79. data/vendor/tests/tests/microformats-mixed/h-card/tworoots.json +10 -0
  80. data/vendor/tests/tests/microformats-mixed/h-entry/mixedroots.html +16 -0
  81. data/vendor/tests/tests/microformats-mixed/h-entry/mixedroots.json +38 -0
  82. data/vendor/tests/tests/microformats-mixed/h-resume/change-log.html +68 -0
  83. data/vendor/tests/tests/microformats-mixed/h-resume/mixedroots.html +16 -0
  84. data/vendor/tests/tests/microformats-mixed/h-resume/mixedroots.json +31 -0
  85. data/vendor/tests/tests/microformats-v1/adr/change-log.html +63 -0
  86. data/vendor/tests/tests/microformats-v1/adr/simpleproperties.html +8 -0
  87. data/vendor/tests/tests/microformats-v1/adr/simpleproperties.json +15 -0
  88. data/vendor/tests/tests/microformats-v1/geo/abbrpattern.html +5 -0
  89. data/vendor/tests/tests/microformats-v1/geo/abbrpattern.json +11 -0
  90. data/vendor/tests/tests/microformats-v1/geo/change-log.1.html +78 -0
  91. data/vendor/tests/tests/microformats-v1/geo/change-log.html +63 -0
  92. data/vendor/tests/tests/microformats-v1/geo/hidden.html +10 -0
  93. data/vendor/tests/tests/microformats-v1/geo/hidden.json +11 -0
  94. data/vendor/tests/tests/microformats-v1/geo/simpleproperties.html +6 -0
  95. data/vendor/tests/tests/microformats-v1/geo/simpleproperties.json +11 -0
  96. data/vendor/tests/tests/microformats-v1/geo/valuetitleclass.html +11 -0
  97. data/vendor/tests/tests/microformats-v1/geo/valuetitleclass.json +11 -0
  98. data/vendor/tests/tests/microformats-v1/hcalendar/ampm.html +41 -0
  99. data/vendor/tests/tests/microformats-v1/hcalendar/ampm.json +21 -0
  100. data/vendor/tests/tests/microformats-v1/hcalendar/attendees.html +13 -0
  101. data/vendor/tests/tests/microformats-v1/hcalendar/attendees.json +37 -0
  102. data/vendor/tests/tests/microformats-v1/hcalendar/change-log.html +68 -0
  103. data/vendor/tests/tests/microformats-v1/hcalendar/combining.html +15 -0
  104. data/vendor/tests/tests/microformats-v1/hcalendar/combining.json +31 -0
  105. data/vendor/tests/tests/microformats-v1/hcalendar/concatenate.html +7 -0
  106. data/vendor/tests/tests/microformats-v1/hcalendar/concatenate.json +12 -0
  107. data/vendor/tests/tests/microformats-v1/hcalendar/time.html +44 -0
  108. data/vendor/tests/tests/microformats-v1/hcalendar/time.json +22 -0
  109. data/vendor/tests/tests/microformats-v1/hcard/change-log.html +68 -0
  110. data/vendor/tests/tests/microformats-v1/hcard/email.html +14 -0
  111. data/vendor/tests/tests/microformats-v1/hcard/email.json +11 -0
  112. data/vendor/tests/tests/microformats-v1/hcard/format.html +6 -0
  113. data/vendor/tests/tests/microformats-v1/hcard/format.json +11 -0
  114. data/vendor/tests/tests/microformats-v1/hcard/hyperlinkedphoto.html +3 -0
  115. data/vendor/tests/tests/microformats-v1/hcard/hyperlinkedphoto.json +8 -0
  116. data/vendor/tests/tests/microformats-v1/hcard/justahyperlink.html +1 -0
  117. data/vendor/tests/tests/microformats-v1/hcard/justahyperlink.json +8 -0
  118. data/vendor/tests/tests/microformats-v1/hcard/justaname.html +1 -0
  119. data/vendor/tests/tests/microformats-v1/hcard/justaname.json +8 -0
  120. data/vendor/tests/tests/microformats-v1/hcard/multiple.html +74 -0
  121. data/vendor/tests/tests/microformats-v1/hcard/multiple.json +65 -0
  122. data/vendor/tests/tests/microformats-v1/hcard/name.html +11 -0
  123. data/vendor/tests/tests/microformats-v1/hcard/name.json +15 -0
  124. data/vendor/tests/tests/microformats-v1/hcard/single.html +14 -0
  125. data/vendor/tests/tests/microformats-v1/hcard/single.json +24 -0
  126. data/vendor/tests/tests/microformats-v1/hentry/change-log.html +73 -0
  127. data/vendor/tests/tests/microformats-v1/hentry/summarycontent.html +20 -0
  128. data/vendor/tests/tests/microformats-v1/hentry/summarycontent.json +24 -0
  129. data/vendor/tests/tests/microformats-v1/hfeed/simple.html +30 -0
  130. data/vendor/tests/tests/microformats-v1/hfeed/simple.json +49 -0
  131. data/vendor/tests/tests/microformats-v1/hnews/all.html +37 -0
  132. data/vendor/tests/tests/microformats-v1/hnews/all.json +74 -0
  133. data/vendor/tests/tests/microformats-v1/hnews/change-log.html +72 -0
  134. data/vendor/tests/tests/microformats-v1/hnews/minimum.html +25 -0
  135. data/vendor/tests/tests/microformats-v1/hnews/minimum.json +48 -0
  136. data/vendor/tests/tests/microformats-v1/hproduct/aggregate.html +26 -0
  137. data/vendor/tests/tests/microformats-v1/hproduct/aggregate.json +52 -0
  138. data/vendor/tests/tests/microformats-v1/hproduct/change-log.html +62 -0
  139. data/vendor/tests/tests/microformats-v1/hproduct/simpleproperties.html +13 -0
  140. data/vendor/tests/tests/microformats-v1/hproduct/simpleproperties.json +33 -0
  141. data/vendor/tests/tests/microformats-v1/hresume/affiliation.html +12 -0
  142. data/vendor/tests/tests/microformats-v1/hresume/affiliation.json +25 -0
  143. data/vendor/tests/tests/microformats-v1/hresume/change-log.html +73 -0
  144. data/vendor/tests/tests/microformats-v1/hresume/contact.html +18 -0
  145. data/vendor/tests/tests/microformats-v1/hresume/contact.json +32 -0
  146. data/vendor/tests/tests/microformats-v1/hresume/education.html +13 -0
  147. data/vendor/tests/tests/microformats-v1/hresume/education.json +29 -0
  148. data/vendor/tests/tests/microformats-v1/hresume/skill.html +12 -0
  149. data/vendor/tests/tests/microformats-v1/hresume/skill.json +33 -0
  150. data/vendor/tests/tests/microformats-v1/hresume/work.html +16 -0
  151. data/vendor/tests/tests/microformats-v1/hresume/work.json +30 -0
  152. data/vendor/tests/tests/microformats-v1/hreview-aggregate/change-log.html +67 -0
  153. data/vendor/tests/tests/microformats-v1/hreview-aggregate/hcard.html +18 -0
  154. data/vendor/tests/tests/microformats-v1/hreview-aggregate/hcard.json +31 -0
  155. data/vendor/tests/tests/microformats-v1/hreview-aggregate/justahyperlink.html +6 -0
  156. data/vendor/tests/tests/microformats-v1/hreview-aggregate/justahyperlink.json +19 -0
  157. data/vendor/tests/tests/microformats-v1/hreview-aggregate/vevent.html +13 -0
  158. data/vendor/tests/tests/microformats-v1/hreview-aggregate/vevent.json +22 -0
  159. data/vendor/tests/tests/microformats-v1/hreview/change-log.html +73 -0
  160. data/vendor/tests/tests/microformats-v1/hreview/item.html +8 -0
  161. data/vendor/tests/tests/microformats-v1/hreview/item.json +19 -0
  162. data/vendor/tests/tests/microformats-v1/hreview/vcard.html +23 -0
  163. data/vendor/tests/tests/microformats-v1/hreview/vcard.json +58 -0
  164. data/vendor/tests/tests/microformats-v1/includes/change-log.html +72 -0
  165. data/vendor/tests/tests/microformats-v1/includes/hcarditemref.html +16 -0
  166. data/vendor/tests/tests/microformats-v1/includes/hcarditemref.json +49 -0
  167. data/vendor/tests/tests/microformats-v1/includes/heventitemref.html +25 -0
  168. data/vendor/tests/tests/microformats-v1/includes/heventitemref.json +33 -0
  169. data/vendor/tests/tests/microformats-v1/includes/hyperlink.html +18 -0
  170. data/vendor/tests/tests/microformats-v1/includes/hyperlink.json +43 -0
  171. data/vendor/tests/tests/microformats-v1/includes/object.html +23 -0
  172. data/vendor/tests/tests/microformats-v1/includes/object.json +42 -0
  173. data/vendor/tests/tests/microformats-v1/includes/table.html +12 -0
  174. data/vendor/tests/tests/microformats-v1/includes/table.json +19 -0
  175. data/vendor/tests/tests/microformats-v2/h-adr/change-log.html +62 -0
  176. data/vendor/tests/tests/microformats-v2/h-adr/geo.html +10 -0
  177. data/vendor/tests/tests/microformats-v2/h-adr/geo.json +16 -0
  178. data/vendor/tests/tests/microformats-v2/h-adr/geourl.html +4 -0
  179. data/vendor/tests/tests/microformats-v2/h-adr/geourl.json +13 -0
  180. data/vendor/tests/tests/microformats-v2/h-adr/justaname.html +1 -0
  181. data/vendor/tests/tests/microformats-v2/h-adr/justaname.json +10 -0
  182. data/vendor/tests/tests/microformats-v2/h-adr/lettercase.html +21 -0
  183. data/vendor/tests/tests/microformats-v2/h-adr/lettercase.json +12 -0
  184. data/vendor/tests/tests/microformats-v2/h-adr/simpleproperties.html +8 -0
  185. data/vendor/tests/tests/microformats-v2/h-adr/simpleproperties.json +16 -0
  186. data/vendor/tests/tests/microformats-v2/h-as-note/note.html +56 -0
  187. data/vendor/tests/tests/microformats-v2/h-as-note/note.json +98 -0
  188. data/vendor/tests/tests/microformats-v2/h-card/baseurl.html +6 -0
  189. data/vendor/tests/tests/microformats-v2/h-card/baseurl.json +26 -0
  190. data/vendor/tests/tests/microformats-v2/h-card/change-log.html +100 -0
  191. data/vendor/tests/tests/microformats-v2/h-card/childimplied.html +7 -0
  192. data/vendor/tests/tests/microformats-v2/h-card/childimplied.json +12 -0
  193. data/vendor/tests/tests/microformats-v2/h-card/extendeddescription.html +10 -0
  194. data/vendor/tests/tests/microformats-v2/h-card/extendeddescription.json +15 -0
  195. data/vendor/tests/tests/microformats-v2/h-card/hcard.html +4 -0
  196. data/vendor/tests/tests/microformats-v2/h-card/hcard.json +19 -0
  197. data/vendor/tests/tests/microformats-v2/h-card/horghcard.html +4 -0
  198. data/vendor/tests/tests/microformats-v2/h-card/horghcard.json +19 -0
  199. data/vendor/tests/tests/microformats-v2/h-card/hyperlinkedphoto.html +3 -0
  200. data/vendor/tests/tests/microformats-v2/h-card/hyperlinkedphoto.json +12 -0
  201. data/vendor/tests/tests/microformats-v2/h-card/impliedname.html +15 -0
  202. data/vendor/tests/tests/microformats-v2/h-card/impliedname.json +90 -0
  203. data/vendor/tests/tests/microformats-v2/h-card/impliedphoto.html +11 -0
  204. data/vendor/tests/tests/microformats-v2/h-card/impliedphoto.json +72 -0
  205. data/vendor/tests/tests/microformats-v2/h-card/impliedurl.html +5 -0
  206. data/vendor/tests/tests/microformats-v2/h-card/impliedurl.json +45 -0
  207. data/vendor/tests/tests/microformats-v2/h-card/justahyperlink.html +1 -0
  208. data/vendor/tests/tests/microformats-v2/h-card/justahyperlink.json +11 -0
  209. data/vendor/tests/tests/microformats-v2/h-card/justaname.html +1 -0
  210. data/vendor/tests/tests/microformats-v2/h-card/justaname.json +10 -0
  211. data/vendor/tests/tests/microformats-v2/h-card/nested.html +4 -0
  212. data/vendor/tests/tests/microformats-v2/h-card/nested.json +18 -0
  213. data/vendor/tests/tests/microformats-v2/h-card/p-property.html +21 -0
  214. data/vendor/tests/tests/microformats-v2/h-card/p-property.json +15 -0
  215. data/vendor/tests/tests/microformats-v2/h-card/relativeurls.html +6 -0
  216. data/vendor/tests/tests/microformats-v2/h-card/relativeurls.json +29 -0
  217. data/vendor/tests/tests/microformats-v2/h-entry/change-log.html +90 -0
  218. data/vendor/tests/tests/microformats-v2/h-entry/encoding.html +3 -0
  219. data/vendor/tests/tests/microformats-v2/h-entry/encoding.json +14 -0
  220. data/vendor/tests/tests/microformats-v2/h-entry/impliedvalue-nested.html +9 -0
  221. data/vendor/tests/tests/microformats-v2/h-entry/impliedvalue-nested.json +27 -0
  222. data/vendor/tests/tests/microformats-v2/h-entry/justahyperlink.html +1 -0
  223. data/vendor/tests/tests/microformats-v2/h-entry/justahyperlink.json +11 -0
  224. data/vendor/tests/tests/microformats-v2/h-entry/justaname.html +1 -0
  225. data/vendor/tests/tests/microformats-v2/h-entry/justaname.json +10 -0
  226. data/vendor/tests/tests/microformats-v2/h-entry/scriptstyletags.html +4 -0
  227. data/vendor/tests/tests/microformats-v2/h-entry/scriptstyletags.json +14 -0
  228. data/vendor/tests/tests/microformats-v2/h-entry/summarycontent.html +20 -0
  229. data/vendor/tests/tests/microformats-v2/h-entry/summarycontent.json +25 -0
  230. data/vendor/tests/tests/microformats-v2/h-entry/u-property.html +33 -0
  231. data/vendor/tests/tests/microformats-v2/h-entry/u-property.json +12 -0
  232. data/vendor/tests/tests/microformats-v2/h-entry/urlincontent.html +13 -0
  233. data/vendor/tests/tests/microformats-v2/h-entry/urlincontent.json +14 -0
  234. data/vendor/tests/tests/microformats-v2/h-event/ampm.html +41 -0
  235. data/vendor/tests/tests/microformats-v2/h-event/ampm.json +21 -0
  236. data/vendor/tests/tests/microformats-v2/h-event/attendees.html +13 -0
  237. data/vendor/tests/tests/microformats-v2/h-event/attendees.json +37 -0
  238. data/vendor/tests/tests/microformats-v2/h-event/change-log.html +82 -0
  239. data/vendor/tests/tests/microformats-v2/h-event/combining.html +13 -0
  240. data/vendor/tests/tests/microformats-v2/h-event/combining.json +25 -0
  241. data/vendor/tests/tests/microformats-v2/h-event/concatenate.html +8 -0
  242. data/vendor/tests/tests/microformats-v2/h-event/concatenate.json +12 -0
  243. data/vendor/tests/tests/microformats-v2/h-event/dates.html +13 -0
  244. data/vendor/tests/tests/microformats-v2/h-event/dates.json +26 -0
  245. data/vendor/tests/tests/microformats-v2/h-event/dt-property.html +23 -0
  246. data/vendor/tests/tests/microformats-v2/h-event/dt-property.json +20 -0
  247. data/vendor/tests/tests/microformats-v2/h-event/justahyperlink.html +1 -0
  248. data/vendor/tests/tests/microformats-v2/h-event/justahyperlink.json +11 -0
  249. data/vendor/tests/tests/microformats-v2/h-event/justaname.html +1 -0
  250. data/vendor/tests/tests/microformats-v2/h-event/justaname.json +10 -0
  251. data/vendor/tests/tests/microformats-v2/h-event/time.html +47 -0
  252. data/vendor/tests/tests/microformats-v2/h-event/time.json +25 -0
  253. data/vendor/tests/tests/microformats-v2/h-feed/implied-title.html +30 -0
  254. data/vendor/tests/tests/microformats-v2/h-feed/implied-title.json +23 -0
  255. data/vendor/tests/tests/microformats-v2/h-feed/simple.html +26 -0
  256. data/vendor/tests/tests/microformats-v2/h-feed/simple.json +33 -0
  257. data/vendor/tests/tests/microformats-v2/h-geo/abbrpattern.html +5 -0
  258. data/vendor/tests/tests/microformats-v2/h-geo/abbrpattern.json +12 -0
  259. data/vendor/tests/tests/microformats-v2/h-geo/altitude.html +8 -0
  260. data/vendor/tests/tests/microformats-v2/h-geo/altitude.json +13 -0
  261. data/vendor/tests/tests/microformats-v2/h-geo/change-log.html +67 -0
  262. data/vendor/tests/tests/microformats-v2/h-geo/hidden.html +10 -0
  263. data/vendor/tests/tests/microformats-v2/h-geo/hidden.json +12 -0
  264. data/vendor/tests/tests/microformats-v2/h-geo/justaname.html +3 -0
  265. data/vendor/tests/tests/microformats-v2/h-geo/justaname.json +10 -0
  266. data/vendor/tests/tests/microformats-v2/h-geo/simpleproperties.html +5 -0
  267. data/vendor/tests/tests/microformats-v2/h-geo/simpleproperties.json +12 -0
  268. data/vendor/tests/tests/microformats-v2/h-geo/valuetitleclass.html +11 -0
  269. data/vendor/tests/tests/microformats-v2/h-geo/valuetitleclass.json +12 -0
  270. data/vendor/tests/tests/microformats-v2/h-news/all.html +35 -0
  271. data/vendor/tests/tests/microformats-v2/h-news/all.json +51 -0
  272. data/vendor/tests/tests/microformats-v2/h-news/change-log.html +78 -0
  273. data/vendor/tests/tests/microformats-v2/h-news/minimum.html +24 -0
  274. data/vendor/tests/tests/microformats-v2/h-news/minimum.json +40 -0
  275. data/vendor/tests/tests/microformats-v2/h-org/change-log.html +57 -0
  276. data/vendor/tests/tests/microformats-v2/h-org/hyperlink.html +1 -0
  277. data/vendor/tests/tests/microformats-v2/h-org/hyperlink.json +11 -0
  278. data/vendor/tests/tests/microformats-v2/h-org/simple.html +1 -0
  279. data/vendor/tests/tests/microformats-v2/h-org/simple.json +10 -0
  280. data/vendor/tests/tests/microformats-v2/h-org/simpleproperties.html +4 -0
  281. data/vendor/tests/tests/microformats-v2/h-org/simpleproperties.json +12 -0
  282. data/vendor/tests/tests/microformats-v2/h-product/aggregate.html +21 -0
  283. data/vendor/tests/tests/microformats-v2/h-product/aggregate.json +45 -0
  284. data/vendor/tests/tests/microformats-v2/h-product/change-log.html +62 -0
  285. data/vendor/tests/tests/microformats-v2/h-product/justahyperlink.html +1 -0
  286. data/vendor/tests/tests/microformats-v2/h-product/justahyperlink.json +11 -0
  287. data/vendor/tests/tests/microformats-v2/h-product/justaname.html +1 -0
  288. data/vendor/tests/tests/microformats-v2/h-product/justaname.json +10 -0
  289. data/vendor/tests/tests/microformats-v2/h-product/simpleproperties.html +10 -0
  290. data/vendor/tests/tests/microformats-v2/h-product/simpleproperties.json +26 -0
  291. data/vendor/tests/tests/microformats-v2/h-recipe/all.html +63 -0
  292. data/vendor/tests/tests/microformats-v2/h-recipe/all.json +54 -0
  293. data/vendor/tests/tests/microformats-v2/h-recipe/change-log.html +62 -0
  294. data/vendor/tests/tests/microformats-v2/h-recipe/minimum.html +7 -0
  295. data/vendor/tests/tests/microformats-v2/h-recipe/minimum.json +17 -0
  296. data/vendor/tests/tests/microformats-v2/h-resume/affiliation.html +12 -0
  297. data/vendor/tests/tests/microformats-v2/h-resume/affiliation.json +20 -0
  298. data/vendor/tests/tests/microformats-v2/h-resume/change-log.html +78 -0
  299. data/vendor/tests/tests/microformats-v2/h-resume/contact.html +17 -0
  300. data/vendor/tests/tests/microformats-v2/h-resume/contact.json +26 -0
  301. data/vendor/tests/tests/microformats-v2/h-resume/education.html +13 -0
  302. data/vendor/tests/tests/microformats-v2/h-resume/education.json +30 -0
  303. data/vendor/tests/tests/microformats-v2/h-resume/justaname.html +1 -0
  304. data/vendor/tests/tests/microformats-v2/h-resume/justaname.json +10 -0
  305. data/vendor/tests/tests/microformats-v2/h-resume/skill.html +12 -0
  306. data/vendor/tests/tests/microformats-v2/h-resume/skill.json +12 -0
  307. data/vendor/tests/tests/microformats-v2/h-resume/work.html +16 -0
  308. data/vendor/tests/tests/microformats-v2/h-resume/work.json +31 -0
  309. data/vendor/tests/tests/microformats-v2/h-review-aggregate/change-log.html +78 -0
  310. data/vendor/tests/tests/microformats-v2/h-review-aggregate/hevent.html +13 -0
  311. data/vendor/tests/tests/microformats-v2/h-review-aggregate/hevent.json +23 -0
  312. data/vendor/tests/tests/microformats-v2/h-review-aggregate/justahyperlink.html +8 -0
  313. data/vendor/tests/tests/microformats-v2/h-review-aggregate/justahyperlink.json +19 -0
  314. data/vendor/tests/tests/microformats-v2/h-review-aggregate/simpleproperties.html +18 -0
  315. data/vendor/tests/tests/microformats-v2/h-review-aggregate/simpleproperties.json +26 -0
  316. data/vendor/tests/tests/microformats-v2/h-review/change-log.html +84 -0
  317. data/vendor/tests/tests/microformats-v2/h-review/hyperlink.html +1 -0
  318. data/vendor/tests/tests/microformats-v2/h-review/hyperlink.json +11 -0
  319. data/vendor/tests/tests/microformats-v2/h-review/implieditem.html +4 -0
  320. data/vendor/tests/tests/microformats-v2/h-review/implieditem.json +19 -0
  321. data/vendor/tests/tests/microformats-v2/h-review/item.html +8 -0
  322. data/vendor/tests/tests/microformats-v2/h-review/item.json +20 -0
  323. data/vendor/tests/tests/microformats-v2/h-review/justaname.html +1 -0
  324. data/vendor/tests/tests/microformats-v2/h-review/justaname.json +10 -0
  325. data/vendor/tests/tests/microformats-v2/h-review/photo.html +1 -0
  326. data/vendor/tests/tests/microformats-v2/h-review/photo.json +11 -0
  327. data/vendor/tests/tests/microformats-v2/h-review/vcard.html +23 -0
  328. data/vendor/tests/tests/microformats-v2/h-review/vcard.json +48 -0
  329. data/vendor/tests/tests/microformats-v2/rel/change-log.html +67 -0
  330. data/vendor/tests/tests/microformats-v2/rel/duplicate-rels.html +10 -0
  331. data/vendor/tests/tests/microformats-v2/rel/duplicate-rels.json +75 -0
  332. data/vendor/tests/tests/microformats-v2/rel/license.html +1 -0
  333. data/vendor/tests/tests/microformats-v2/rel/license.json +12 -0
  334. data/vendor/tests/tests/microformats-v2/rel/nofollow.html +1 -0
  335. data/vendor/tests/tests/microformats-v2/rel/nofollow.json +12 -0
  336. data/vendor/tests/tests/microformats-v2/rel/rel-urls.html +8 -0
  337. data/vendor/tests/tests/microformats-v2/rel/rel-urls.json +33 -0
  338. data/vendor/tests/tests/microformats-v2/rel/varying-text-duplicate-rels.html +4 -0
  339. data/vendor/tests/tests/microformats-v2/rel/varying-text-duplicate-rels.json +20 -0
  340. data/vendor/tests/tests/microformats-v2/rel/xfn-all.html +19 -0
  341. data/vendor/tests/tests/microformats-v2/rel/xfn-all.json +92 -0
  342. data/vendor/tests/tests/microformats-v2/rel/xfn-elsewhere.html +10 -0
  343. data/vendor/tests/tests/microformats-v2/rel/xfn-elsewhere.json +40 -0
  344. metadata +533 -57
  345. data/CHANGELOG.rdoc +0 -6
  346. data/LICENSE +0 -20
  347. data/README.rdoc +0 -147
  348. data/lib/address.rb +0 -97
  349. data/lib/calendar.rb +0 -40
  350. data/lib/event.rb +0 -156
  351. data/lib/formatting_helpers.rb +0 -57
  352. data/lib/helpers.rb +0 -74
  353. data/lib/vcard.rb +0 -177
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5c09dd3a9534b0c5a36897e4be9b8897c893fd0c
4
+ data.tar.gz: 5399942d007058cc68e35051ee38647594939df5
5
+ SHA512:
6
+ metadata.gz: d2a67b6925a3109f46dbecf6eb0a2283ba88b23e00f66d54f93d083cef7af0fa96840982a7833db0f77afdbd5b0a306e9fab482dfb027c5b04d43dc0fd7e32ad
7
+ data.tar.gz: 88f38a7593acc3393c58e1f1412e9f54e5b1ece357fda1596de67b2a13fb2dcd26c503a4435568bc3a66ebc73bd4d1146721c9b604b8beb9fd96bbe1f0bbbb95
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ coverage
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format doc
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.5
4
+ script: bundle exec rspec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in microformats.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard "rspec" do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch("spec/spec_helper.rb") { "spec" }
5
+ end
data/LICENSE.md ADDED
@@ -0,0 +1,36 @@
1
+ # Creative Commons Legal Code
2
+
3
+ ## CC0 1.0 Universal
4
+
5
+ http://creativecommons.org/publicdomain/zero/1.0
6
+
7
+ Official translations of this legal tool are available> CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER.
8
+
9
+ ### _Statement of Purpose_
10
+
11
+ The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work").
12
+
13
+ Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others.
14
+
15
+ For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights.
16
+
17
+ **1. Copyright and Related Rights.** A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following:
18
+
19
+ 1. the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work;
20
+ 2. moral rights retained by the original author(s) and/or performer(s);
21
+ 3. publicity and privacy rights pertaining to a person's image or likeness depicted in a Work;
22
+ 4. rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below;
23
+ 5. rights protecting the extraction, dissemination, use and reuse of data in a Work;
24
+ 6. database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and
25
+ 7. other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof.
26
+
27
+ **2. Waiver.** To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose.
28
+
29
+ **3. Public License Fallback.** Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose.
30
+
31
+ **4. Limitations and Disclaimers.**
32
+
33
+ 1. No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document.
34
+ 2. Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.
35
+ 3. Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work.
36
+ 4. Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work.
data/README.md ADDED
@@ -0,0 +1,228 @@
1
+ # Microformats (ruby)
2
+
3
+ [![Build Status](https://travis-ci.org/indieweb/microformats-ruby.svg)](https://travis-ci.org/indieweb/microformats-ruby)
4
+ [![Code Climate](https://codeclimate.com/github/indieweb/microformats-ruby/badges/gpa.svg)](https://codeclimate.com/github/indieweb/microformats-ruby)
5
+
6
+ A Ruby gem to parse HTML containing one or more microformats and [microformats2](http://microformats.org/wiki/microformats-2)
7
+ and return a collection of dynamically defined Ruby objects, a Ruby hash or a JSON hash.
8
+
9
+
10
+ ## Development Status
11
+
12
+ Implemented:
13
+
14
+ * [parsing depth first, doc order](http://microformats.org/wiki/microformats2-parsing#parse_a_document_for_microformats)
15
+ * [parsing a p- property](http://microformats.org/wiki/microformats2-parsing#parsing_a_p-_property)
16
+ * [parsing a u- property](http://microformats.org/wiki/microformats2-parsing#parsing_a_u-_property)
17
+ * [parsing a dt- property](http://microformats.org/wiki/microformats2-parsing#parsing_a_dt-_property)
18
+ * [parsing a e- property](http://microformats.org/wiki/microformats2-parsing#parsing_an_e-_property)
19
+ * [parsing implied properties](http://microformats.org/wiki/microformats-2-parsing#parsing_for_implied_properties)
20
+ * nested properties
21
+ * nested microformat with associated property
22
+ * dynamic creation of properties
23
+ * [rel](http://microformats.org/wiki/rel)
24
+ * [normalize u-* property values](http://microformats.org/wiki/microformats2-parsing-faq#normalizing_u-.2A_property_values)
25
+ * nested microformat without associated property
26
+ * [value-class-pattern](http://microformats.org/wiki/value-class-pattern)
27
+ * recognition of [vendor extensions](http://microformats.org/wiki/microformats2#VENDOR_EXTENSIONS)
28
+ * backward compatible support for microformats v1
29
+
30
+ Not Implemented:
31
+
32
+ * [include-pattern](http://microformats.org/wiki/include-pattern)
33
+
34
+
35
+ ## Current Version
36
+
37
+ 4.0.0
38
+
39
+ ![Version 4.0.0](https://img.shields.io/badge/VERSION-4.0.0-green.svg)
40
+
41
+
42
+ ## Requirements
43
+
44
+ * [nokogiri](https://github.com/sparklemotion/nokogiri)
45
+ * [json](https://github.com/flori/json)
46
+
47
+
48
+ ## Installation
49
+
50
+ Add this line to your application's Gemfile:
51
+
52
+ ```ruby
53
+ gem "microformats"
54
+ ```
55
+
56
+ And then execute:
57
+
58
+ ```
59
+ bundle
60
+ ```
61
+
62
+ Or install it yourself as:
63
+
64
+ ```
65
+ gem install microformats
66
+ ```
67
+
68
+
69
+ ## Usage
70
+
71
+ ```ruby
72
+ require "microformats"
73
+
74
+ source = "<div class='h-card'><p class='p-name'>Jessica Lynn Suttles</p></div>"
75
+ collection = Microformats.parse(source)
76
+
77
+ # getting a copy of the canonical microformats hash structure
78
+ collection.to_hash
79
+
80
+ # the above, as JSON in a string
81
+ collection.to_json
82
+
83
+ # shortcuts
84
+
85
+ # return a string if there is only one item found
86
+ collection.card.name #=> "Jessica Lynn Suttles"
87
+
88
+ source = "<article class='h-entry'>
89
+ <h1 class='p-name'>Microformats 2</h1>
90
+ <div class='h-card p-author'><p class='p-name'><span class='p-first-name'>Jessica</span> Lynn Suttles</p></div>
91
+ </article>"
92
+ collection = Microformats.parse(source)
93
+ collection.entry.name.to_s #=> "Microformats 2"
94
+
95
+ # accessing nested microformats
96
+ collection.entry.author.name.to_s #=> "Jessica Lynn Suttles"
97
+
98
+ # accessing nested microformats can use shortcuts or more expanded method
99
+ collection.entry.author.name #=> "Jessica Lynn Suttles"
100
+ collection.entry.properties.author.properties.name.to_s #=> "Jessica Lynn Suttles"
101
+
102
+ # use _ instead of - to get these items
103
+ collection.entry.author.first_name #=> "Jessica"
104
+ collection.rel_urls #=> {}
105
+
106
+ source = "<article class='h-entry'>
107
+ <h1 class='p-name'>Microformats 2</h1>
108
+ <div class='h-card p-author'><p class='p-name'><span class='p-first-name'>Jessica</span> Lynn Suttles</p></div>
109
+ <div class='h-card p-author'><p class='p-name'><span class='p-first-name'>Brandon</span> Edens</p></div>
110
+ </article>"
111
+ collection = Microformats.parse(source)
112
+
113
+ # arrays of items with always take the first item by default
114
+ collection.entry.author.name #=> "Jessica Lynn Suttles"
115
+ collection.entry.author(1).name #=> "Brandon Edens"
116
+
117
+ # get the actual array with :all
118
+ collection.entry.author(:all).count #=> 2
119
+ collection.entry.author(:all)[1].name #=> "Brandon Edens"
120
+
121
+ ```
122
+
123
+ * `source` can be a URL, filepath, or HTML
124
+
125
+
126
+ ## Ruby Gem release process
127
+
128
+ Check out latest code from GitHub repo.
129
+
130
+ ```
131
+ git pull origin master
132
+ ```
133
+
134
+ Make sure the version has been bumped up in all four places:
135
+
136
+ - [lib/microformats/version.rb](https://github.com/indieweb/microformats-ruby/blob/master/lib/microformats/version.rb#L2)
137
+ - [README.md (three places)](https://github.com/indieweb/microformats-ruby/blob/master/README.md)
138
+
139
+ Do a test build locally to make sure it builds properly.
140
+
141
+ ```
142
+ rake build
143
+ ```
144
+
145
+ If that works, then do a test install locally.
146
+
147
+ ```
148
+ rake install
149
+ ```
150
+
151
+ If that works, uninstall the gem.
152
+
153
+ ```
154
+ gem uninstall microformats
155
+ ```
156
+
157
+ Clean up any mess made from testing.
158
+
159
+ ```
160
+ rake clean
161
+ rake clobber
162
+ ```
163
+
164
+ Assuming your one of the gem owners and have release privileges, release the gem!
165
+
166
+ ```
167
+ rake release
168
+ ```
169
+
170
+ If that works, you’ve just release a new version of the gem! Yay! You can see it at:
171
+
172
+ [https://rubygems.org/gems/microformats](https://rubygems.org/gems/microformats)
173
+
174
+ If `rake release` failed because of an error with your authentication to rubygems.org, follow their instructions in the error message. Then repeat the `rake release` step.
175
+
176
+ If any other errors failed along the way before `rake release`, try to figure them out or reach out to the IRC/Slack channel for help.
177
+
178
+ Good luck.
179
+
180
+
181
+ ## Authors
182
+
183
+ - Ben Roberts / [@dissolve](https://github.com/dissolve)
184
+ - Jessica Lynn Suttles / [@jlsuttles](https://github.com/jlsuttles)
185
+ - Shane Becker / [@veganstraightedge](https://github.com/veganstraightedge)
186
+ - Chris Stringer / [@jcstringer](https://github.com/jcstringer)
187
+ - Michael Mitchell / [@variousred](https://github.com/variousred)
188
+ - Jessica Dillon / [@jessicard](https://github.com/jessicard)
189
+ - Jeena Paradies / [@jeena](https://github.com/jeena)
190
+ - Marty McGuire / [@martymcguire](https://github.com/martymcguire)
191
+
192
+ ## Contributions
193
+
194
+ 1. Fork it
195
+ 2. Get it running (see Installation above)
196
+ 3. Create your feature branch (`git checkout -b my-new-feature`)
197
+ 4. Write your code and **specs**
198
+ 5. Commit your changes (`git commit -am 'Add some feature'`)
199
+ 6. Push to the branch (`git push origin my-new-feature`)
200
+ 7. Create new Pull Request
201
+
202
+ If you find bugs, have feature requests or questions, please
203
+ [file an issue](https://github.com/indieweb/microformats-ruby/issues).
204
+
205
+
206
+ ## Testing
207
+
208
+ ### Specs
209
+
210
+ This uses a copy of [microformats tests repo](https://github.com/microformats/tests).
211
+
212
+ To run specs
213
+ ```
214
+ rake spec
215
+ ```
216
+
217
+ ###Interactive
218
+
219
+ You can use the code interacively for testing but running
220
+ ```
221
+ bundle console
222
+ ```
223
+
224
+ ## License
225
+
226
+ Microformats (ruby) is dedicated to the public domain using Creative Commons -- CC0 1.0 Universal.
227
+
228
+ http://creativecommons.org/publicdomain/zero/1.0
data/Rakefile CHANGED
@@ -1,27 +1,9 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'rake/rdoctask'
4
- # require 'rake/gempackagetask'
5
- # require 'rcov/rcovtask'
6
- # require 'date'
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "nokogiri"
4
+ require "open-uri"
5
+ require "pp"
7
6
 
8
- require 'spec/rake/spectask'
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ task :default => [:spec]
9
9
 
10
- desc 'Default: run the specs.'
11
- task :default => :spec
12
-
13
- Spec::Rake::SpecTask.new do |t|
14
- t.warning = true
15
- end
16
-
17
- namespace :doc do
18
- desc "Generate documentation for the gem."
19
- Rake::RDocTask.new("gem") { |rdoc|
20
- rdoc.rdoc_dir = 'doc'
21
- rdoc.title = "Microformats"
22
- rdoc.options << '--line-numbers' << '--inline-source'
23
- rdoc.options << '--charset' << 'utf-8'
24
- rdoc.rdoc_files.include('README.rdoc')
25
- rdoc.rdoc_files.include('lib/**/*.rb')
26
- }
27
- end
data/lib/microformats.rb CHANGED
@@ -1,12 +1,28 @@
1
- module Microformats
1
+ require "nokogiri"
2
+ require "open-uri"
3
+ require "json"
2
4
 
3
- end
5
+ require "microformats/version"
6
+ require "microformats/absolute_uri"
7
+ require "microformats/parser_core"
8
+ require "microformats/parser"
9
+ require "microformats/format_parser"
10
+ require "microformats/property_parser"
11
+ require "microformats/time_property_parser"
12
+ require "microformats/results/parser_result"
13
+ require "microformats/results/collection"
14
+ require "microformats/results/property_set"
4
15
 
5
- require 'time'
16
+ module Microformats
17
+ class << self
18
+ def parse(html, base: nil)
19
+ Parser.new.parse(html, base: base)
20
+ end
6
21
 
7
- require 'formatting_helpers'
8
- require 'vcard'
9
- require 'address'
10
- require 'calendar'
11
- require 'event'
12
- require 'helpers'
22
+ def read_html(html)
23
+ Parser.new.read_html(html)
24
+ end
25
+ end # class << self
26
+
27
+ class InvalidPropertyPrefix < StandardError; end
28
+ end
@@ -0,0 +1,30 @@
1
+ module Microformats
2
+ class AbsoluteUri
3
+ attr_accessor :base, :relative
4
+
5
+ def initialize(relative, base: nil)
6
+ @base = base
7
+ @relative = relative
8
+ @base.strip! unless @base.nil?
9
+ @relative.strip! unless @relative.nil?
10
+ end
11
+
12
+ def absolutize
13
+ #TODO: i'm sure this could be improved a bit
14
+ return nil if relative.nil? or relative == ""
15
+ return relative if relative =~ /^https?:\/\//
16
+
17
+ uri = URI.parse(relative)
18
+
19
+ if base && !uri.absolute?
20
+ uri = URI.join(base.to_s, relative.to_s)
21
+ end
22
+
23
+ uri.normalize!
24
+ uri.to_s
25
+
26
+ rescue URI::BadURIError, URI::InvalidURIError => e
27
+ relative.to_s
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,343 @@
1
+ module Microformats
2
+ class FormatParser < ParserCore
3
+
4
+ def parse(element, base:nil, element_type:nil, format_class_array:[], backcompat:false)
5
+ @base = base
6
+
7
+ @mode_backcompat = backcompat
8
+
9
+ @properties = {}
10
+ @children = []
11
+
12
+ @format_property_type = element_type
13
+ @value = nil
14
+
15
+ @mode_backcompat = backcompat
16
+
17
+ @fmt_classes = format_class_array
18
+
19
+ parse_node(element.children)
20
+
21
+ ##### Implied Properties######
22
+ #NOTE: much of this code may be simplified by using element.css, not sure yet, but coding to have passing tests first
23
+ # can optimize this later
24
+ unless @mode_backcompat
25
+ if @properties['name'].nil?
26
+
27
+ if element.name == 'img' and not element.attribute('alt').nil?
28
+ @properties['name'] = [element.attribute('alt').value.strip]
29
+ elsif element.name == 'area' and not element.attribute('alt').nil?
30
+ @properties['name'] = [element.attribute('alt').value.strip]
31
+ elsif element.name == 'abbr' and not element.attribute('title').nil?
32
+ @properties['name'] = [element.attribute('title').value.strip]
33
+
34
+ else
35
+ child_nodes = element.children.select{|n| not n.is_a?(Nokogiri::XML::Text)}
36
+
37
+ if child_nodes.count == 1 and child_nodes.first.is_a?(Nokogiri::XML::Element) and format_classes(child_nodes.first).empty?
38
+ node = child_nodes.first
39
+
40
+ #else if .h-x>img:only-child[alt]:not([alt=""]):not[.h-*] then use that img’s alt for name
41
+ if node.name == 'img' and not node.attribute('alt').nil? and not node.attribute('alt').value.empty?
42
+ @properties['name'] = [node.attribute('alt').value.strip]
43
+
44
+ #else if .h-x>area:only-child[alt]:not([alt=""]):not[.h-*] then use that area’s alt for name
45
+ elsif node.name == 'area' and not node.attribute('alt').nil? and not node.attribute('alt').value.empty?
46
+ @properties['name'] = [node.attribute('alt').value.strip]
47
+
48
+ #else if .h-x>abbr:only-child[title]:not([title=""]):not[.h-*] then use that abbr title for name
49
+ elsif node.name == 'abbr' and not node.attribute('title').nil? and not node.attribute('title').value.empty?
50
+ @properties['name'] = [node.attribute('title').value.strip]
51
+
52
+ else
53
+ child_nodes = node.children.select{|n| not n.is_a?(Nokogiri::XML::Text)}
54
+ if child_nodes.count == 1 and child_nodes.first.is_a?(Nokogiri::XML::Element) and format_classes(child_nodes.first).empty?
55
+ node = child_nodes.first
56
+
57
+ #else if .h-x>:only-child:not[.h-*]>img:only-child[alt]:not([alt=""]):not[.h-*] then use that img’s alt for name
58
+ if node.name == 'img' and not node.attribute('alt').nil? and not node.attribute('alt').value.empty?
59
+ @properties['name'] = [node.attribute('alt').value.strip]
60
+
61
+ #else if .h-x>:only-child:not[.h-*]>area:only-child[alt]:not([alt=""]):not[.h-*] then use that area’s alt for name
62
+ elsif node.name == 'area' and not node.attribute('alt').nil? and not node.attribute('alt').value.empty?
63
+ @properties['name'] = [node.attribute('alt').value.strip]
64
+
65
+ #else if .h-x>:only-child:not[.h-*]>abbr:only-child[title]:not([title=""]):not[.h-*] use that abbr’s title for name
66
+ elsif node.name == 'abbr' and not node.attribute('title').nil? and not node.attribute('title').value.empty?
67
+ @properties['name'] = [node.attribute('title').value.strip]
68
+
69
+ else
70
+ @properties['name'] = [element.text.strip]
71
+
72
+ end
73
+ else
74
+ @properties['name'] = [element.text.strip]
75
+ end
76
+ end
77
+ else
78
+ @properties['name'] = [element.text.strip]
79
+ end
80
+ end
81
+ end # end implied name
82
+
83
+
84
+ if @properties['photo'].nil?
85
+ if element.name == 'img' and not element.attribute('src').nil?
86
+ @properties['photo'] = [element.attribute('src').value]
87
+ elsif element.name == 'object' and not element.attribute('data').nil?
88
+ @properties['photo'] = [element.attribute('data').value]
89
+ else
90
+
91
+ #else if .h-x>img[src]:only-of-type:not[.h-*] then use that img src for photo
92
+
93
+ child_img_tags_with_src = element.children.select do |child|
94
+ child.is_a?(Nokogiri::XML::Element) and child.name == 'img' and not child.attribute('src').nil?
95
+ end
96
+ if child_img_tags_with_src.count == 1
97
+ node = child_img_tags_with_src.first
98
+ if format_classes(node).empty?
99
+ @properties['photo'] = [node.attribute('src').value.strip]
100
+ end
101
+ end
102
+
103
+ if @properties['photo'].nil?
104
+
105
+ #else if .h-x>object[data]:only-of-type:not[.h-*] then use that object’s data for photo
106
+
107
+ child_object_tags_with_data = element.children.select do |child|
108
+ child.is_a?(Nokogiri::XML::Element) and child.name == 'object' and not child.attribute('data').nil?
109
+ end
110
+ if child_object_tags_with_data.count == 1
111
+ node = child_object_tags_with_data.first
112
+ if format_classes(node).empty?
113
+ @properties['photo'] = [node.attribute('data').value.strip]
114
+ end
115
+ end
116
+ end
117
+
118
+ child_elements = element.children.select do |child| not child.is_a?(Nokogiri::XML::Text) end
119
+
120
+ if @properties['photo'].nil? and child_elements.count == 1 and format_classes(child_elements.first).empty?
121
+
122
+ #else if .h-x>:only-child:not[.h-*]>img[src]:only-of-type:not[.h-*], then use that img’s src for photo
123
+
124
+ child_img_tags_with_src = child_elements.first.children.select do |child|
125
+ child.is_a?(Nokogiri::XML::Element) and child.name == 'img' and not child.attribute('src').nil?
126
+ end
127
+ if child_img_tags_with_src.count == 1
128
+ node = child_img_tags_with_src.first
129
+ if format_classes(node).empty?
130
+ @properties['photo'] = [node.attribute('src').value.strip]
131
+ end
132
+ end
133
+
134
+ if @properties['photo'].nil?
135
+
136
+ #else if .h-x>:only-child:not[.h-*]>object[data]:only-of-type:not[.h-*], then use that object’s data for photo
137
+ #
138
+ child_object_tags_with_data = child_elements.first.children.select do |child|
139
+ child.is_a?(Nokogiri::XML::Element) and child.name == 'object' and not child.attribute('data').nil?
140
+ end
141
+ if child_object_tags_with_data.count == 1
142
+ node = child_object_tags_with_data.first
143
+ if format_classes(node).empty?
144
+ @properties['photo'] = [node.attribute('data').value.strip]
145
+ end
146
+ end
147
+ end
148
+ end
149
+
150
+ end
151
+ unless @properties['photo'].nil?
152
+ @properties['photo'] = [ Microformats::AbsoluteUri.new(@properties['photo'].first, base: @base).absolutize ]
153
+ end
154
+ end
155
+
156
+ if @properties['url'].nil?
157
+ if element.name == 'a' and not element.attribute('href').nil?
158
+ @properties['url'] = [element.attribute('href').value]
159
+ elsif element.name == 'area' and not element.attribute('href').nil?
160
+ @properties['url'] = [element.attribute('href').value]
161
+ else
162
+ #else if .h-x>a[href]:only-of-type:not[.h-*], then use that [href] for url
163
+ child_a_tags_with_href = element.children.select do |child|
164
+ child.is_a?(Nokogiri::XML::Element) and child.name == 'a' and not child.attribute('href').nil?
165
+ end
166
+ if child_a_tags_with_href.count == 1
167
+ node = child_a_tags_with_href.first
168
+ if format_classes(node).empty?
169
+ @properties['url'] = [node.attribute('href').value.strip]
170
+ end
171
+ end
172
+
173
+ if @properties['url'].nil?
174
+
175
+ #else if .h-x>area[href]:only-of-type:not[.h-*], then use that [href] for url
176
+ child_area_tags_with_href = element.children.select do |child|
177
+ child.is_a?(Nokogiri::XML::Element) and child.name == 'area' and not child.attribute('href').nil?
178
+ end
179
+ if child_area_tags_with_href.count == 1
180
+ node = child_area_tags_with_href.first
181
+ if format_classes(node).empty?
182
+ @properties['url'] = [node.attribute('href').value.strip]
183
+ end
184
+ end
185
+ end
186
+
187
+ child_elements = element.children.select do |child| not child.is_a?(Nokogiri::XML::Text) end
188
+
189
+ if @properties['url'].nil? and child_elements.count == 1 and format_classes(child_elements.first).empty?
190
+ child_element = child_elements.first
191
+
192
+ #else if .h-x>:only-child:not[.h-*]>a[href]:only-of-type:not[.h-*], then use that [href] for url
193
+ child_a_tags_with_href = child_element.children.select do |child|
194
+ child.is_a?(Nokogiri::XML::Element) and child.name == 'a' and not child.attribute('href').nil?
195
+ end
196
+ if child_a_tags_with_href.count == 1
197
+ node = child_a_tags_with_href.first
198
+ if format_classes(node).empty?
199
+ @properties['url'] = [node.attribute('href').value.strip]
200
+ end
201
+ end
202
+
203
+ if @properties['url'].nil?
204
+
205
+ #else if .h-x>:only-child:not[.h-*]>area[href]:only-of-type:not[.h-*], then use that [href] for url
206
+ child_area_tags_with_href = child_element.children.select do |child|
207
+ child.is_a?(Nokogiri::XML::Element) and child.name == 'area' and not child.attribute('href').nil?
208
+ end
209
+ if child_area_tags_with_href.count == 1
210
+ node = child_area_tags_with_href.first
211
+ if format_classes(node).empty?
212
+ @properties['url'] = [node.attribute('href').value.strip]
213
+ end
214
+ end
215
+ end
216
+ end
217
+ end
218
+
219
+ unless @properties['url'].nil?
220
+ @properties['url'] = [ Microformats::AbsoluteUri.new(@properties['url'].first, base: @base).absolutize ]
221
+ end
222
+ end
223
+
224
+ end
225
+ ##### END Implied Properties when not in backcompat mode######
226
+
227
+ ### imply date for dt-end if dt-start is defined with a date ###
228
+ if not @properties['end'].nil? and not @properties['start'].nil?
229
+ start_date = nil
230
+ @properties['start'].each do |start_val|
231
+ if start_val =~ /^(\d{4}-[01]\d-[0-3]\d)/
232
+ start_date = $1 if start_date.nil?
233
+ elsif start_val =~ /^(\d{4}-[0-3]\d\d)/
234
+ start_date = $1 if start_date.nil?
235
+ end
236
+ end
237
+ unless start_date.nil?
238
+ @properties['end'].map! do |end_val|
239
+ if end_val=~ /^\d{4}-[01]\d-[0-3]\d/
240
+ end_val
241
+ elsif end_val=~ /^\d{4}-[0-3]\d\d/
242
+ end_val
243
+ else
244
+ start_date + ' ' + end_val
245
+ end
246
+ end
247
+ end
248
+ end
249
+
250
+ if @value.nil? or @value.empty?
251
+ if element_type == 'p' and not @properties['name'].nil? and not @properties['name'].empty?
252
+ @value = @properties['name'].first
253
+ elsif element_type == 'u' and not @properties['url'].nil? and not @properties['url'].empty?
254
+ @value = @properties['url'].first
255
+ elsif not element_type.nil?
256
+ @value = PropertyParser.new.parse(element, base: @base, element_type: element_type, backcompat: @mode_backcompat)
257
+ end
258
+ end
259
+
260
+ h_object = {}
261
+
262
+ h_object['value'] = @value unless @value.nil?
263
+ h_object['type'] = format_class_array
264
+ h_object['properties'] = @properties
265
+
266
+ h_object['children'] = @children unless @children.empty?
267
+
268
+ if @format_property_type == 'e'
269
+ h_object['value'] = element.text.strip
270
+ h_object['html'] = element.inner_html
271
+ end
272
+
273
+ ##todo fall back to p- dt- u- parsing if value still not set?
274
+ # not sure that is correct by the spec actually
275
+
276
+ h_object
277
+
278
+ end
279
+
280
+
281
+ def parse_element(element)
282
+
283
+ prop_classes = property_classes(element)
284
+ prop_classes = backcompat_property_classes(element) if @mode_backcompat
285
+
286
+ bc_classes_found = false
287
+ fmt_classes = format_classes(element)
288
+
289
+ if fmt_classes.empty?
290
+ fmt_classes = backcompat_format_classes(element)
291
+ bc_classes_found = true unless fmt_classes.empty?
292
+ end
293
+
294
+ if prop_classes.length >= 1
295
+
296
+ if fmt_classes.length >= 1
297
+
298
+ prop_classes.each do |element_class|
299
+ element_type = element_class.downcase.split('-')[0]
300
+ property_name = element_class.downcase.split('-')[1..-1].join('-')
301
+
302
+ parsed_format = FormatParser.new.parse(element, base:@base, element_type: element_type, format_class_array: fmt_classes, backcompat: bc_classes_found )
303
+
304
+ if @value.nil?
305
+ if @format_property_type == 'p' and property_name == 'name'
306
+ @value = parsed_format['value']
307
+ #elsif @format_property_type == 'dt' and property_name == '???'
308
+ #@value = parsed_format['value']
309
+ elsif @format_property_type == 'u' and property_name == 'url'
310
+ @value = parsed_format['value']
311
+ end
312
+ end
313
+
314
+ @properties[property_name] = [] if @properties[property_name].nil?
315
+ @properties[property_name] << parsed_format
316
+
317
+ end
318
+
319
+ else
320
+
321
+ prop_classes.each do |element_class|
322
+ element_type = element_class.downcase.split('-')[0]
323
+ property_name = element_class.downcase.split('-')[1..-1].join('-')
324
+
325
+ parsed_property = PropertyParser.new.parse(element, base: @base, element_type: element_type, backcompat: @mode_backcompat)
326
+
327
+ if not parsed_property.nil? and not parsed_property.empty?
328
+ @properties[property_name] = [] if @properties[property_name].nil?
329
+ @properties[property_name] << parsed_property
330
+ end
331
+ end
332
+ parse_nodeset(element.children)
333
+ end
334
+
335
+ elsif fmt_classes.length >= 1
336
+ @children << FormatParser.new.parse(element, base: @base, format_class_array: fmt_classes, backcompat: bc_classes_found )
337
+ else
338
+ parse_nodeset(element.children)
339
+ end
340
+ end
341
+
342
+ end
343
+ end