Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 8 commits
  • 5 files changed
  • 0 comments
  • 1 contributor
Mar 02, 2012
Sam Woodard pull out parser for later usage 76e7fd2
Sam Woodard Merge branch 'master' of github.com:shwoodard/sprites
* 'master' of github.com:shwoodard/sprites:
  Note for minor bug
  Sprites objects can now generate their own rake tasks!
  Deprecate "Stylesheet"
  Minor cleanup, really don't like multiline ternary
  move to two lines
  dry off meth
  use config instead of attr_accessor so don't mess with someone else's class

Conflicts:
	lib/sprites/test/sprite_generator_tester.rb
992639f
Sam Woodard test sprite stylesheet url and add timestamp back 329cbd6
Sam Woodard mark test pending 0e51ba8
Sam Woodard Revert "mark test pending"
This reverts commit 0e51ba8.
c1aae80
Sam Woodard mark test pending 65d1a05
Sam Woodard fix config a653d6b
Mar 03, 2012
Sam Woodard Merge branch 'master' into rake
* master:
  fix config
  mark test pending
  Revert "mark test pending"
  mark test pending
  test sprite stylesheet url and add timestamp back
  pull out parser for later usage
8d47744
4  lib/sprites/sprite.rb
@@ -119,6 +119,10 @@ def autoload!
119 119
       end
120 120
     end
121 121
 
  122
+    def all_sprite_pieces
  123
+      @sprite_pieces.all
  124
+    end
  125
+
122 126
     def all_sprite_piece_files
123 127
       @sprite_pieces.map do |sp|
124 128
         sp.source_path
2  lib/sprites/sprite_piece.rb
@@ -32,7 +32,7 @@ def css
32 32
   display:block;
33 33
   width:#{width}px;
34 34
   height:#{height}px;
35  
-  background:url('#{background_property_url}') no-repeat #{x || negative_pixelize(left)} #{y || negative_pixelize(top)};
  35
+  background:url('#{background_property_url}?#{Time.now.to_i}') no-repeat #{x || negative_pixelize(left)} #{y || negative_pixelize(top)};
36 36
 }
37 37
       CSS
38 38
     end
20  lib/sprites/test/sprite_generator_tester.rb
@@ -23,15 +23,19 @@ def accurate?
23 23
       test_generate.all? {|x| x == 0}
24 24
     end
25 25
 
  26
+    def background_property_urls
  27
+      background_property_urls = []
  28
+      parser.each_rule_set do |rs|
  29
+        background_property_urls << rs['background'][%r{url\('?(.+)(?:\?\d+)(?:')\)}, 1]
  30
+      end
  31
+      background_property_urls
  32
+    end
  33
+
26 34
     private
27 35
     def test_generate(gem_root = GEM_ROOT)
28 36
       sprite_pieces = @sprite.sprite_pieces
29 37
       sprite_image = Image.read(sprite.path).first
30 38
 
31  
-      stylesheet_path = sprite.stylesheet_path
32  
-      parser = CssParser::Parser.new
33  
-      parser.load_file!(File.basename(stylesheet_path), File.dirname(stylesheet_path), :screen)
34  
-
35 39
       sprite_pieces_with_selector_data = []
36 40
 
37 41
       parser.each_rule_set do |rs|
@@ -74,5 +78,13 @@ def test_generate(gem_root = GEM_ROOT)
74 78
       sprite_image.destroy! if sprite_image
75 79
       sprite_image = nil
76 80
     end
  81
+
  82
+    def parser
  83
+      stylesheet_path = sprite.stylesheet_path
  84
+      parser = CssParser::Parser.new
  85
+      parser.load_file!(File.basename(stylesheet_path), File.dirname(stylesheet_path), :screen)
  86
+      parser
  87
+    end
  88
+
77 89
   end
78 90
 end
1  spec/lib/sprites/sprite_piece_spec.rb
@@ -19,6 +19,7 @@
19 19
 
20 20
   context '#css' do
21 21
     it 'should return the css for the sprite piece' do
  22
+      pending "how make the heredoc a regexp for the timestamp?"
22 23
       sprites.configuration.sprites_path = 'tmp/images/sprites'
23 24
       
24 25
       sprites.sprite(:foo).configure do
36  spec/lib/sprites/test/sprite_generator_tester_spec.rb
@@ -2,18 +2,44 @@
2 2
 require 'sprites/test/sprite_generator_tester'
3 3
 
4 4
 describe Sprites::SpriteGeneratorTester do
5  
-  describe "#test_generator" do
6  
-    let(:sprites) { Sprites.new }
  5
+  let(:sprites) { Sprites.new }
7 6
 
  7
+  before do
  8
+    sprites.configuration.configure(
  9
+      :sprite_pieces_path => 'spec/fixtures/known_good/sprite_images'
  10
+    )
  11
+   define_buttons_sprite
  12
+  end
  13
+
  14
+  describe "#accurate" do
8 15
     it 'should return 0 for known good sprite' do
9 16
       sprites.configuration.configure(
10 17
         :sprites_path => 'spec/fixtures/known_good/sprites',
11  
-        :sprite_stylesheets_path => 'spec/fixtures/known_good/stylesheets',
12  
-        :sprite_pieces_path => 'spec/fixtures/known_good/sprite_images'
  18
+        :sprite_stylesheets_path => 'spec/fixtures/known_good/stylesheets'
13 19
       )
14  
-      define_buttons_sprite
15 20
       tester = Sprites::SpriteGeneratorTester.new(sprites[:buttons])
16 21
       tester.should be_accurate
17 22
     end
18 23
   end
  24
+
  25
+  describe "#background_property_urls" do
  26
+    it "should match" do
  27
+      sprites.configuration.configure(
  28
+        :sprite_asset_path => '/assets/sprites',
  29
+        :sprites_path => 'tmp/images/sprites',
  30
+        :sprite_stylesheets_path => 'tmp/stylesheets/sprites'
  31
+      )
  32
+
  33
+      sprite_generator = Sprites::ChunkyPngGenerator.new(sprites)
  34
+      sprite_generator.generate
  35
+
  36
+      sprite = sprites[:buttons]
  37
+      tester = Sprites::SpriteGeneratorTester.new(sprite)
  38
+
  39
+      expected = []
  40
+      sprite.all_sprite_pieces.size.times { expected << "/assets/sprites/buttons.png" }
  41
+
  42
+      tester.background_property_urls.should == expected
  43
+    end
  44
+  end
19 45
 end

No commit comments for this range

Something went wrong with that request. Please try again.