Last active
October 5, 2015 07:18
-
-
Save inkel/2770288 to your computer and use it in GitHub Desktop.
GitStaticAssets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.arrow | |
background: asset_path('/images/arrow_small_white.png') no-repeat 14px center |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-# Just the important bits | |
- Dir["public/js/vendor/jquery*.js"].each do |js| | |
%script{type: "text/javascript", src: asset(js.sub("public", ""))} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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