Simplify Microformats::Collection#absolutize
This commit is contained in:
parent
e630923e1d
commit
cdce96db13
1 changed files with 8 additions and 9 deletions
|
@ -4,7 +4,7 @@ module Microformats2
|
||||||
|
|
||||||
def initialize(element, url = nil)
|
def initialize(element, url = nil)
|
||||||
@element = element
|
@element = element
|
||||||
|
|
||||||
@base = nil
|
@base = nil
|
||||||
if url != nil
|
if url != nil
|
||||||
@base = url
|
@base = url
|
||||||
|
@ -12,7 +12,7 @@ module Microformats2
|
||||||
if @element.search("base").size > 0
|
if @element.search("base").size > 0
|
||||||
@base = @element.search("base")[0].attribute("href")
|
@base = @element.search("base")[0].attribute("href")
|
||||||
end
|
end
|
||||||
|
|
||||||
@format_names = []
|
@format_names = []
|
||||||
@rels = {}
|
@rels = {}
|
||||||
@alternates = []
|
@alternates = []
|
||||||
|
@ -46,7 +46,7 @@ module Microformats2
|
||||||
hash[:items] << format.to_hash
|
hash[:items] << format.to_hash
|
||||||
end
|
end
|
||||||
hash[:alternates] = @alternates unless @alternates.nil? || @alternates.empty?
|
hash[:alternates] = @alternates unless @alternates.nil? || @alternates.empty?
|
||||||
|
|
||||||
hash
|
hash
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -81,11 +81,11 @@ module Microformats2
|
||||||
send("#{mn.pluralize}=", [value])
|
send("#{mn.pluralize}=", [value])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_rels
|
def parse_rels
|
||||||
@element.search("*[@rel]").each do |rel|
|
@element.search("*[@rel]").each do |rel|
|
||||||
rel_values = rel.attribute("rel").text.split(" ")
|
rel_values = rel.attribute("rel").text.split(" ")
|
||||||
|
|
||||||
if rel_values.member?("alternate")
|
if rel_values.member?("alternate")
|
||||||
alternate_inst = {}
|
alternate_inst = {}
|
||||||
alternate_inst["url"] = absolutize(rel.attribute("href").text)
|
alternate_inst["url"] = absolutize(rel.attribute("href").text)
|
||||||
|
@ -108,16 +108,15 @@ module Microformats2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def absolutize(href)
|
def absolutize(href)
|
||||||
uri = URI.parse(href)
|
uri = URI.parse(href)
|
||||||
|
|
||||||
if uri.scheme || @base.nil?
|
if @base && !uri.absolute?
|
||||||
uri = uri.normalize
|
|
||||||
else
|
|
||||||
uri = URI.join(@base, href)
|
uri = URI.join(@base, href)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
uri.normalize!
|
||||||
uri.to_s
|
uri.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue