Created
January 28, 2011 06:08
-
-
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.
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
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