Skip to content

Instantly share code, notes, and snippets.

@guilleiguaran
Forked from nhocki/assets.rake
Created September 29, 2011 05:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save guilleiguaran/1250021 to your computer and use it in GitHub Desktop.
Save guilleiguaran/1250021 to your computer and use it in GitHub Desktop.
Compile assets and push them automatically when run rake assets:precompile
class AssetsCompiler < Sprockets::StaticCompiler
def precompile(paths)
ensure_clean_git
Rake::Task["assets:clean"].invoke
super
commit_compiled_assets
push
end
def ensure_clean_git
raise "Can't deploy without a clean git status." if git_dirty?
end
def commit_compiled_assets
run "git add -u && git add . && git commit -am 'Compiled assets'"
end
def push
run "git push"
end
private
def run(command)
puts "+ Running: #{command}"
puts "-- #{system command}"
end
def git_dirty?
`[[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]]`
dirty = $?.success?
end
end
Rails.application.config.assets.compiler = AssetsCompiler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment