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
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,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - jruby-18mode # JRuby in 1.8 mode
5
+ - jruby-19mode # JRuby in 1.9 mode
6
+ - rbx-18mode
7
+ - rbx-19mode
8
+ - 1.8.7
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in microformats2.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.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 G5
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,43 +1,134 @@
1
- # Microformats
1
+ # Microformats2
2
2
 
3
- http://github.com/veganstraightedge/microformats2
3
+ [![Build Status](https://travis-ci.org/G5/microformats2.png?branch=master)](https://travis-ci.org/G5/microformats2)
4
+ [![Code Climate](https://codeclimate.com/github/G5/microformats2.png)](https://codeclimate.com/github/G5/microformats2)
4
5
 
5
- ## DESCRIPTION
6
+ A Ruby gem to parse HTML containing one or more [microformats2](http://microformats.org/wiki/microformats-2)
7
+ and return a collection of dynamically defined Ruby objects.
6
8
 
7
- Generic Microformats 2 Extractor
9
+ A work in progress.
8
10
 
9
- ## FEATURES/PROBLEMS
11
+ Implemented:
10
12
 
11
- * parses and extracts [Microformats 2](http://microformats.org/wiki/microformats-2) syntax
12
- * needs more test cases
13
- * needs better docs
14
- * needs to deal with nested microformats
15
- * needs to deal with class-value pattern
13
+ * [parsing depth first, doc order](parse_a_document_for_microformats)
14
+ * [parsing a p- property](http://microformats.org/wiki/microformats2-parsing#parsing_a_p-_property)
15
+ * [parsing a u- property](http://microformats.org/wiki/microformats2-parsing#parsing_a_u-_property)
16
+ * [parsing a dt- property](http://microformats.org/wiki/microformats2-parsing#parsing_a_dt-_property)
17
+ * [parsing a e- property](http://microformats.org/wiki/microformats2-parsing#parsing_a_e-_property)
18
+ * [parsing implied properties](http://microformats.org/wiki/microformats-2-parsing#parsing_for_implied_properties)
19
+ * nested properties
20
+ * nested microformat with associated property
16
21
 
17
- ## SYNOPSIS
22
+ Not Implemented:
18
23
 
19
- Microformats2.parse(File.open("example.html"))
24
+ * [normalize u-* property values](http://microformats.org/wiki/microformats2-parsing-faq#normalizing_u-.2A_property_values)
25
+ * nested microformat without associated property
26
+ * [rel](http://microformats.org/wiki/rel)
27
+ * [value-class-pattern](http://microformats.org/wiki/value-class-pattern)
28
+ * [include-pattern](http://microformats.org/wiki/include-pattern)
29
+ * recognition of [vendor extensions](http://microformats.org/wiki/microformats2#VENDOR_EXTENSIONS)
30
+ * backwards compatable support for microformats v1
20
31
 
21
- ## REQUIREMENTS
22
32
 
23
- * Hoe
24
- * Nokogiri
33
+ ## Current Version
25
34
 
26
- ## INSTALL
35
+ 2.0.0.pre1
27
36
 
28
- sudo gem install microformats2
29
37
 
30
- ## DEVELOPERS
38
+ ## Requirements
31
39
 
32
- After checking out the source, run:
40
+ * "nokogiri", "~> 1.5.6"
41
+ * "json", "~> 1.7.6"
42
+ * "activesupport", "~> 3.2.12"
33
43
 
34
- rake newb
35
44
 
36
- This task will install any missing dependencies,
37
- run the tests/specs, and generate the RDoc.
45
+ ## Installation
38
46
 
39
- ## LICENSE
47
+ Add this line to your application's Gemfile:
40
48
 
41
- **PUBLIC DOMAIN.**
42
- Your heart is as free as the air you breathe.
43
- The ground you stand on is liberated territory.
49
+ gem 'microformats2'
50
+
51
+ And then execute:
52
+
53
+ $ bundle
54
+
55
+ Or install it yourself as:
56
+
57
+ $ gem install microformats2
58
+
59
+
60
+ ## Usage
61
+
62
+ ```ruby
63
+ require "microformats2"
64
+
65
+ source = '<div class="h-card"><p class="p-name">Jessica Lynn Suttles</p></div>'
66
+ collection = Microformats.parse(source)
67
+ collection.cards.first.names.first.to_s #=> "Jessica Lynn Suttles"
68
+ collection.card.name.to_s #=> "Jessica Lynn Suttles"
69
+ ```
70
+
71
+ * `source` can be a URL, filepath, or HTML
72
+
73
+ ## Authors
74
+
75
+ * Jessica Lynn Suttles / [@jlsuttles](https://github.com/jlsuttles)
76
+
77
+
78
+ ## Contributions
79
+
80
+ 1. Fork it
81
+ 2. Get it running (see Installation above)
82
+ 3. Create your feature branch (`git checkout -b my-new-feature`)
83
+ 4. Write your code and **specs**
84
+ 5. Commit your changes (`git commit -am 'Add some feature'`)
85
+ 6. Push to the branch (`git push origin my-new-feature`)
86
+ 7. Create new Pull Request
87
+
88
+ If you find bugs, have feature requests or questions, please
89
+ [file an issue](https://github.com/G5/microformats2/issues).
90
+
91
+
92
+ ## Specs
93
+
94
+ To update spec cases that are scraped from other sites.
95
+ **Warning:** This could break specs.
96
+ ```bash
97
+ rake specs:update
98
+ ```
99
+
100
+ To run specs
101
+ ```bash
102
+ rake spec
103
+ ```
104
+
105
+ To keep specs running
106
+ ```bash
107
+ guard
108
+ ```
109
+
110
+
111
+ ## License
112
+
113
+ Copyright (c) 2013 G5
114
+
115
+ MIT License
116
+
117
+ Permission is hereby granted, free of charge, to any person obtaining
118
+ a copy of this software and associated documentation files (the
119
+ "Software"), to deal in the Software without restriction, including
120
+ without limitation the rights to use, copy, modify, merge, publish,
121
+ distribute, sublicense, and/or sell copies of the Software, and to
122
+ permit persons to whom the Software is furnished to do so, subject to
123
+ the following conditions:
124
+
125
+ The above copyright notice and this permission notice shall be
126
+ included in all copies or substantial portions of the Software.
127
+
128
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
129
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
130
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
131
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
132
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
133
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
134
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,13 +1,69 @@
1
- # -*- ruby -*-
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "nokogiri"
4
+ require "open-uri"
5
+ require "pp"
2
6
 
3
- require 'rubygems'
4
- require 'hoe'
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ task :default => [:spec]
5
9
 
6
- Hoe.spec 'microformats2' do
7
- developer('Shane Becker', 'veganstraightedge@gmail.com')
8
- extra_deps << ['nokogiri', ">= 0"]
9
- self.readme_file = "README.md"
10
- end
10
+ namespace :specs do
11
+ task :update do
12
+ sources = [
13
+ { dir: "microformats.org",
14
+ urls: ["http://microformats.org/wiki/microformats-2"],
15
+ html_selector: ".source-html4strict",
16
+ json_selector: ".source-javascript",
17
+ html_method: "inner_text"
18
+ },
19
+ { dir: "microformat2-node.jit.su",
20
+ urls: [
21
+ "http://microformat2-node.jit.su/h-adr.html",
22
+ "http://microformat2-node.jit.su/h-card.html",
23
+ "http://microformat2-node.jit.su/h-entry.html",
24
+ "http://microformat2-node.jit.su/h-event.html",
25
+ "http://microformat2-node.jit.su/h-geo.html",
26
+ "http://microformat2-node.jit.su/h-news.html",
27
+ "http://microformat2-node.jit.su/h-org.html",
28
+ "http://microformat2-node.jit.su/h-product.html",
29
+ "http://microformat2-node.jit.su/h-recipe.html",
30
+ "http://microformat2-node.jit.su/h-resume.html",
31
+ "http://microformat2-node.jit.su/h-review-aggregate.html",
32
+ "http://microformat2-node.jit.su/h-review.html",
33
+ "http://microformat2-node.jit.su/rel.html",
34
+ "http://microformat2-node.jit.su/includes.html",
35
+ ],
36
+ html_selector: ".e-x-microformat",
37
+ json_selector: ".language-json",
38
+ html_method: "inner_html"
39
+ }
40
+ ]
41
+
42
+ sources.each do |source|
43
+ source[:urls].each do |url|
44
+ document = Nokogiri::HTML(open(url).read)
45
+ html = document.css(source[:html_selector]).map { |e| e.send(source[:html_method]) }
46
+ json = document.css(source[:json_selector]).map { |e| e.inner_text }
47
+
48
+ name = url.split("/").last.gsub(/[.]\w+/, "")
49
+ path = File.join "spec/support/cases", source[:dir], name
50
+
51
+ FileUtils.mkdir_p(path)
11
52
 
53
+ ([html.length, json.length].min).times do |index|
12
54
 
13
- # vim: syntax=ruby
55
+ File.open(File.join(path, "#{name}-#{index}.html"), "w") do |f|
56
+ f.write "<!-- #{url} -->\n"
57
+ f.write html[index]
58
+ end
59
+
60
+ File.open(File.join(path, "#{name}-#{index}.js"), "w") do |f|
61
+ f.write "// #{url}\n"
62
+ f.write json[index]
63
+ end
64
+ end
65
+
66
+ end
67
+ end
68
+ end
69
+ end
data/lib/microformats2.rb CHANGED
@@ -1,121 +1,36 @@
1
- require 'nokogiri'
2
- require 'time'
3
- require 'date'
1
+ require "nokogiri"
2
+ require "open-uri"
3
+ require "json"
4
+ require "active_support/inflector"
5
+
6
+ require "microformats2/version"
7
+ require "microformats2/format_parser"
8
+ require "microformats2/property_parser"
9
+ require "microformats2/collection"
10
+ require "microformats2/format"
11
+ require "microformats2/property/foundation"
12
+ require "microformats2/property/text"
13
+ require "microformats2/property/url"
14
+ require "microformats2/property/date_time"
15
+ require "microformats2/property/embedded"
16
+ require "microformats2/property"
17
+ require "microformats2/implied_property/foundation"
18
+ require "microformats2/implied_property/name"
19
+ require "microformats2/implied_property/photo"
20
+ require "microformats2/implied_property/url"
4
21
 
5
22
  module Microformats2
6
- VERSION = "1.0.2"
7
-
8
- class LoadError < StandardError; end
9
-
10
- def self.parse(html)
11
- raise LoadError, "argument must be a String or File" unless [String, File].include?(html.class)
12
-
13
- html = html.read if IO === html
14
-
15
- doc = Nokogiri::HTML(html)
16
- microformats = Hash.new{|hash, key| hash[key] = Array.new}
17
- doc.css("*[class*=h-]").each do |microformat|
18
- microformat.attribute("class").to_s.split.each do |mf_class|
19
- if mf_class =~ /^h-/
20
- constant_name = mf_class.gsub("-","_").gsub(/^([a-z])/){$1.upcase}.gsub(/_(.)/) { $1.upcase }
21
-
22
- if Object.const_defined?(constant_name)
23
- klass = Object.const_get(constant_name)
24
- else
25
- klass = Class.new
26
- Object.const_set constant_name, klass
27
- end
28
-
29
- obj = klass.new
30
-
31
- add_properties(microformat, obj)
32
-
33
- microformats[constant_name.downcase.to_sym] << obj
34
- end
35
- end
36
- end
37
-
38
- microformats
39
- end
40
-
41
- def self.add_method(obj, method_name)
42
- unless obj.respond_to?(method_name)
43
- obj.class.class_eval { attr_accessor method_name }
23
+ class << self
24
+ def parse(html)
25
+ html = read_html(html)
26
+ document = Nokogiri::HTML(html)
27
+ Collection.new(document).parse
44
28
  end
45
29
 
46
- obj
47
- end
48
-
49
- def self.populate_method(obj, method_name, value)
50
- if cur = obj.send(method_name)
51
- if cur.kind_of? Array
52
- cur << value
53
- else
54
- obj.send("#{method_name}=", [cur, value])
55
- end
56
- else
57
- obj.send("#{method_name}=", value)
58
- end
59
- end
60
-
61
- class Stripper
62
- def transform(property)
63
- property.text.gsub(/\n+/, " ").gsub(/\s+/, " ").strip
64
- end
65
- end
66
-
67
- class URL
68
- def transform(property)
69
- (property.attribute("href") || property.text).to_s
70
- end
71
- end
72
-
73
- class Date
74
- def transform(property)
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
82
- end
83
- end
84
-
85
- class TimeThingy
86
- def transform(property)
87
- Time.parse((property.attribute("title") || property.text).to_s)
88
- end
89
- end
90
-
91
- FormatClass = {
92
- "p" => Stripper.new,
93
- "n" => Stripper.new,
94
- "e" => Stripper.new,
95
- "i" => Stripper.new,
96
- "u" => URL.new,
97
- "d" => Date.new,
98
- "t" => TimeThingy.new
99
- }
100
-
101
- def self.add_properties(mf, obj)
102
- FormatClass.each do |letter, trans|
103
- mf.css("*[class*=#{letter}-]").each do |property|
104
- property.attribute("class").to_s.split.each do |css_class|
105
- if css_class[0..1] == "#{letter}-"
106
- css_class = css_class[2..-1].gsub("-","_")
107
- method_name = css_class.gsub("-","_")
108
- value = trans.transform(property)
109
-
110
- if method_name == "class"
111
- method_name = "klass"
112
- end
113
-
114
- add_method(obj, method_name)
115
- populate_method(obj, method_name, value)
116
- end
117
- end
118
- end
30
+ def read_html(html)
31
+ open(html).read
32
+ rescue Errno::ENOENT, Errno::ENAMETOOLONG => e
33
+ html
119
34
  end
120
- end
35
+ end # class << self
121
36
  end