Merge commit 'psampaio/sprite_skip_overrides'

* commit 'psampaio/sprite_skip_overrides':
  adding --skip-overrides argument to the compass sprite command
This commit is contained in:
Chris Eppstein 2011-01-16 12:58:36 -08:00
commit d3a346e1ac
2 changed files with 28 additions and 19 deletions

View File

@ -8,6 +8,9 @@ module Compass
opts.on("-f SPRITE_FILE") do |output_file| opts.on("-f SPRITE_FILE") do |output_file|
self.options[:output_file] = output_file self.options[:output_file] = output_file
end end
opts.on("--skip-overrides", "Skip the generation of sprite overrides") do |skip_overrides|
self.options[:skip_overrides] = skip_overrides
end
opts.banner = %Q{ opts.banner = %Q{
Usage: compass sprite [options] "images/path/to/sprites/*.png" Usage: compass sprite [options] "images/path/to/sprites/*.png"
@ -41,7 +44,8 @@ module Compass
image_names = sprite_images.map{|i| File.basename(i, '.png')} image_names = sprite_images.map{|i| File.basename(i, '.png')}
sprites.path, sprites.name = Compass::Sprites.path_and_name(relative_uri) sprites.path, sprites.name = Compass::Sprites.path_and_name(relative_uri)
options[:output_file] ||= File.join(Compass.configuration.sass_path, "sprites", "_#{sprites.name}.#{Compass.configuration.preferred_syntax}") options[:output_file] ||= File.join(Compass.configuration.sass_path, "sprites", "_#{sprites.name}.#{Compass.configuration.preferred_syntax}")
contents = sprites.content_for_images(relative_uri, sprites.name, image_names) options[:skip_overrides] ||= false
contents = sprites.content_for_images(relative_uri, sprites.name, image_names, options[:skip_overrides])
if options[:output_file][-4..-1] != "scss" if options[:output_file][-4..-1] != "scss"
contents = Sass::Engine.new(contents, Compass.sass_engine_options.merge(:syntax => :scss)).to_tree.to_sass contents = Sass::Engine.new(contents, Compass.sass_engine_options.merge(:syntax => :scss)).to_tree.to_sass
end end

View File

@ -35,7 +35,7 @@ module Compass
end end
end end
def content_for_images(uri, name, images) def content_for_images(uri, name, images, skip_overrides = false)
<<-SCSS <<-SCSS
@import "compass/utilities/sprites/base"; @import "compass/utilities/sprites/base";
@ -47,22 +47,7 @@ $#{name}-position: 0% !default;
$#{name}-spacing: 0 !default; $#{name}-spacing: 0 !default;
$#{name}-repeat: no-repeat !default; $#{name}-repeat: no-repeat !default;
// These variables control the generated sprite output #{skip_overrides ? "$#{name}-sprites: sprite-map(\"#{uri}\");" : generate_overrides(uri, name, images) }
// You can override them selectively before you import this file.
#{images.map do |sprite_name|
<<-SCSS
$#{name}-#{sprite_name}-position: $#{name}-position !default;
$#{name}-#{sprite_name}-spacing: $#{name}-spacing !default;
$#{name}-#{sprite_name}-repeat: $#{name}-repeat !default;
SCSS
end.join}
$#{name}-sprites: sprite-map("#{uri}",
#{images.map do |sprite_name|
%Q{ $#{sprite_name}-position: $#{name}-#{sprite_name}-position,
$#{sprite_name}-spacing: $#{name}-#{sprite_name}-spacing,
$#{sprite_name}-repeat: $#{name}-#{sprite_name}-repeat}
end.join(",\n")});
// All sprites should extend this class // All sprites should extend this class
// The #{name}-sprite mixin will do so for you. // The #{name}-sprite mixin will do so for you.
@ -118,5 +103,25 @@ SCSS
"" ""
end end
def generate_overrides(uri, name,images)
content = <<-TXT
// These variables control the generated sprite output
// You can override them selectively before you import this file.
TXT
images.map do |sprite_name|
content += <<-SCSS
$#{name}-#{sprite_name}-position: $#{name}-position !default;
$#{name}-#{sprite_name}-spacing: $#{name}-spacing !default;
$#{name}-#{sprite_name}-repeat: $#{name}-repeat !default;
SCSS
end.join
content += "\n$#{name}-sprites: sprite-map(\"#{uri}\",\n"
content += images.map do |sprite_name|
%Q{ $#{sprite_name}-position: $#{name}-#{sprite_name}-position,
$#{sprite_name}-spacing: $#{name}-#{sprite_name}-spacing,
$#{sprite_name}-repeat: $#{name}-#{sprite_name}-repeat}
end.join(",\n")
content += ");"
end
end end
end end