Merge branch 'master' of github.com:lyuba/compass into stable
This commit is contained in:
commit
937a15a41a
@ -23,7 +23,7 @@ module Compass
|
||||
plugin_opts[:cache_location] = cache_path unless cache_path.nil?
|
||||
plugin_opts.merge!(sass_options || {})
|
||||
plugin_opts[:load_paths] ||= []
|
||||
plugin_opts[:load_paths] << Compass::Sprites.new
|
||||
plugin_opts[:load_paths] << Compass::SpriteMap.new
|
||||
plugin_opts
|
||||
end
|
||||
|
||||
@ -63,7 +63,7 @@ module Compass
|
||||
next p if p.respond_to?(:find_relative)
|
||||
Sass::Importers::Filesystem.new(p.to_s)
|
||||
end
|
||||
load_paths << Compass::Sprites.new
|
||||
load_paths << Compass::SpriteMap.new
|
||||
load_paths
|
||||
end
|
||||
end
|
||||
|
@ -1,5 +1,4 @@
|
||||
require 'digest/md5'
|
||||
require 'compass/sass_extensions/sprites/sprites'
|
||||
require 'compass/sass_extensions/sprites/sprite_map'
|
||||
require 'compass/sass_extensions/sprites/image'
|
||||
require 'compass/sass_extensions/sprites/base'
|
||||
|
@ -7,7 +7,7 @@ module Compass
|
||||
# Initialize a new aprite object from a relative file path
|
||||
# the path is relative to the <tt>images_path</tt> confguration option
|
||||
def self.from_uri(uri, context, kwargs)
|
||||
sprite_map = ::Compass::SpriteMap.new(uri.value, {})
|
||||
sprite_map = ::Compass::SpriteMap.new(:uri => uri.value, :options => {})
|
||||
sprites = sprite_map.files.map do |sprite|
|
||||
sprite.gsub(Compass.configuration.images_path+"/", "")
|
||||
end
|
||||
|
@ -1,14 +1,63 @@
|
||||
module Compass
|
||||
class SpriteMap
|
||||
attr_reader :uri, :options
|
||||
class SpriteMap < Sass::Importers::Base
|
||||
attr_accessor :uri, :options
|
||||
VAILD_FILE_NAME = /\A#{Sass::SCSS::RX::IDENT}\Z/
|
||||
SPRITE_IMPORTER_REGEX = %r{((.+/)?([^\*.]+))/(.+?)\.png}
|
||||
|
||||
def find_relative(*args)
|
||||
nil
|
||||
def self.load(uri, options)
|
||||
Compass.quick_cache "Sprite_map:#{uri}#{options.inspect}", 5 do
|
||||
klass = Compass::SpriteMap.new
|
||||
klass.uri, klass.options = uri, options
|
||||
klass
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(uri, options)
|
||||
def initialize(options ={})
|
||||
@uri, @options = '', {}
|
||||
options.each do |key, value|
|
||||
send("#{key}=", value)
|
||||
end
|
||||
end
|
||||
|
||||
def find(uri, options)
|
||||
@uri, @options = uri, options
|
||||
if uri =~ SPRITE_IMPORTER_REGEX
|
||||
return sass_engine
|
||||
end
|
||||
end
|
||||
|
||||
def find_relative(uri, base, options)
|
||||
@uri, @options = uri, options
|
||||
find(File.join(base, uri), options)
|
||||
end
|
||||
|
||||
def to_s
|
||||
content_for_images
|
||||
end
|
||||
|
||||
def hash
|
||||
self.class.name.hash
|
||||
end
|
||||
|
||||
def eql?(other)
|
||||
other.class == self.class
|
||||
end
|
||||
|
||||
|
||||
|
||||
def key(uri, options={})
|
||||
@uri, @options = uri, options
|
||||
[self.class.name + ":" + File.dirname(File.expand_path(uri)), File.basename(uri)]
|
||||
end
|
||||
|
||||
def self.path_and_name(uri)
|
||||
Compass.quick_cache "Sprite_map_name:#{uri}", 5 do
|
||||
if uri =~ SPRITE_IMPORTER_REGEX
|
||||
[$1, $3]
|
||||
else
|
||||
[nil, nil]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Name of this spite
|
||||
@ -50,26 +99,7 @@ module Compass
|
||||
end
|
||||
|
||||
def ensure_path_and_name!
|
||||
@path ||= get_path
|
||||
@name ||= get_name
|
||||
end
|
||||
|
||||
def get_name
|
||||
_, name = Compass::Sprites.path_and_name(uri)
|
||||
name
|
||||
end
|
||||
|
||||
def get_path
|
||||
path, _ = Compass::Sprites.path_and_name(uri)
|
||||
path
|
||||
end
|
||||
|
||||
def key(uri, options)
|
||||
Compass::Sprites.key(uri)
|
||||
end
|
||||
|
||||
def mtime(uri, options)
|
||||
Compass::Sprites.mtime(uri, options)
|
||||
@path, @name = self.class.path_and_name(uri)
|
||||
end
|
||||
|
||||
# Generates the Sass for this sprite file
|
||||
|
@ -1,62 +0,0 @@
|
||||
module Compass
|
||||
class Sprites < Sass::Importers::Base
|
||||
attr_accessor :name, :path
|
||||
|
||||
def self.path_and_name(uri)
|
||||
if uri =~ %r{((.+/)?([^\*.]+))/(.+?)\.png}
|
||||
[$1, $3]
|
||||
end
|
||||
end
|
||||
|
||||
def self.discover_sprites(uri)
|
||||
self.load_map(uri, {}).files
|
||||
end
|
||||
|
||||
def self.sprite_name(file)
|
||||
File.basename(file, '.png')
|
||||
end
|
||||
|
||||
def self.load_map(uri, options)
|
||||
Compass.quick_cache("spritemap:#{uri}", 5) do
|
||||
SpriteMap.new(uri, options)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Called by the sass engine to build a new SpriteMap
|
||||
def find(uri, options)
|
||||
if uri =~ /\.png$/
|
||||
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 identify the SpriteMap
|
||||
def self.key(uri, options={})
|
||||
[self.class.name + ":" + File.dirname(File.expand_path(uri)), File.basename(uri)]
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def hash
|
||||
self.class.name.hash
|
||||
end
|
||||
|
||||
def eql?(other)
|
||||
other.class == self.class
|
||||
end
|
||||
|
||||
end
|
||||
end
|
@ -16,7 +16,7 @@ class SpritesBaseTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def setup_map
|
||||
@map = Compass::SpriteMap.new("selectors/*.png", @options)
|
||||
@map = Compass::SpriteMap.new(:uri => "selectors/*.png", :options => @options)
|
||||
@base = Compass::SassExtensions::Sprites::Base.new(@map.sprite_names.map{|n| "selectors/#{n}.png"}, @map, @map.sass_engine, @map.options)
|
||||
end
|
||||
|
||||
|
@ -19,7 +19,7 @@ class SpritesImageTest < Test::Unit::TestCase
|
||||
let(:sprite_name) { File.basename(sprite_filename, '.png') }
|
||||
|
||||
def parent
|
||||
map = Compass::SpriteMap.new("selectors/*.png", options)
|
||||
map = Compass::SpriteMap.new(:uri => "selectors/*.png", :options => options)
|
||||
@parent ||= Compass::SassExtensions::Sprites::Base.new(map.sprite_names.map{|n| "selectors/#{n}.png"}, map, map.sass_engine, map.options)
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user