diff --git a/Gemfile.lock b/Gemfile.lock index 360e7d17..642873a1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - compass (0.11.beta.2.994cf53) + compass (0.11.beta.2.995a20c) chunky_png (~> 0.12.0) sass (>= 3.1.0.alpha.218) diff --git a/lib/compass/sass_extensions/functions/sprites.rb b/lib/compass/sass_extensions/functions/sprites.rb index 9730f5d9..3ff566d6 100644 --- a/lib/compass/sass_extensions/functions/sprites.rb +++ b/lib/compass/sass_extensions/functions/sprites.rb @@ -19,38 +19,32 @@ module Compass::SassExtensions::Functions::Sprites # collects image sizes and input parameters for each sprite def compute_image_metadata! @width = 0 - + init_images + compute_image_positions! + @height = @images.last.top + @images.last.height + end + + def init_images @images = image_names.collect do |relative_file| image = Compass::SassExtensions::Sprites::Image.new(relative_file, options) @width = [ @width, image.width + image.offset ].max image end - + end + + def compute_image_positions! @images.each_with_index do |image, index| - if index == 0 - image.top = 0 - else - last_image = @images[index-1] - image.top = last_image.top + last_image.height + [image.spacing, last_image.spacing].max - end - if image.position.unit_str == "%" - image.left = (@width - image.width) * (image.position.value / 100) - else - image.left = image.position.value - end + image.left = image.position.unit_str == "%" ? (@width - image.width) * (image.position.value / 100) : image.position.value + next if index == 0 + last_image = @images[index-1] + image.top = last_image.top + last_image.height + [image.spacing, last_image.spacing].max end - @height = @images.last.top + @images.last.height end def image_for(name) @images.detect { |img| img.name == name} end - # Calculate the size of the sprite - def size - [width, height] - end - def require_png_library! begin require 'oily_png' diff --git a/lib/compass/sass_extensions/sprites/base.rb b/lib/compass/sass_extensions/sprites/base.rb index 0fe768d7..f5f7080f 100644 --- a/lib/compass/sass_extensions/sprites/base.rb +++ b/lib/compass/sass_extensions/sprites/base.rb @@ -27,6 +27,11 @@ module Compass compute_image_metadata! end + # Calculate the size of the sprite + def size + [width, height] + end + def sprite_names image_names.map{|f| Compass::Sprites.sprite_name(f) } end diff --git a/lib/compass/sass_extensions/sprites/image.rb b/lib/compass/sass_extensions/sprites/image.rb index 2683d4aa..f90861e6 100644 --- a/lib/compass/sass_extensions/sprites/image.rb +++ b/lib/compass/sass_extensions/sprites/image.rb @@ -9,6 +9,7 @@ module Compass def initialize(relative_file, options) @relative_file, @options = relative_file, options + @left = @top = 0 end def file