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
|
PATH
|
||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
compass (0.11.beta.4.c3f0053)
|
compass (0.11.beta.4.c201563)
|
||||||
chunky_png (~> 1.1.0)
|
chunky_png (~> 1.1.0)
|
||||||
sass (>= 3.1.0.alpha.249)
|
sass (>= 3.1.0.alpha.249)
|
||||||
|
|
||||||
|
@ -159,14 +159,14 @@ module Compass
|
|||||||
# Checks whether this sprite is outdated
|
# Checks whether this sprite is outdated
|
||||||
def outdated?
|
def outdated?
|
||||||
if File.exists?(filename)
|
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
|
end
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
# Mtime of the sprite file
|
# Mtime of the sprite file
|
||||||
def mtime
|
def mtime
|
||||||
File.mtime(filename)
|
@mtime ||= File.mtime(filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
def inspect
|
def inspect
|
||||||
|
@ -2,6 +2,11 @@ module Compass
|
|||||||
class SpriteMap
|
class SpriteMap
|
||||||
attr_reader :uri, :options
|
attr_reader :uri, :options
|
||||||
|
|
||||||
|
|
||||||
|
def find_relative(*args)
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
def initialize(uri, options)
|
def initialize(uri, options)
|
||||||
@uri, @options = uri, options
|
@uri, @options = uri, options
|
||||||
end
|
end
|
||||||
@ -27,29 +32,27 @@ module Compass
|
|||||||
def sprite_names
|
def sprite_names
|
||||||
@sprite_names ||= files.collect { |file| File.basename(file, '.png') }
|
@sprite_names ||= files.collect { |file| File.basename(file, '.png') }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the sass options for this sprite
|
# Returns the sass options for this sprite
|
||||||
def sass_options
|
def sass_options
|
||||||
@sass_options ||= options.merge(:filename => name, :syntax => :scss, :importer => self)
|
@sass_options ||= options.merge(:filename => name, :syntax => :scss, :importer => self)
|
||||||
end
|
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
|
# Returns a Sass::Engine for this sprite object
|
||||||
def sass_engine
|
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
|
end
|
||||||
|
|
||||||
private
|
def mtime(uri, options)
|
||||||
def ensure_path_and_name!
|
Compass::Sprites.mtime(uri, options)
|
||||||
return if @path && @name
|
|
||||||
uri =~ %r{((.+/)?(.+))/(.+?)\.png}
|
|
||||||
@path, @name = $1, $3
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Generates the Sass for this sprite file
|
# Generates the Sass for this sprite file
|
||||||
|
@ -1,27 +1,53 @@
|
|||||||
module Compass
|
module Compass
|
||||||
class Sprites < Sass::Importers::Base
|
class Sprites < Sass::Importers::Base
|
||||||
|
attr_accessor :name, :path
|
||||||
def find_relative(*args)
|
@@maps = {}
|
||||||
nil
|
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
|
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
|
# Called by the sass engine to build a new SpriteMap
|
||||||
def find(uri, options)
|
def find(uri, options)
|
||||||
if uri =~ /\.png$/
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
# Called by the sass engine to identift the SpriteMap
|
# Called by the sass engine to identify the SpriteMap
|
||||||
def key(uri, options)
|
def self.key(uri, options={})
|
||||||
[self.class.name + ":" + File.dirname(File.expand_path(uri)),
|
[self.class.name + ":" + File.dirname(File.expand_path(uri)), File.basename(uri)]
|
||||||
File.basename(uri)]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def mtime(uri, options)
|
def self.mtime(uri, options)
|
||||||
SpriteMap.new(uri, options).mtime
|
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
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
""
|
""
|
||||||
end
|
end
|
||||||
|
@ -42,7 +42,10 @@ describe Compass::SpriteMap do
|
|||||||
|
|
||||||
its(:sass_options) { should == options.merge(:filename => name, :syntax => :scss, :importer => sprite_map) }
|
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
|
it "should have a test for the sass engine" do
|
||||||
pending 'sass'
|
pending 'sass'
|
||||||
|
Loading…
Reference in New Issue
Block a user