Skip to content

Instantly share code, notes, and snippets.

@inkel
Last active October 5, 2015 07:18
Show Gist options
  • Save inkel/2770288 to your computer and use it in GitHub Desktop.
Save inkel/2770288 to your computer and use it in GitHub Desktop.
GitStaticAssets
.arrow
background: asset_path('/images/arrow_small_white.png') no-repeat 14px center
module GitStaticAssets
def asset(path)
if ENV["RACK_ENV"] == "production"
sha = `git rev-parse --short HEAD:public#{path}`.strip
"/asset-#{sha}#{path}"
else
path
end
end
end
module Sass::Script::Functions
include GitStaticAssets
def asset_path(path)
assert_type path, :String
Sass::Script::String.new("url(#{asset(path.value)})")
end
declare :asset_path, :args => [:string]
end
Cuba.plugin GitStaticAssets
-# Just the important bits
- Dir["public/js/vendor/jquery*.js"].each do |js|
%script{type: "text/javascript", src: asset(js.sub("public", ""))}
# For use with latest commit SHA1
location ^~ /asset {
expires max;
rewrite "^/asset-([a-z0-9]+)/(.*)" /$2 break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment