This commit is contained in:
John Bintz 2011-02-22 21:29:47 -05:00
parent da43418af0
commit 994cf534af

View File

@ -8,7 +8,7 @@ module Compass
attr_accessor :image_names, :path, :name, :options attr_accessor :image_names, :path, :name, :options
attr_accessor :images, :width, :height attr_accessor :images, :width, :height
def self.from_uri(uri, context, kwargs) def self.from_uri(uri, context, kwargs)
path, name = Compass::Sprites.path_and_name(uri.value) path, name = Compass::Sprites.path_and_name(uri.value)
sprites = Compass::Sprites.discover_sprites(uri.value).map do |sprite| sprites = Compass::Sprites.discover_sprites(uri.value).map do |sprite|
@ -26,7 +26,7 @@ module Compass
validate! validate!
compute_image_metadata! compute_image_metadata!
end end
def sprite_names def sprite_names
image_names.map{|f| Compass::Sprites.sprite_name(f) } image_names.map{|f| Compass::Sprites.sprite_name(f) }
end end
@ -38,7 +38,7 @@ module Compass
end end
end end
end end
# The on-the-disk filename of the sprite # The on-the-disk filename of the sprite
def filename def filename
File.join(Compass.configuration.images_path, "#{path}-#{uniqueness_hash}.png") File.join(Compass.configuration.images_path, "#{path}-#{uniqueness_hash}.png")
@ -48,7 +48,7 @@ module Compass
# collects image sizes and input parameters for each sprite # collects image sizes and input parameters for each sprite
def compute_image_metadata! def compute_image_metadata!
end end
# Generate a sprite image if necessary # Generate a sprite image if necessary
def generate def generate
if generation_required? if generation_required?
@ -61,7 +61,7 @@ module Compass
def generation_required? def generation_required?
!File.exists?(filename) || outdated? !File.exists?(filename) || outdated?
end end
def uniqueness_hash def uniqueness_hash
@uniqueness_hash ||= begin @uniqueness_hash ||= begin
sum = Digest::MD5.new sum = Digest::MD5.new
@ -69,14 +69,14 @@ module Compass
sum << path sum << path
images.each do |image| images.each do |image|
[:relative_file, :height, :width, :repeat, :spacing, :position, :digest].each do |attr| [:relative_file, :height, :width, :repeat, :spacing, :position, :digest].each do |attr|
sum << image[attr].to_s sum << image.send(attr).to_s
end end
end end
sum.hexdigest[0...10] sum.hexdigest[0...10]
end end
@uniqueness_hash @uniqueness_hash
end end
# saves the sprite for later retrieval # saves the sprite for later retrieval
def save!(output_png) def save!(output_png)
saved = output_png.save filename saved = output_png.save filename
@ -90,7 +90,7 @@ module Compass
File.join(Compass.configuration.images_path, image_name) File.join(Compass.configuration.images_path, image_name)
end end
end end
def inspect def inspect
to_s to_s
end end
@ -98,7 +98,7 @@ module Compass
def to_s(options = self.options) def to_s(options = self.options)
sprite_url(self).value sprite_url(self).value
end end
def respond_to?(meth) def respond_to?(meth)
super || @evaluation_context.respond_to?(meth) super || @evaluation_context.respond_to?(meth)
end end
@ -110,7 +110,7 @@ module Compass
super super
end end
end end
end end
end end
end end