fixed a bug that was causeing stack level too deep
This commit is contained in:
parent
c2015635dc
commit
27735a9537
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
@ -33,23 +38,21 @@ module Compass
|
||||
@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
|
||||
|
||||
private
|
||||
def ensure_path_and_name!
|
||||
return if @path && @name
|
||||
uri =~ %r{((.+/)?(.+))/(.+?)\.png}
|
||||
@path, @name = $1, $3
|
||||
@path, @name = Compass::Sprites.path_and_name(uri)
|
||||
end
|
||||
|
||||
def key(uri, options)
|
||||
Compass::Sprites.key(uri)
|
||||
end
|
||||
|
||||
def mtime(uri, options)
|
||||
Compass::Sprites.mtime(uri, options)
|
||||
end
|
||||
|
||||
# Generates the Sass for this sprite file
|
||||
|
@ -1,25 +1,51 @@
|
||||
module Compass
|
||||
class Sprites < Sass::Importers::Base
|
||||
attr_accessor :name, :path
|
||||
@@maps = {}
|
||||
class << self
|
||||
|
||||
def find_relative(*args)
|
||||
nil
|
||||
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
|
||||
|
@ -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'
|
||||
|
Loading…
Reference in New Issue
Block a user