Skip to content

Commit f304c01

Browse files
committed
Adding automatic datestamping to generated sprite background image urls. This allows cache expiration on every release
1 parent 63daa91 commit f304c01

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ Configuration of `sprite` is done via `config/sprite.yml`. It allows you to set
7979
- `default_format:` defines the default file image format of the generated files. (defaults to `png`)
8080
- `default_spacing:` defines the default pixel spacing between sprites (defaults to 0)
8181
- `class_separator:` used to generated the class name by separating the image name and sprite name (defaults to `-`)
82-
82+
- `add_datestamps`: whether or not to add datestamps to the generated background image urls. this will allow proper cache versioning (defaults to `true`)
83+
8384
* `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:
8485
- `name:` name of image (required)
8586
- `sources:` defines a list of source image filenames to build the target image from (required). They are parsed by <code>Dir.glob</code>

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.6
1+
0.1.7

lib/sprite/builder.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ def initialize(config = nil, images = nil)
3030
@images = images || []
3131
set_image_defaults
3232
expand_image_paths
33+
34+
# initialize datestamp
35+
@datestamp_query = "?#{Time.now.to_i}" if @config["add_datestamps"]
3336

3437
# initialize sprite files
3538
@sprite_files = {}
@@ -86,7 +89,7 @@ def write_image(image)
8689

8790
# write sprite image file to disk
8891
dest_image.write(path)
89-
@sprite_files["#{name}.#{format}"] = results
92+
@sprite_files["#{name}.#{format}#{@datestamp_query}"] = results
9093
end
9194

9295
def write_styles
@@ -111,6 +114,10 @@ def set_config_defaults
111114
@config['class_separator'] ||= '-'
112115
@config["sprites_class"] ||= 'sprites'
113116
@config["default_spacing"] ||= 0
117+
118+
unless @config.has_key?("add_datestamps")
119+
@config["add_datestamps"] = true
120+
end
114121
end
115122

116123
# if no image configs are detected, set some intelligent defaults

0 commit comments

Comments
 (0)