mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-09 00:54:21 +01:00
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:
parent
d41c369f09
commit
48fb00b24e
3 changed files with 38 additions and 31 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue