class Object
Public Instance Methods
fix_links(doc, old_path, new_path)
click to toggle source
fixes relative paths for the new tag files
# File lib/logtags.rb, line 190 def fix_links(doc, old_path, new_path) # figure out relative link mapping prefix = Pathname.new(old_path).relative_path_from(Pathname.new(new_path)) url_tags = { 'img' => 'src', 'script' => 'src', 'a' => 'href' } # grab all url links doc.search(url_tags.keys.join(',')).each do |node| url_param = url_tags[node.name] src = node[url_param] unless src.empty? path = Pathname.new(src) uri = URI.parse(src) # only fix relative links and non http calls if path.relative? && !%w( http https ).include?(uri.scheme) node[url_param] = (prefix+path).to_s end end end end