Sha256: c252cb456d90a5a622153e5f751f54a6749c8705e739a0bc9adde3c1e883a917
Contents?: true
Size: 1.72 KB
Versions: 14
Compression:
Stored size: 1.72 KB
Contents
require File.dirname(__FILE__) + '../../../resolver' module Roger::Release::Processors class UrlRelativizer < Base def initialize(options={}) @options = { :url_attributes => %w{src href action}, :match => ["**/*.html"], :skip => [] } @options.update(options) if options end def call(release, options={}) options = {}.update(@options).update(options) release.log(self, "Relativizing all URLS in #{options[:match].inspect} files in attributes #{options[:url_attributes].inspect}, skipping #{options[:skip].any? ? options[:skip].inspect : "none" }") @resolver = Roger::Resolver.new(release.build_path) release.get_files(options[:match], options[:skip]).each do |file_path| release.debug(self, "Relativizing URLS in #{file_path}") do orig_source = File.read(file_path) File.open(file_path,"w") do |f| doc = Hpricot(orig_source) options[:url_attributes].each do |attribute| (doc/"*[@#{attribute}]").each do |tag| converted_url = @resolver.url_to_relative_url(tag[attribute], file_path) release.debug(self, "Converting '#{tag[attribute]}' to '#{converted_url}'") case converted_url when String tag[attribute] = converted_url when nil release.log(self, "Could not resolve link #{tag[attribute]} in #{file_path}") end end end f.write(doc.to_original_html) end end end end end end Roger::Release::Processors.register(:url_relativizer, Roger::Release::Processors::UrlRelativizer)
Version data entries
14 entries across 14 versions & 1 rubygems