Skip to content

Instantly share code, notes, and snippets.

@madpilot
Created March 16, 2010 07:37
Show Gist options
  • Save madpilot/333732 to your computer and use it in GitHub Desktop.
Save madpilot/333732 to your computer and use it in GitHub Desktop.
if Rails.env == 'production' && File.exists?(File.join(Rails.root, 'REVISION'))
revision = File.read(File.join(Rails.root, 'REVISION')).strip
ActionController::Base.asset_host = "yourcdn.s3.amazon.com/#{revision}"
end
module Sass::Script::Functions
def url(string)
if Rails.env == 'production' && File.exists?(File.join(Rails.root, 'REVISION'))
revision = File.read(File.join(Rails.root, 'REVISION')).strip
path = string.value
pre = 'url('
post = ''
if (path[0..0] == "\"" || path[0..0] == "'")
pre += path[0..0]
path = path[1..-1]
end
if (path[-1..-1] == "\"" || path[-1..-1] == "'")
post += path[-1..-1]
path = path[0..-2]
end
pre += "http://yourcdn.s3.amazon.com"
if path[0..0] == '/'
pre += "/"
path = path[1..-1] unless pre == ''
end
post += ")"
Sass::Script::String.new(pre + (revision ? "#{revision}/" : "") + path + post)
else
Sass::Script::String.new("url(#{string.value})")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment