Skip to content

Instantly share code, notes, and snippets.

@Burgestrand
Created October 6, 2010 10:02
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 Burgestrand/613114 to your computer and use it in GitHub Desktop.
Save Burgestrand/613114 to your computer and use it in GitHub Desktop.
Asset packaging rake task
# Rake task for compiling CoffeeScript and SASS (Compass).
#
# Author: Kim Burgestrand <http://burgestrand.se/>
# Date: 6th October 2010
# License: X11 License (MIT License)
# URL: http://gist.github.com/gists/613114
desc "Compiles CoffeeScript using Barrista (but only if they changed)"
task 'coffee:compile' => :environment do
require 'barista'
abort "'#{Barista::Compiler.bin_path}' is unavailable." unless Barista::Compiler.available?
Barista.compile_all! false, false
end
desc "Compiles SASS using Compass"
task 'sass:compile' do
sh 'bundle exec compass compile'
end
namespace :assets do
desc "Compiles all assets (CSS/JS)"
task :compile => ['coffee:compile', 'sass:compile']
desc "Bundles all assets with Jammit"
task :bundle do
require 'jammit'
Jammit.package!
end
desc "Removes all compiled and bundled assets"
task :clean => :environment do
files = []
files << ['assets']
files << ['javascripts', 'compiled']
files << ['stylesheets', 'compiled']
files = files.map { |path| Dir[Rails.root.join('public', *[path, '*.*'])] }.flatten
puts "Removing:"
files.each do |file|
puts " #{file.gsub(Rails.root.to_s + '/', '')}"
end
File.delete *files
end
end
desc "Compiles and bundles all assets"
task :assets => ['assets:compile', 'assets:bundle']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment