fixed a bug that was causeing stack level too deep

This commit is contained in:
Scott Davis 2011-03-26 13:31:48 -04:00
parent c2015635dc
commit 27735a9537
5 changed files with 63 additions and 31 deletions

View File

@ -7,7 +7,7 @@ GIT
PATH
remote: .
specs:
compass (0.11.beta.4.c3f0053)
compass (0.11.beta.4.c201563)
chunky_png (~> 1.1.0)
sass (>= 3.1.0.alpha.249)

View File

@ -159,14 +159,14 @@ module Compass
# Checks whether this sprite is outdated
def outdated?
if File.exists?(filename)
return @images.map(&:mtime).any? { |mtime| mtime > self.mtime }
return @images.map(&:mtime).any? { |imtime| imtime.to_i > self.mtime.to_i }
end
true
end
# Mtime of the sprite file
def mtime
File.mtime(filename)
@mtime ||= File.mtime(filename)
end
def inspect

View File

@ -2,6 +2,11 @@ module Compass
class SpriteMap
attr_reader :uri, :options
def find_relative(*args)
nil
end
def initialize(uri, options)
@uri, @options = uri, options
end
@ -27,29 +32,27 @@ module Compass
def sprite_names
@sprite_names ||= files.collect { |file| File.basename(file, '.png') }
end
# Returns the sass options for this sprite
def sass_options
@sass_options ||= options.merge(:filename => name, :syntax => :scss, :importer => self)
end
# Returns the mtime of all image files combined
def mtime
Compass.quick_cache("mtime:#{uri}") do
files.collect { |file| File.mtime(file) }.max
end
end
# Returns a Sass::Engine for this sprite object
def sass_engine
Sass::Engine.new(content_for_images, options)
Sass::Engine.new(content_for_images, sass_options)
end
def ensure_path_and_name!
@path, @name = Compass::Sprites.path_and_name(uri)
end
def key(uri, options)
Compass::Sprites.key(uri)
end
private
def ensure_path_and_name!
return if @path && @name
uri =~ %r{((.+/)?(.+))/(.+?)\.png}
@path, @name = $1, $3
def mtime(uri, options)
Compass::Sprites.mtime(uri, options)
end
# Generates the Sass for this sprite file

View File

@ -1,27 +1,53 @@
module Compass
class Sprites < Sass::Importers::Base
def find_relative(*args)
nil
attr_accessor :name, :path
@@maps = {}
class << self
def path_and_name(uri)
if uri =~ %r{((.+/)?(.+))/(.+?)\.png}
[$1, $3, $4]
end
end
def discover_sprites(uri)
self.load_map(uri, options).files
end
def sprite_name(file)
File.basename(file, '.png')
end
end
def self.load_map(uri, options)
key = self.key(uri, options)
@@maps[key] ||= SpriteMap.new(uri, options)
end
# Called by the sass engine to build a new SpriteMap
def find(uri, options)
if uri =~ /\.png$/
SpriteMap.new(uri, options).sass_engine
map = Compass::Sprites.load_map(uri, options)
self.path, self.name = map.path, map.name
return map.sass_engine
end
end
# Called by the sass engine to identift the SpriteMap
def key(uri, options)
[self.class.name + ":" + File.dirname(File.expand_path(uri)),
File.basename(uri)]
# Called by the sass engine to identify the SpriteMap
def self.key(uri, options={})
[self.class.name + ":" + File.dirname(File.expand_path(uri)), File.basename(uri)]
end
def mtime(uri, options)
SpriteMap.new(uri, options).mtime
def self.mtime(uri, options)
Compass.quick_cache("mtime:#{uri}") do
map = Compass::Sprites.load_map(uri, options)
map.files.inject(Time.at(0)) do |max_time, file|
(t = File.mtime(file)) > max_time ? t : max_time
end
end
end
def to_s
""
end

View File

@ -42,7 +42,10 @@ describe Compass::SpriteMap do
its(:sass_options) { should == options.merge(:filename => name, :syntax => :scss, :importer => sprite_map) }
its(:mtime) { should == mtime }
it "should have a correct mtime" do
puts sprite_map.mtime(uri, subject.sass_options)
end
it "should have a test for the sass engine" do
pending 'sass'