Skip to content

Instantly share code, notes, and snippets.

@scottwb
Created January 28, 2011 06:08
Show Gist options
  • Save scottwb/799901 to your computer and use it in GitHub Desktop.
Save scottwb/799901 to your computer and use it in GitHub Desktop.
Rake task to rebuild all JS/CSS assets with Compass/Jammit, including workaround for the bugs within.
namespace :assets do
task :rebuild do
# Config the base names of all the jammit CSS packages you have defined
# in assets.yml. Could probably parse assets.yml to get this if
# we wanted to.
packages = ['common']
# This is because on OS X, you have to put an explicit empty string to the
# required extension argument with the -i parameter, but on Linux you
# do not.
in_place_option = "-i"
if `uname` =~ /darwin/i
in_place_option = '-i ""'
end
Dir.chdir(RAILS_ROOT) do
sh("compass compile --force")
# This is a workaround for this jammit bug:
# https://github.com/documentcloud/jammit/issues/#issue/120
#
sh("sed #{in_place_option} -e \"s/^@charset.*$//g\" public/stylesheets/*.css")
sh("jammit --force")
# This is a workaround for this YuiCompressor bug:
# http://yuilibrary.com/projects/yuicompressor/ticket/2528053
#
Dir.chdir("public/assets") do
packages.each do |package|
Dir.glob("#{package}*.css").each do |file|
sh("sed #{in_place_option} -e \"s/@media \\([^[:space:]]*\\) and(/@media \\1 and (/g\" #{file}")
sh("gzip --best --stdout #{file} > #{file}.gz")
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment