fix bundle_fu to handle relative roots

applied pending patches from bundle_fu issues 3 and 6
reverted previous workaround in standard.css for relative roots
This commit is contained in:
Reinier Balt 2009-02-07 20:09:09 +01:00
parent d41c369f09
commit 48fb00b24e
3 changed files with 38 additions and 31 deletions

View file

@ -9,10 +9,11 @@ class BundleFu
def bundle_files(filenames=[])
output = ""
filenames.each{ |filename|
output << "/* --------- #{filename} --------- */ "
filename_no_root = filename.sub(/^#{ActionController::Base.relative_url_root}/, '')
output << "/* --------- #{filename} - #{filename_no_root} --- ------ */ "
output << "\n"
begin
content = (File.read(File.join(RAILS_ROOT, "public", filename)))
content = (File.read(File.join(RAILS_ROOT, "public", filename_no_root)))
rescue
output << "/* FILE READ ERROR! */"
next

View file

@ -1,12 +1,16 @@
class BundleFu::CSSUrlRewriter
class << self
# rewrites a relative path to an absolute path, removing excess "../" and "./"
# rewrite_relative_path("stylesheets/default/global.css", "../image.gif") => "/stylesheets/image.gif"
# rewrite_relative_path("stylesheets/default/global.css", "../image.gif") => "#{rails_relative_root}/stylesheets/image.gif"
def rewrite_relative_path(source_filename, relative_url)
relative_url = relative_url.to_s.strip.gsub(/["']/, "")
return relative_url if relative_url.first == "/" || relative_url.include?("://")
return relative_url if relative_url.include?("://")
if ( relative_url.first == "/" )
return relative_url unless ActionController::Base.relative_url_root
return "#{ActionController::Base.relative_url_root}#{relative_url}"
end
elements = File.join("/", File.dirname(source_filename)).gsub(/\/+/, '/').split("/")
elements += relative_url.gsub(/\/+/, '/').split("/")
@ -24,7 +28,9 @@ class BundleFu::CSSUrlRewriter
end
end
elements * "/"
path = elements * "/"
return path unless ActionController::Base.relative_url_root
"#{ActionController::Base.relative_url_root}#{path}"
end
# rewrite the URL reference paths
@ -39,4 +45,4 @@ class BundleFu::CSSUrlRewriter
end
end
end
end