Skip to content

Instantly share code, notes, and snippets.

@rondevera
Created August 3, 2011 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rondevera/1123477 to your computer and use it in GitHub Desktop.
Save rondevera/1123477 to your computer and use it in GitHub Desktop.
AssetHat workaround for a media query bug in the `cssmin` gem
# rails_app/lib/tasks/asset_hat_extensions.rake
# AssetHat: http://mintdigital.github.com/asset_hat/
namespace :asset_hat_extensions do
namespace :css do
task :fix_media_queries do
# The `cssmin` gem has a bug in which it shortens
# `@media screen and (max-width:800px)` to
# `@media screen and(max-width:800px)` -- the missing space breaks it.
# This task re-adds the space.
config = AssetHat.config['css']
bundles = config['bundles'].keys
bundles.each do |bundle|
bundle_filepath = AssetHat::CSS.min_filepath(
File.join(AssetHat.bundles_dir(:css), "#{bundle}.css"))
css = File.read(bundle_filepath)
css.gsub!(/ and\(/, ' and (') # Caution: This regex is naive.
File.open(bundle_filepath, 'w') { |file| file.write(css) }
end
end
end # namespace :css
end # namespace :asset_hat_extensions
%w[
asset_hat:minify
asset_hat:minify:css
asset_hat:css:minify
].each do |task_name|
Rake::Task[task_name].enhance do
Rake::Task['asset_hat_extensions:css:fix_media_queries'].invoke
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment