Added ability to accept microformats that are not at the beginning of a class string for attributes

This commit is contained in:
Shane Becker 2011-06-28 20:04:15 -07:00
parent ea8a526da3
commit 601a65d1db
3 changed files with 8 additions and 3 deletions

View file

@ -52,9 +52,9 @@ module Microformats2
def self.add_properties(mf, obj)
%w(p n e i).each do |letter|
mf.css("*[class|=#{letter}]").each do |property|
mf.css("*[class*=#{letter}-]").each do |property|
property.attribute("class").to_s.split.each do |css_class|
if css_class =~ /^[pnei]/
if css_class[0..1] == "#{letter}-"
css_class = css_class[2..-1].gsub("-","_")
method_name = css_class.gsub("-","_")
value = property.text.gsub(/\n+/, " ").gsub(/\s+/, " ").strip

View file

@ -6,7 +6,7 @@
<body>
<h1 class="h-card">
<a class="p-fn u-url" href="http://factoryjoe.com/">
<span class="p-given-name">Chris</span>
<span class="foxtrot echo niner p-given-name">Chris</span>
<abbr class="p-additional-name">R.</abbr>
<span class="p-family-name">Messina</span>
</a>

View file

@ -23,6 +23,11 @@ class TestMicroformats2 < Test::Unit::TestCase
assert_equal HCard, result[:hcard].first.class
assert_equal 2, result[:hcard].length
end
def test_extracts_name_from_tag_with_multiple_classes
result = Microformats2.parse(File.open(File.join(File.dirname(__FILE__), "simple.html")))
assert_equal "Chris", result[:hcard].first.given_name
end
def test_extracts_hcard_from_html
hcard = <<-END