Including:
- Autoprefixer
- Breakpoint (for media queries)
- Scut mixin library
- Sass Media Query Combiner (a must have if you're working with lots of inline media queries)
- Compresses generated sprites
Including:
| require 'autoprefixer-rails' | |
| require 'breakpoint' | |
| require 'scut' | |
| require 'sass-media_query_combiner' | |
| http_path = "/" | |
| sass_dir = "sass" | |
| css_dir = "public/css" | |
| http_stylesheets_path = "/css" | |
| images_dir = "public/images" | |
| http_images_path = "/images" | |
| http_generated_images_path = "/images" | |
| javascripts_dir = "public/js" | |
| http_javascripts_path = "/js" | |
| fonts_dir = "public/fonts" | |
| http_fonts_path = "/fonts" | |
| output_style = (environment == :production) ? :compressed : :expanded # for live: compass compile -e production --force | |
| color_output = false | |
| # -------------------- Autoprefix | |
| on_stylesheet_saved do |file| | |
| css = File.read(file) | |
| File.open(file, 'w') do |io| | |
| io << AutoprefixerRails.process(css) | |
| end | |
| end | |
| # -------------------- Compress sprites | |
| # callback - on_sprite_saved | |
| # http://compass-style.org/help/tutorials/configuration-reference/ | |
| on_sprite_saved do |filename| | |
| if File.exists?(filename) | |
| # if (environment == :production) | |
| # Post process sprite image | |
| postprocesspng(filename) | |
| # end | |
| end | |
| end | |
| # fn - Post processing for pngs | |
| # http://compass-style.org/help/tutorials/configuration-reference/ | |
| # http://pngquant.org/ | |
| # http://advsys.net/ken/utils.htm & http://nicj.net/2012/05/15/pngoutbatch | |
| # http://optipng.sourceforge.net/ | |
| def postprocesspng(filename) | |
| print "**********************\r\n" | |
| print "Compressing sprites...\r\n" | |
| print "**********************\r\n" | |
| if File.exists?(filename) | |
| sleep 1 | |
| optimize(filename, "pngquant --iebug --force --ext .png 256") | |
| optimize(filename, "pngout -c3 -b0 -v") | |
| optimize(filename, "optipng -o7 -verbose") | |
| end | |
| end | |
| # fn - Run optimize command line for a specified script | |
| # https://gist.github.com/2403117 | |
| def optimize(filename, script) | |
| if File.exists?(filename) | |
| sleep 1 | |
| print "\r\n** Running: " + script + " " + Shellwords.escape(filename) + "\r\n\r\n" | |
| system script + " " + Shellwords.escape(filename) | |
| end | |
| end |