Move the sprite importer to the compass module and rename it to be more clear about what it does.

This commit is contained in:
Chris Eppstein 2011-06-05 18:06:37 -07:00
parent dc8d8cd765
commit c73d281e58
9 changed files with 21 additions and 22 deletions

View File

@ -39,7 +39,7 @@ module Compass
def perform
relative_uri = options[:uri].gsub(/^#{Compass.configuration.images_dir}\//, '')
sprites = Compass::SpriteMap.new(relative_uri, Compass.sass_engine_options)
sprites = Compass::SpriteImporter.new(relative_uri, Compass.sass_engine_options)
options[:output_file] ||= File.join(Compass.configuration.sass_path, "sprites", "_#{sprites.name}.#{Compass.configuration.preferred_syntax}")
options[:skip_overrides] ||= false
contents = sprites.content_for_images(options[:skip_overrides])

View File

@ -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::SpriteMap.new
plugin_opts[:load_paths] << Compass::SpriteImporter.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::SpriteMap.new
load_paths << Compass::SpriteImporter.new
load_paths
end
end

View File

@ -1,5 +1,5 @@
require 'digest/md5'
require 'compass/sass_extensions/sprites/sprite_map'
require 'compass/sprite_importer'
require 'compass/sass_extensions/sprites/image'
require 'compass/sass_extensions/sprites/base'
require 'compass/sass_extensions/sprites/engines'

View File

@ -4,14 +4,14 @@ module Compass
class Base < Sass::Script::Literal
# Initialize a new aprite object from a relative file path
# Initialize a new sprite 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 => uri.value, :options => {})
sprites = sprite_map.files.map do |sprite|
importer = ::Compass::SpriteImporter.new(:uri => uri.value, :options => {})
sprites = importer.files.map do |sprite|
sprite.gsub(Compass.configuration.images_path+"/", "")
end
new(sprites, sprite_map, context, kwargs)
new(sprites, importer.path, importer.name, context, kwargs)
end
# Loads the sprite engine
@ -23,22 +23,21 @@ module Compass
# We should do so only when the packing algorithm changes
SPRITE_VERSION = "1"
attr_accessor :image_names, :path, :name, :map, :kwargs
attr_accessor :image_names, :path, :name, :kwargs
attr_accessor :images, :width, :height
def initialize(sprites, sprite_map, context, kwargs)
def initialize(sprites, path, name, context, kwargs)
require_engine!
@image_names = sprites
@path = sprite_map.path
@name = sprite_map.name
@path = path
@name = name
@kwargs = kwargs
@kwargs['cleanup'] ||= Sass::Script::Bool.new(true)
@images = nil
@width = nil
@height = nil
@evaluation_context = context
@map = sprite_map
validate!
compute_image_metadata!
end

View File

@ -1,12 +1,12 @@
module Compass
class SpriteMap < Sass::Importers::Base
class SpriteImporter < Sass::Importers::Base
attr_accessor :uri, :options
VAILD_FILE_NAME = /\A#{Sass::SCSS::RX::IDENT}\Z/
SPRITE_IMPORTER_REGEX = %r{((.+/)?([^\*.]+))/(.+?)\.png}
def self.load(uri, options)
Compass.quick_cache "Sprite_map:#{uri}#{options.inspect}", 5 do
klass = Compass::SpriteMap.new
klass = Compass::SpriteImporter.new
klass.uri, klass.options = uri, options
klass
end

View File

@ -11,7 +11,7 @@ describe Compass::SassExtensions::Sprites::Base do
Compass.configure_sass_plugin!
#fix this eww
options = Compass.sass_engine_options.extend Compass::SassExtensions::Functions::Sprites::VariableReader
@map = Compass::SpriteMap.new("selectors/*.png", options)
@map = Compass::SpriteImporter.new("selectors/*.png", options)
@base = Compass::SassExtensions::Sprites::Base.new(@map.sprite_names.map{|n| "selectors/#{n}.png"}, @map.path, 'selectors', @map.sass_engine, @map.options)
end

View File

@ -2,7 +2,7 @@ require 'spec_helper'
require 'fakefs/spec_helpers'
require 'timecop'
describe Compass::SpriteMap do
describe Compass::SpriteImporter do
include FakeFS::SpecHelpers
let(:sprite_map) { self.class.describes.new(uri, options) }

View File

@ -16,8 +16,8 @@ class SpritesBaseTest < Test::Unit::TestCase
end
def setup_map
@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)
@importer = Compass::SpriteImporter.new(:uri => "selectors/*.png", :options => @options)
@base = Compass::SassExtensions::Sprites::Base.new(@importer.sprite_names.map{|n| "selectors/#{n}.png"}, @importer.path, @importer.name, @importer.sass_engine, @importer.options)
end
def teardown
@ -29,7 +29,7 @@ class SpritesBaseTest < Test::Unit::TestCase
end
it "should have the sprite names" do
assert_equal @map.sprite_names, @base.sprite_names
assert_equal @importer.sprite_names, @base.sprite_names
end
it 'should have image filenames' do

View File

@ -19,8 +19,8 @@ class SpritesImageTest < Test::Unit::TestCase
let(:sprite_name) { File.basename(sprite_filename, '.png') }
def parent
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)
importer = Compass::SpriteImporter.new(:uri => "selectors/*.png", :options => options)
@parent ||= Compass::SassExtensions::Sprites::Base.new(importer.sprite_names.map{|n| "selectors/#{n}.png"}, importer.path, importer.name, importer.sass_engine, importer.options)
end
let(:options) do