def run(content, params={})
@item_rep = assigns[:item_rep] if @item_rep.nil?
case params[:type]
when :css
content.gsub(/url\((['"]?)(\/(?:[^\/].*?)?)\1\)/) do
'url(' + $1 + relative_path_to($2) + $1 + ')'
end
when :html, :xml, :xhtml
selectors = params.fetch(:select) { SELECTORS }
namespaces = params[:namespaces] || {}
require 'nokogiri'
case params[:type]
when :html
klass = ::Nokogiri::HTML
when :xml
klass = ::Nokogiri::XML
when :xhtml
klass = ::Nokogiri::XML
content = content.sub(%r{(<html[^>]+)xmlns="http://www.w3.org/1999/xhtml"}, '\1')
end
nokogiri_process(content, selectors, namespaces, klass, params[:type])
else
raise RuntimeError.new(
"The relativize_paths needs to know the type of content to " +
"process. Pass a :type to the filter call (:html for HTML, " +
":xhtml for XHTML, :xml for XML, or :css for CSS).")
end
end