From 00b41b5506233d8ab358fa32fdd14d59b94c5445 Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Sun, 5 Dec 2010 16:09:15 -0800 Subject: [PATCH] Only require (chunky|oily)_png if it is needed. --- lib/compass/sass_extensions/functions/sprites.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/compass/sass_extensions/functions/sprites.rb b/lib/compass/sass_extensions/functions/sprites.rb index d62c914a..563a0949 100644 --- a/lib/compass/sass_extensions/functions/sprites.rb +++ b/lib/compass/sass_extensions/functions/sprites.rb @@ -1,5 +1,3 @@ -require 'chunky_png' - module Compass::SassExtensions::Functions::Sprites ZERO = Sass::Script::Number::new(0) @@ -121,8 +119,17 @@ module Compass::SassExtensions::Functions::Sprites !File.exists?(filename) || outdated? end + def require_png_library! + begin + require 'oily_png' + rescue LoadError + require 'chunky_png' + end + end + # Returns a PNG object def construct_sprite + require_png_library! output_png = ChunkyPNG::Image.new(width, height, ChunkyPNG::Color::TRANSPARENT) images.each do |image| input_png = ChunkyPNG::Image.from_file(image[:file])