Permalink
Browse files

We now only update the files if they are stale. That is they are olde…

…r than the files in the sprites directory, the sprites directory itself (in case something is deleted) or one of the files are missing.
  • Loading branch information...
1 parent 0f35886 commit 0352897a214e73651c1c57a18e14d8d1a27134aa Stephen Blackstone committed Feb 19, 2010
Showing with 18 additions and 8 deletions.
  1. +4 −2 README.rdoc
  2. +1 −1 auto_sprite.gemspec
  3. +13 −5 lib/auto_sprite.rb
View
6 README.rdoc
@@ -1,5 +1,5 @@
-=AutoSprite 1.0.4
+=AutoSprite 1.1.0
An easy, automated CSS image sprite creator.
@@ -42,7 +42,9 @@ Suppose you have 10 images on your homepage. Rather than downloading 10 seperat
==Details
-Whenever rails reloads, it will automatically generate two files:
+When rails starts, it checks whether or not the CSS or Sprite file is stale or missing.
+
+If so, it will create:
RAILS_ROOT/public/stylesheets/auto_sprite.css
RAILS_ROOT/public/images/auto_sprite.png
View
2 auto_sprite.gemspec
@@ -2,7 +2,7 @@ spec = Gem::Specification.new do |s|
require 'fileutils'
s.name = "auto_sprite"
- s.version = "1.0.4"
+ s.version = "1.1.0"
s.author = "Stephen Blackstone"
s.email = "sblackstone@gmail.com"
s.homepage = "http://fargle.org/auto_sprite"
View
18 lib/auto_sprite.rb
@@ -9,11 +9,11 @@ module AutoSprite
class << self
def sprite_file_paths
- sprite_file_names.map {|f| File.join(SPRITE_ASSETS_PATH, f) }
+ @sprite_file_paths ||= sprite_file_names.map {|f| File.join(SPRITE_ASSETS_PATH, f) }
end
def sprite_file_names
- Dir.entries(SPRITE_ASSETS_PATH).reject { |f|
+ @sprite_file_names ||= Dir.entries(SPRITE_ASSETS_PATH).reject { |f|
!File.file?(File.join(SPRITE_ASSETS_PATH,f))
}
end
@@ -24,11 +24,19 @@ def generate_css_name(f)
"_as_#{filename}"
end
+ def stale?
+ to_check = [sprite_file_paths , SPRITE_ASSETS_PATH].flatten
+ !FileUtils.uptodate?(SPRITE_IMG_PATH , to_check) ||
+ !FileUtils.uptodate?(CSS_FILE_PATH , to_check)
+ end
+
def setup!
FileUtils::mkdir_p(SPRITE_ASSETS_PATH)
- FileUtils::rm_f(CSS_FILE_PATH)
- FileUtils::rm_f(SPRITE_IMG_PATH)
- write_new_assets
+ if stale?
+ FileUtils::rm_f(CSS_FILE_PATH)
+ FileUtils::rm_f(SPRITE_IMG_PATH)
+ write_new_assets
+ end
end
def write_new_assets

0 comments on commit 0352897

Please sign in to comment.