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'
module Compass
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}
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 = 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
// You can override them before you import this file.
$<%= name %>-sprite-base-class: ".<%= name %>-sprite" !default;
$<%= name %>-sprite-dimensions: false !default;
$<%= name %>-position: 0% !default;
$<%= name %>-spacing: 0 !default;
$<%= name %>-repeat: no-repeat !default;
$<%= name %>-prefix: '' !default;
$<%= name %>-clean-up: true !default;
$<%= name %>-layout:vertical !default;
$<%= name %>-inline: false !default;
$<%= name %>-sprite-base-class : ".<%= name %>-sprite" !default;
$<%= name %>-sprite-dimensions : false !default;
$<%= name %>-position : 0% !default;
$<%= name %>-spacing : 0 !default;
$<%= name %>-repeat : no-repeat !default;
$<%= name %>-prefix : '' !default;
$<%= name %>-clean-up : true !default;
$<%= name %>-layout : vertical !default;
$<%= name %>-inline : false !default;
<% 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 %>
// These variables control the generated sprite output
// 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 %>-repeat: $<%= name %>-<%= sprite_name %>-repeat,
<% end %>
$layout: $<%= name %>-layout,
$cleanup: $<%= name %>-clean-up
$layout : $<%= name %>-layout,
$cleanup : $<%= name %>-clean-up,
$spacing : $<%= name %>-spacing,
$position : $<%= name %>-position
);
<% end %>

View File

@ -863,4 +863,24 @@ class SpritesTest < Test::Unit::TestCase
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