Created
August 3, 2011 18:54
-
-
Save rondevera/1123477 to your computer and use it in GitHub Desktop.
AssetHat workaround for a media query bug in the `cssmin` gem
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
# 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