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.
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/Guardfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +117 -26
- data/Rakefile +65 -9
- data/lib/microformats2.rb +30 -115
- data/lib/microformats2/collection.rb +71 -0
- data/lib/microformats2/format.rb +101 -0
- data/lib/microformats2/format_parser.rb +59 -0
- data/lib/microformats2/implied_property/foundation.rb +58 -0
- data/lib/microformats2/implied_property/name.rb +34 -0
- data/lib/microformats2/implied_property/photo.rb +24 -0
- data/lib/microformats2/implied_property/url.rb +20 -0
- data/lib/microformats2/property.rb +10 -0
- data/lib/microformats2/property/date_time.rb +31 -0
- data/lib/microformats2/property/embedded.rb +9 -0
- data/lib/microformats2/property/foundation.rb +80 -0
- data/lib/microformats2/property/text.rb +16 -0
- data/lib/microformats2/property/url.rb +18 -0
- data/lib/microformats2/property_parser.rb +54 -0
- data/lib/microformats2/version.rb +3 -0
- data/microformats2.gemspec +30 -0
- data/spec/lib/microformats2/collection_spec.rb +181 -0
- data/spec/lib/microformats2/implied_property/name_spec.rb +31 -0
- data/spec/lib/microformats2/implied_property/photo_spec.rb +31 -0
- data/spec/lib/microformats2/implied_property/url_spec.rb +31 -0
- data/spec/lib/microformats2_spec.rb +30 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/support/cases/microformat2-node.jit.su/h-adr/h-adr-0.html +3 -0
- data/spec/support/cases/microformat2-node.jit.su/h-adr/h-adr-0.js +10 -0
- data/spec/support/cases/microformat2-node.jit.su/h-adr/h-adr-1.html +10 -0
- data/spec/support/cases/microformat2-node.jit.su/h-adr/h-adr-1.js +16 -0
- data/spec/support/cases/microformat2-node.jit.su/h-adr/h-adr-2.html +12 -0
- data/spec/support/cases/microformat2-node.jit.su/h-adr/h-adr-2.js +16 -0
- data/spec/support/cases/microformat2-node.jit.su/h-adr/h-adr-3.html +6 -0
- data/spec/support/cases/microformat2-node.jit.su/h-adr/h-adr-3.js +12 -0
- data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-0.html +3 -0
- data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-0.js +10 -0
- data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-1.html +3 -0
- data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-1.js +11 -0
- data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-2.html +4 -0
- data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-2.js +12 -0
- data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-3.html +11 -0
- data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-3.js +15 -0
- data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-4.html +6 -0
- data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-4.js +26 -0
- data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-5.html +6 -0
- data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-5.js +30 -0
- data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-6.html +6 -0
- data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-6.js +29 -0
- data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-7.html +16 -0
- data/spec/support/cases/microformat2-node.jit.su/h-card/h-card-7.js +15 -0
- data/spec/support/cases/microformat2-node.jit.su/h-entry/h-entry-0.html +4 -0
- data/spec/support/cases/microformat2-node.jit.su/h-entry/h-entry-0.js +10 -0
- data/spec/support/cases/microformat2-node.jit.su/h-entry/h-entry-1.html +3 -0
- data/spec/support/cases/microformat2-node.jit.su/h-entry/h-entry-1.js +11 -0
- data/spec/support/cases/microformat2-node.jit.su/h-entry/h-entry-2.html +21 -0
- data/spec/support/cases/microformat2-node.jit.su/h-entry/h-entry-2.js +28 -0
- data/spec/support/cases/microformat2-node.jit.su/h-entry/h-entry-3.html +22 -0
- data/spec/support/cases/microformat2-node.jit.su/h-entry/h-entry-3.js +21 -0
- data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-0.html +3 -0
- data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-0.js +10 -0
- data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-1.html +3 -0
- data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-1.js +11 -0
- data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-2.html +14 -0
- data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-2.js +57 -0
- data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-3.html +15 -0
- data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-3.js +35 -0
- data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-4.html +9 -0
- data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-4.js +12 -0
- data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-5.html +45 -0
- data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-5.js +22 -0
- data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-6.html +51 -0
- data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-6.js +21 -0
- data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-7.html +22 -0
- data/spec/support/cases/microformat2-node.jit.su/h-event/h-event-7.js +20 -0
- data/spec/support/cases/microformat2-node.jit.su/h-geo/h-geo-0.html +5 -0
- data/spec/support/cases/microformat2-node.jit.su/h-geo/h-geo-0.js +10 -0
- data/spec/support/cases/microformat2-node.jit.su/h-geo/h-geo-1.html +7 -0
- data/spec/support/cases/microformat2-node.jit.su/h-geo/h-geo-1.js +12 -0
- data/spec/support/cases/microformat2-node.jit.su/h-geo/h-geo-2.html +10 -0
- data/spec/support/cases/microformat2-node.jit.su/h-geo/h-geo-2.js +13 -0
- data/spec/support/cases/microformat2-node.jit.su/h-geo/h-geo-3.html +12 -0
- data/spec/support/cases/microformat2-node.jit.su/h-geo/h-geo-3.js +12 -0
- data/spec/support/cases/microformat2-node.jit.su/h-geo/h-geo-4.html +12 -0
- data/spec/support/cases/microformat2-node.jit.su/h-geo/h-geo-4.js +12 -0
- data/spec/support/cases/microformat2-node.jit.su/h-geo/h-geo-5.html +6 -0
- data/spec/support/cases/microformat2-node.jit.su/h-geo/h-geo-5.js +12 -0
- data/spec/support/cases/microformat2-node.jit.su/h-news/h-news-0.html +26 -0
- data/spec/support/cases/microformat2-node.jit.su/h-news/h-news-0.js +37 -0
- data/spec/support/cases/microformat2-node.jit.su/h-news/h-news-1.html +37 -0
- data/spec/support/cases/microformat2-node.jit.su/h-news/h-news-1.js +48 -0
- data/spec/support/cases/microformat2-node.jit.su/h-org/h-org-0.html +3 -0
- data/spec/support/cases/microformat2-node.jit.su/h-org/h-org-0.js +10 -0
- data/spec/support/cases/microformat2-node.jit.su/h-org/h-org-1.html +3 -0
- data/spec/support/cases/microformat2-node.jit.su/h-org/h-org-1.js +11 -0
- data/spec/support/cases/microformat2-node.jit.su/h-org/h-org-2.html +6 -0
- data/spec/support/cases/microformat2-node.jit.su/h-org/h-org-2.js +12 -0
- data/spec/support/cases/microformat2-node.jit.su/h-product/h-product-0.html +3 -0
- data/spec/support/cases/microformat2-node.jit.su/h-product/h-product-0.js +10 -0
- data/spec/support/cases/microformat2-node.jit.su/h-product/h-product-1.html +3 -0
- data/spec/support/cases/microformat2-node.jit.su/h-product/h-product-1.js +11 -0
- data/spec/support/cases/microformat2-node.jit.su/h-product/h-product-2.html +11 -0
- data/spec/support/cases/microformat2-node.jit.su/h-product/h-product-2.js +23 -0
- data/spec/support/cases/microformat2-node.jit.su/h-product/h-product-3.html +22 -0
- data/spec/support/cases/microformat2-node.jit.su/h-product/h-product-3.js +42 -0
- data/spec/support/cases/microformat2-node.jit.su/h-recipe/h-recipe-0.html +9 -0
- data/spec/support/cases/microformat2-node.jit.su/h-recipe/h-recipe-0.js +11 -0
- data/spec/support/cases/microformat2-node.jit.su/h-recipe/h-recipe-1.html +67 -0
- data/spec/support/cases/microformat2-node.jit.su/h-recipe/h-recipe-1.js +51 -0
- data/spec/support/cases/microformat2-node.jit.su/h-resume/h-resume-0.html +3 -0
- data/spec/support/cases/microformat2-node.jit.su/h-resume/h-resume-0.js +10 -0
- data/spec/support/cases/microformat2-node.jit.su/h-resume/h-resume-1.html +20 -0
- data/spec/support/cases/microformat2-node.jit.su/h-resume/h-resume-1.js +39 -0
- data/spec/support/cases/microformat2-node.jit.su/h-resume/h-resume-2.html +17 -0
- data/spec/support/cases/microformat2-node.jit.su/h-resume/h-resume-2.js +54 -0
- data/spec/support/cases/microformat2-node.jit.su/h-resume/h-resume-3.html +15 -0
- data/spec/support/cases/microformat2-node.jit.su/h-resume/h-resume-3.js +54 -0
- data/spec/support/cases/microformat2-node.jit.su/h-resume/h-resume-4.html +15 -0
- data/spec/support/cases/microformat2-node.jit.su/h-resume/h-resume-4.js +12 -0
- data/spec/support/cases/microformat2-node.jit.su/h-resume/h-resume-5.html +13 -0
- data/spec/support/cases/microformat2-node.jit.su/h-resume/h-resume-5.js +27 -0
- data/spec/support/cases/microformat2-node.jit.su/h-review-aggregate/h-review-aggregate-0.html +10 -0
- data/spec/support/cases/microformat2-node.jit.su/h-review-aggregate/h-review-aggregate-0.js +19 -0
- data/spec/support/cases/microformat2-node.jit.su/h-review-aggregate/h-review-aggregate-1.html +20 -0
- data/spec/support/cases/microformat2-node.jit.su/h-review-aggregate/h-review-aggregate-1.js +26 -0
- data/spec/support/cases/microformat2-node.jit.su/h-review-aggregate/h-review-aggregate-2.html +15 -0
- data/spec/support/cases/microformat2-node.jit.su/h-review-aggregate/h-review-aggregate-2.js +23 -0
- data/spec/support/cases/microformat2-node.jit.su/h-review/h-review-0.html +3 -0
- data/spec/support/cases/microformat2-node.jit.su/h-review/h-review-0.js +10 -0
- data/spec/support/cases/microformat2-node.jit.su/h-review/h-review-1.html +3 -0
- data/spec/support/cases/microformat2-node.jit.su/h-review/h-review-1.js +11 -0
- data/spec/support/cases/microformat2-node.jit.su/h-review/h-review-2.html +3 -0
- data/spec/support/cases/microformat2-node.jit.su/h-review/h-review-2.js +11 -0
- data/spec/support/cases/microformat2-node.jit.su/h-review/h-review-3.html +6 -0
- data/spec/support/cases/microformat2-node.jit.su/h-review/h-review-3.js +19 -0
- data/spec/support/cases/microformat2-node.jit.su/h-review/h-review-4.html +8 -0
- data/spec/support/cases/microformat2-node.jit.su/h-review/h-review-4.js +20 -0
- data/spec/support/cases/microformat2-node.jit.su/h-review/h-review-5.html +24 -0
- data/spec/support/cases/microformat2-node.jit.su/h-review/h-review-5.js +37 -0
- data/spec/support/cases/microformat2-node.jit.su/includes/includes-0.html +18 -0
- data/spec/support/cases/microformat2-node.jit.su/includes/includes-0.js +43 -0
- data/spec/support/cases/microformat2-node.jit.su/includes/includes-1.html +26 -0
- data/spec/support/cases/microformat2-node.jit.su/includes/includes-1.js +54 -0
- data/spec/support/cases/microformat2-node.jit.su/includes/includes-2.html +13 -0
- data/spec/support/cases/microformat2-node.jit.su/includes/includes-2.js +20 -0
- data/spec/support/cases/microformat2-node.jit.su/includes/includes-3.html +20 -0
- data/spec/support/cases/microformat2-node.jit.su/includes/includes-3.js +40 -0
- data/spec/support/cases/microformat2-node.jit.su/includes/includes-4.html +23 -0
- data/spec/support/cases/microformat2-node.jit.su/includes/includes-4.js +42 -0
- data/spec/support/cases/microformat2-node.jit.su/rel/rel-0.html +3 -0
- data/spec/support/cases/microformat2-node.jit.su/rel/rel-0.js +10 -0
- data/spec/support/cases/microformat2-node.jit.su/rel/rel-1.html +3 -0
- data/spec/support/cases/microformat2-node.jit.su/rel/rel-1.js +10 -0
- data/spec/support/cases/microformat2-node.jit.su/rel/rel-2.html +12 -0
- data/spec/support/cases/microformat2-node.jit.su/rel/rel-2.js +19 -0
- data/spec/support/cases/microformat2-node.jit.su/rel/rel-3.html +21 -0
- data/spec/support/cases/microformat2-node.jit.su/rel/rel-3.js +26 -0
- data/spec/support/cases/microformat2-node.jit.su/rel/rel-4.html +15 -0
- data/spec/support/cases/microformat2-node.jit.su/rel/rel-4.js +42 -0
- data/spec/support/cases/microformats.org/microformats-2/microformats-2-0.html +2 -0
- data/spec/support/cases/microformats.org/microformats-2/microformats-2-0.js +9 -0
- data/spec/support/cases/microformats.org/microformats-2/microformats-2-1.html +2 -0
- data/spec/support/cases/microformats.org/microformats-2/microformats-2-1.js +10 -0
- data/spec/support/cases/microformats.org/microformats-2/microformats-2-2.html +5 -0
- data/spec/support/cases/microformats.org/microformats-2/microformats-2-2.js +11 -0
- data/spec/support/cases/microformats.org/microformats-2/microformats-2-3.html +17 -0
- data/spec/support/cases/microformats.org/microformats-2/microformats-2-3.js +20 -0
- data/spec/support/cases/microformats.org/microformats-2/microformats-2-4.html +16 -0
- data/spec/support/cases/microformats.org/microformats-2/microformats-2-4.js +24 -0
- data/spec/support/cases/microformats.org/microformats-2/microformats-2-5.html +7 -0
- data/spec/support/cases/microformats.org/microformats-2/microformats-2-5.js +11 -0
- data/spec/support/cases/microformats.org/microformats-2/microformats-2-6.html +9 -0
- data/spec/support/cases/microformats.org/microformats-2/microformats-2-6.js +18 -0
- data/spec/support/cases/microformats.org/microformats-2/microformats-2-7.html +9 -0
- data/spec/support/cases/microformats.org/microformats-2/microformats-2-7.js +18 -0
- data/spec/support/cases/microformats.org/microformats-2/microformats-2-8.html +9 -0
- data/spec/support/cases/microformats.org/microformats-2/microformats-2-8.js +17 -0
- data/spec/support/cases/microformats.org/microformats-2/microformats-2-9.html +9 -0
- data/spec/support/cases/microformats.org/microformats-2/microformats-2-9.js +17 -0
- data/spec/support/lib/microformats2/implied_property/name-fail.html +60 -0
- data/spec/support/lib/microformats2/implied_property/name-pass.html +30 -0
- data/spec/support/lib/microformats2/implied_property/photo-fail.html +60 -0
- data/spec/support/lib/microformats2/implied_property/photo-pass.html +30 -0
- data/spec/support/lib/microformats2/implied_property/url-fail.html +18 -0
- data/spec/support/lib/microformats2/implied_property/url-pass.html +12 -0
- data/spec/support/lib/microformats2/nested-format-with-property.html +12 -0
- data/spec/support/lib/microformats2/nested-format-with-property.js +15 -0
- data/spec/support/lib/microformats2/nested-format-without-property.html +13 -0
- data/spec/support/lib/microformats2/nested-property.html +12 -0
- data/spec/support/lib/microformats2/nested-property.js +9 -0
- data/spec/support/lib/microformats2/simple.html +19 -0
- data/spec/support/lib/microformats2/simple.js +10 -0
- metadata +535 -85
- data/.autotest +0 -23
- data/.gemtest +0 -0
- data/History.txt +0 -19
- data/Manifest.txt +0 -10
- data/bin/microformats2 +0 -3
- data/test/IndieWebCamp.html +0 -351
- data/test/simple.html +0 -30
- data/test/test_microformats2.rb +0 -185
@@ -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,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
|