Skip to content

Commit e3f3244

Browse files
committed
Updating default class separator to be dash instead of underscore
1 parent 04dac31 commit e3f3244

39 files changed

+48
-38
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ Configuration of `sprite` is done via `config/sprite.yml`. It allows you to set
9393
- `output_path:` defines the file path where your style settings get written (defaults to `public/stylesheets/sprites`). the file extension not needed as it will be set based on the `style:` setting
9494
- `image_output_path:` defines the folder path where the combined sprite images files are written (defaults to `public/images/sprites/`)
9595
- `source_path:` defines the folder where source image files are read from (defaults to `public/images/`)
96+
- `sprites_class:` defines the class name that gets added to all sprite stylesheet rules (defaults to `sprites`)
9697
- `default_format:` defines the default file image format of the generated files. (defaults to `png`)
97-
- `class_separator:` used within the generated class names between the image name and sprite name (defaults to `_`)
98+
- `class_separator:` used to generated the class name by separating the image name and sprite name (defaults to `-`)
9899

99100
* `images:` section provides an array of configurations which define which image files are built, and where they get their sprites from. each image setup provides the following config options:
100101
- `name:` name of image (required)
@@ -114,7 +115,8 @@ you can define any number of destination image files.
114115
output_path: public/sass/mixins/sprites.sass
115116
image_output_path: public/images/sprites/
116117
source_path: public/images/
117-
class_separator: '_'
118+
sprites_class: 'sprites'
119+
class_separator: '-'
118120
default_format: png
119121

120122
# defines what sprite collections get created

lib/sprite/builder.rb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def output_image(image)
7171
x = 0
7272
y = dest_image.rows + spaced_by
7373
end
74-
results << combiner.image_properties(source_image).merge(:x => x, :y => y)
74+
results << combiner.image_properties(source_image).merge(:x => x, :y => y, :group => name)
7575
dest_image = combiner.composite_images(dest_image, source_image, x, y)
7676
end
7777
@output[name] = results
@@ -89,11 +89,14 @@ def output_file
8989
path = output_path("css")
9090
FileUtils.mkdir_p(File.dirname(path))
9191

92+
# set up class_name to append to each rule
93+
sprites_class = config['sprites_class'] ? ".#{config['sprites_class']}" : ""
94+
9295
# write stylesheet file to disk
9396
File.open(path, 'w') do |f|
9497
@output.each do |dest, results|
9598
results.each do |result|
96-
f.puts ".#{result[:name]} {"
99+
f.puts "#{sprites_class}.#{result[:group]}#{config['class_separator']}#{result[:name]} {"
97100
f.puts " background: url(http://github.com/'/images/%3Cspan%20class=pl-s1%3E%3Cspan%20class=pl-kos%3E#{%3C/span%3E%3Cspan%20class=pl-s1%3Edest%3C/span%3E%3Cspan%20class=pl-kos%3E}%3C/span%3E%3C/span%3E') no-repeat #{result[:x]}px #{result[:y]}px;"
98101
f.puts " width: #{result[:width]}px;"
99102
f.puts " height: #{result[:height]}px;"
@@ -115,12 +118,13 @@ def image_path(name, format)
115118

116119
# sets all the default values on the config
117120
def set_config_defaults
118-
@config['style'] ||= 'css'
119-
@config['output_path'] ||= 'public/stylesheets/sprites'
120-
@config['image_output_path'] ||= 'public/images/sprites/'
121-
@config['source_path'] ||= 'public/images/'
122-
@config['default_format'] ||= 'png'
123-
@config['class_separator'] ||= '_'
121+
@config['style'] ||= 'css'
122+
@config['output_path'] ||= 'public/stylesheets/sprites'
123+
@config['image_output_path'] ||= 'public/images/sprites/'
124+
@config['source_path'] ||= 'public/images/'
125+
@config['default_format'] ||= 'png'
126+
@config['class_separator'] ||= '-'
127+
@config["sprites_class"] ||= 'sprites'
124128
end
125129

126130
# expands out sources, taking the Glob paths and turning them into separate entries in the array
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
config:
22
style: css
3-
output_path: output/stylesheets/android_icons
3+
output_path: output/stylesheets/android-icons
44
image_output_path: output/images/sprites/
55
source_path: resources/images/
6-
class_separator: '_'
6+
class_separator: '-'
77
default_format: png
88

99
# defines what sprite collections get created
1010
images:
11-
- name: android_icons
11+
- name: android-icons
1212
format: png
1313
align: vertical
1414
spaced_by: 50
1515
sources:
16-
- android_icons/*.png
16+
- android-icons/*.png

spec/resources/configs/config_test.yml renamed to spec/resources/configs/config-test.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ config:
33
output_path: output/stylesheets/sprites
44
image_output_path: output/images/sprites/
55
source_path: resources/images/
6-
class_separator: '_'
6+
class_separator: '-'
77
default_format: png
88

99
# defines what sprite collections get created
1010
images:
11-
- name: android_icons
11+
- name: android-icons
1212
format: png
1313
align: vertical
1414
spaced_by: 50
1515
sources:
16-
- android_icons/*.png
16+
- android-icons/*.png
1717

1818
- name: topics
1919
format: gif
2020
align: vertical
2121
spaced_by: 50
2222
sources:
23-
- topics/good_topic.gif
24-
- topics/mid_topic.gif
23+
- topics/good-topic.gif
24+
- topics/mid-topic.gif

spec/sprite/builder_spec.rb

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
context "configuration parsing" do
66
before(:all) do
7-
@sprite = Sprite::Builder.from_config("resources/configs/config_test.yml")
7+
@sprite = Sprite::Builder.from_config("resources/configs/config-test.yml")
88
end
99

1010
it "should load the settings keys from file" do
11-
@sprite.config.keys.size.should == 6
11+
@sprite.config.keys.size.should == 7
1212
end
1313

1414
it "should load the image keys from file" do
@@ -46,30 +46,34 @@
4646
@sprite.config['default_format'].should == "png"
4747
end
4848

49-
it "'class_separator:' setting should default to '_'" do
50-
@sprite.config['class_separator'].should == "_"
49+
it "'sprites_class:' setting should default to 'sprites'" do
50+
@sprite.config['sprites_class'].should == "sprites"
51+
end
52+
53+
it "'class_separator:' setting should default to '-'" do
54+
@sprite.config['class_separator'].should == "-"
5155
end
5256
end
5357

5458
context "generate android icon sprites" do
5559
before(:all) do
5660
clear_output
57-
@sprite = Sprite::Builder.from_config("resources/configs/android_icons.yml")
61+
@sprite = Sprite::Builder.from_config("resources/configs/android-icons.yml")
5862
@sprite.build
5963
end
6064

6165
it "should generate android.png" do
62-
File.exists?("#{Sprite.root}/output/images/sprites/android_icons.png").should be_true
66+
File.exists?("#{Sprite.root}/output/images/sprites/android-icons.png").should be_true
6367
end
6468

65-
it "should generate android_icons.css" do
66-
File.exists?("#{Sprite.root}/output/stylesheets/android_icons.css").should be_true
69+
it "should generate android-icons.css" do
70+
File.exists?("#{Sprite.root}/output/stylesheets/android-icons.css").should be_true
6771
end
6872

6973
context "sprite result image" do
7074
before(:all) do
7175
combiner = Sprite::ImageCombiner.new
72-
@result_image = combiner.get_image("#{Sprite.root}/output/images/sprites/android_icons.png")
76+
@result_image = combiner.get_image("#{Sprite.root}/output/images/sprites/android-icons.png")
7377
@result_properties = combiner.image_properties(@result_image)
7478
end
7579

@@ -81,7 +85,7 @@
8185

8286
context "sprite result styles" do
8387
before(:all) do
84-
@styles = File.read("#{Sprite.root}/output/stylesheets/android_icons.css")
88+
@styles = File.read("#{Sprite.root}/output/stylesheets/android-icons.css")
8589
end
8690

8791
it "should have some styles in it" do

spec/sprite/image_combiner_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,36 @@
66
@combiner = Sprite::ImageCombiner.new
77

88
@image_paths = {
9-
:good_topic => "#{Sprite.root}/resources/images/topics/good_topic.gif",
10-
:mid_topic => "#{Sprite.root}/resources/images/topics/mid_topic.gif"
9+
:good => "#{Sprite.root}/resources/images/topics/good-topic.gif",
10+
:mid => "#{Sprite.root}/resources/images/topics/mid-topic.gif"
1111
}
1212
end
1313

1414
context "image handling" do
1515
context "get_image" do
1616
it "should get a image" do
17-
@combiner.get_image(@image_paths[:good_topic]).class.should == Magick::Image
17+
@combiner.get_image(@image_paths[:good]).class.should == Magick::Image
1818
end
1919
end
2020

2121
context "image_properties" do
2222
it "should get image properties" do
23-
image = @combiner.get_image(@image_paths[:good_topic])
24-
@combiner.image_properties(image).should == {:name => 'good_topic', :width => 20, :height => 19}
23+
image = @combiner.get_image(@image_paths[:good])
24+
@combiner.image_properties(image).should == {:name => 'good-topic', :width => 20, :height => 19}
2525
end
2626
end
2727

2828
context "composite_images" do
2929
it "should composite two images into one horizontally" do
30-
image1 = @combiner.get_image(@image_paths[:good_topic])
31-
image2 = @combiner.get_image(@image_paths[:mid_topic])
30+
image1 = @combiner.get_image(@image_paths[:good])
31+
image2 = @combiner.get_image(@image_paths[:mid])
3232
image = @combiner.composite_images(image1, image2, image1.columns, 0)
3333
@combiner.image_properties(image).should == {:name => nil, :width => 40, :height => 19}
3434
end
3535

3636
it "should composite two images into one verically" do
37-
image1 = @combiner.get_image(@image_paths[:good_topic])
38-
image2 = @combiner.get_image(@image_paths[:mid_topic])
37+
image1 = @combiner.get_image(@image_paths[:good])
38+
image2 = @combiner.get_image(@image_paths[:mid])
3939
image = @combiner.composite_images(image1, image2, 0, image1.rows)
4040
@combiner.image_properties(image).should == {:name => nil, :width => 20, :height => 38}
4141
end

0 commit comments

Comments
 (0)