global sprite configs for spacing closes #406

This commit is contained in:
Scott Davis 2012-03-24 09:10:25 -04:00
parent 81d2a44ef4
commit b40fa29e44
3 changed files with 38 additions and 16 deletions

View File

@ -2,13 +2,13 @@ require 'erb'
require 'compass/sprite_importer/binding' require 'compass/sprite_importer/binding'
module Compass module Compass
class SpriteImporter < Sass::Importers::Base class SpriteImporter < Sass::Importers::Base
VAILD_FILE_NAME = /\A#{Sass::SCSS::RX::IDENT}\Z/ VAILD_FILE_NAME = /\A#{Sass::SCSS::RX::IDENT}\Z/
SPRITE_IMPORTER_REGEX = %r{((.+/)?([^\*.]+))/(.+?)\.png} SPRITE_IMPORTER_REGEX = %r{((.+/)?([^\*.]+))/(.+?)\.png}
VALID_EXTENSIONS = ['.png'] VALID_EXTENSIONS = ['.png']
TEMPLATE_FOLDER = File.join(File.expand_path('../', __FILE__), 'sprite_importer') TEMPLATE_FOLDER = File.join(File.expand_path('../', __FILE__), 'sprite_importer')
CONTENT_TEMPLATE_FILE = File.join(TEMPLATE_FOLDER, 'content.erb') CONTENT_TEMPLATE_FILE = File.join(TEMPLATE_FOLDER, 'content.erb')
CONTENT_TEMPLATE = ERB.new(File.read(CONTENT_TEMPLATE_FILE)) CONTENT_TEMPLATE = ERB.new(File.read(CONTENT_TEMPLATE_FILE))

View File

@ -2,18 +2,18 @@
// General Sprite Defaults // General Sprite Defaults
// You can override them before you import this file. // You can override them before you import this file.
$<%= name %>-sprite-base-class: ".<%= name %>-sprite" !default; $<%= name %>-sprite-base-class : ".<%= name %>-sprite" !default;
$<%= name %>-sprite-dimensions: false !default; $<%= name %>-sprite-dimensions : false !default;
$<%= name %>-position: 0% !default; $<%= name %>-position : 0% !default;
$<%= name %>-spacing: 0 !default; $<%= name %>-spacing : 0 !default;
$<%= name %>-repeat: no-repeat !default; $<%= name %>-repeat : no-repeat !default;
$<%= name %>-prefix: '' !default; $<%= name %>-prefix : '' !default;
$<%= name %>-clean-up: true !default; $<%= name %>-clean-up : true !default;
$<%= name %>-layout:vertical !default; $<%= name %>-layout : vertical !default;
$<%= name %>-inline: false !default; $<%= name %>-inline : false !default;
<% if skip_overrides %> <% if skip_overrides %>
$<%= name %>-sprites: sprite-map("<%= uri %>", $layout: $<%= name %>-layout, $cleanup: $<%= name %>-clean-up); $<%= name %>-sprites: sprite-map("<%= uri %>", $layout: $<%= name %>-layout, $cleanup: $<%= name %>-clean-up, $spacing: $<%= name %>-spacing, $position : $<%= name %>-position);
<% else %> <% else %>
// These variables control the generated sprite output // These variables control the generated sprite output
// You can override them selectively before you import this file. // You can override them selectively before you import this file.
@ -29,8 +29,10 @@ $<%= name %>-inline: false !default;
$<%= name %>-<%= sprite_name %>-spacing: $<%= name %>-<%= sprite_name %>-spacing, $<%= name %>-<%= sprite_name %>-spacing: $<%= name %>-<%= sprite_name %>-spacing,
$<%= name %>-<%= sprite_name %>-repeat: $<%= name %>-<%= sprite_name %>-repeat, $<%= name %>-<%= sprite_name %>-repeat: $<%= name %>-<%= sprite_name %>-repeat,
<% end %> <% end %>
$layout: $<%= name %>-layout, $layout : $<%= name %>-layout,
$cleanup: $<%= name %>-clean-up $cleanup : $<%= name %>-clean-up,
$spacing : $<%= name %>-spacing,
$position : $<%= name %>-position
); );
<% end %> <% end %>

View File

@ -863,4 +863,24 @@ class SpritesTest < Test::Unit::TestCase
end end
it "should respect global spacing" do
css = render <<-SCSS
$colors-spacing:5px;
@import "colors/*.png";
@include all-colors-sprites;
SCSS
other_css = <<-CSS
.colors-sprite, .colors-blue, .colors-yellow {
background: url('/colors-s747dec274e.png') no-repeat;
}
.colors-blue {
background-position:0 0;
}
.colors-yellow {
background-position:0 -15px;
}
CSS
assert_correct clean(css), clean(other_css)
end
end end