Permalink
Browse files

Adding automatic datestamping to generated sprite background image ur…

…ls. This allows cache expiration on every release
  • Loading branch information...
1 parent 63daa91 commit f304c01a59ae0fc3662294bc4c0c39dcdfee2280 @merbjedi merbjedi committed Dec 22, 2009
Showing with 11 additions and 3 deletions.
  1. +2 −1 README.md
  2. +1 −1 VERSION
  3. +8 −1 lib/sprite/builder.rb
View
@@ -79,7 +79,8 @@ Configuration of `sprite` is done via `config/sprite.yml`. It allows you to set
- `default_format:` defines the default file image format of the generated files. (defaults to `png`)
- `default_spacing:` defines the default pixel spacing between sprites (defaults to 0)
- `class_separator:` used to generated the class name by separating the image name and sprite name (defaults to `-`)
-
+ - `add_datestamps`: whether or not to add datestamps to the generated background image urls. this will allow proper cache versioning (defaults to `true`)
+
* `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:
- `name:` name of image (required)
- `sources:` defines a list of source image filenames to build the target image from (required). They are parsed by <code>Dir.glob</code>
View
@@ -1 +1 @@
-0.1.6
+0.1.7
View
@@ -30,6 +30,9 @@ def initialize(config = nil, images = nil)
@images = images || []
set_image_defaults
expand_image_paths
+
+ # initialize datestamp
+ @datestamp_query = "?#{Time.now.to_i}" if @config["add_datestamps"]
# initialize sprite files
@sprite_files = {}
@@ -86,7 +89,7 @@ def write_image(image)
# write sprite image file to disk
dest_image.write(path)
- @sprite_files["#{name}.#{format}"] = results
+ @sprite_files["#{name}.#{format}#{@datestamp_query}"] = results
end
def write_styles
@@ -111,6 +114,10 @@ def set_config_defaults
@config['class_separator'] ||= '-'
@config["sprites_class"] ||= 'sprites'
@config["default_spacing"] ||= 0
+
+ unless @config.has_key?("add_datestamps")
+ @config["add_datestamps"] = true
+ end
end
# if no image configs are detected, set some intelligent defaults

0 comments on commit f304c01

Please sign in to comment.