auto_sprite 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +41 -47
- data/auto_sprite.gemspec +2 -2
- data/lib/auto_sprite.rb +13 -5
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -1,16 +1,12 @@
|
|
1
1
|
|
2
|
-
=AutoSprite 1.0
|
3
|
-
|
2
|
+
=AutoSprite 1.1.0
|
4
3
|
|
5
4
|
An easy, automated CSS image sprite creator.
|
6
5
|
|
7
|
-
|
8
|
-
=Why do I care?
|
9
|
-
|
10
6
|
Suppose you have 10 images on your homepage. Rather than downloading 10 seperate images one at a time, 1 image is downloaded and we use CSS to show different parts of that image when we need to. This speeds up your page load time. It can be hard to manage this manually since you need to keep appending images to a sprite file and updating your css file with the correct offsets, etc. Auto Sprite lets you get back to more important things.
|
11
7
|
|
12
8
|
|
13
|
-
|
9
|
+
==Install
|
14
10
|
|
15
11
|
1. Install auto_sprite and RMagick.
|
16
12
|
|
@@ -18,73 +14,71 @@ Suppose you have 10 images on your homepage. Rather than downloading 10 seperat
|
|
18
14
|
|
19
15
|
2. Edit your environement.rb add config.gem "auto_sprite"
|
20
16
|
|
21
|
-
|
17
|
+
==Usage
|
22
18
|
1. Include the stylesheet in your layout:
|
23
19
|
|
24
|
-
|
20
|
+
<%= stylesheet_link_tag "auto_sprite" %>`
|
25
21
|
|
26
22
|
2. Create a directory called sprites in your images directory (e.g. RAILS_ROOT/public/images/sprites)
|
27
23
|
|
28
24
|
3. Put the images you want to link to in your public/images/sprites directory.
|
29
25
|
|
30
|
-
4.
|
26
|
+
4. Use your images like you normally would:
|
31
27
|
|
32
|
-
<%= image_tag 'sprites/logo.png' %>
|
33
28
|
<%= image_tag 'sprites/icon1.jpg' %>
|
34
29
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
30
|
+
A :title can also be passed so your icons have tooltips:
|
31
|
+
|
32
|
+
<%= image_tag "sprites/stuff.png", :title => "I like Ice Cream" %>
|
39
33
|
|
40
|
-
5. Reload after adding any new images to sprites/ and enjoy your now faster rendering website.
|
41
34
|
|
35
|
+
5. Reload after adding any new images to sprites/ and enjoy your now faster rendering website.
|
42
36
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
=Notes
|
37
|
+
==Notes
|
47
38
|
- Animated images are not supported.
|
48
39
|
- Any image format supported by RMagick should work.
|
49
40
|
- Images of mixed sizes are not a problem.
|
41
|
+
- Should auto_sprite be removed, your application still works!
|
50
42
|
|
43
|
+
==Details
|
51
44
|
|
52
|
-
|
45
|
+
When rails starts, it checks whether or not the CSS or Sprite file is stale or missing.
|
53
46
|
|
54
|
-
|
47
|
+
If so, it will create:
|
55
48
|
|
56
|
-
|
57
|
-
|
49
|
+
RAILS_ROOT/public/stylesheets/auto_sprite.css
|
50
|
+
RAILS_ROOT/public/images/auto_sprite.png
|
58
51
|
|
59
52
|
|
60
53
|
The image tag will automatically generate a div tag for any images located in the sprite directory.
|
61
54
|
|
62
|
-
|
55
|
+
<span class="_as_logo_png"></span> instead of <img src="/images/sprites/logo.png" />
|
63
56
|
|
64
57
|
|
65
58
|
Here is an exmplmple of the stylehseet that would be generated if you had two files face3.png and face4.png
|
66
59
|
|
67
|
-
._as_face3_png {
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
}
|
72
|
-
|
73
|
-
._as_face4_png{
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
}
|
78
|
-
|
79
|
-
._as_face3_png,
|
80
|
-
._as_face3_png {
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
}
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
60
|
+
._as_face3_png {
|
61
|
+
background-position:0 0px;
|
62
|
+
height:16px;
|
63
|
+
width:16px;
|
64
|
+
}
|
65
|
+
|
66
|
+
._as_face4_png{
|
67
|
+
background-position:0 -16px;
|
68
|
+
height:16px;
|
69
|
+
width:16px;
|
70
|
+
}
|
71
|
+
|
72
|
+
._as_face3_png,
|
73
|
+
._as_face3_png {
|
74
|
+
display:inline-block;
|
75
|
+
background-image:url('/images/auto_sprite.png');
|
76
|
+
background-repeat:no-repeat;
|
77
|
+
}
|
78
|
+
|
79
|
+
==Contact
|
80
|
+
|
81
|
+
*Author*:: Stephen Blackstone (mailto:sblackstone@gmail.com)
|
82
|
+
*Website*:: http://github.com/sblackstone/auto_sprite
|
83
|
+
|
90
84
|
Copyright (c) 2010 Stephen Blackstone, released under the MIT license
|
data/auto_sprite.gemspec
CHANGED
@@ -2,10 +2,10 @@ spec = Gem::Specification.new do |s|
|
|
2
2
|
|
3
3
|
require 'fileutils'
|
4
4
|
s.name = "auto_sprite"
|
5
|
-
s.version = "1.0
|
5
|
+
s.version = "1.1.0"
|
6
6
|
s.author = "Stephen Blackstone"
|
7
7
|
s.email = "sblackstone@gmail.com"
|
8
|
-
s.homepage = "http://
|
8
|
+
s.homepage = "http://github.com/sblackstone/auto_sprite"
|
9
9
|
s.platform = Gem::Platform::RUBY
|
10
10
|
s.summary = "A fully-Automagic Sprite Builder"
|
11
11
|
s.description = "CSS Sprites can get you down, don't let them. This gem automatically creates the CSS, Sprite and HTML tags so you don't have to"
|
data/lib/auto_sprite.rb
CHANGED
@@ -9,11 +9,11 @@ module AutoSprite
|
|
9
9
|
|
10
10
|
class << self
|
11
11
|
def sprite_file_paths
|
12
|
-
sprite_file_names.map {|f| File.join(SPRITE_ASSETS_PATH, f) }
|
12
|
+
@sprite_file_paths ||= sprite_file_names.map {|f| File.join(SPRITE_ASSETS_PATH, f) }
|
13
13
|
end
|
14
14
|
|
15
15
|
def sprite_file_names
|
16
|
-
Dir.entries(SPRITE_ASSETS_PATH).reject { |f|
|
16
|
+
@sprite_file_names ||= Dir.entries(SPRITE_ASSETS_PATH).reject { |f|
|
17
17
|
!File.file?(File.join(SPRITE_ASSETS_PATH,f))
|
18
18
|
}
|
19
19
|
end
|
@@ -24,11 +24,19 @@ module AutoSprite
|
|
24
24
|
"_as_#{filename}"
|
25
25
|
end
|
26
26
|
|
27
|
+
def stale?
|
28
|
+
to_check = [sprite_file_paths , SPRITE_ASSETS_PATH].flatten
|
29
|
+
!FileUtils.uptodate?(SPRITE_IMG_PATH , to_check) ||
|
30
|
+
!FileUtils.uptodate?(CSS_FILE_PATH , to_check)
|
31
|
+
end
|
32
|
+
|
27
33
|
def setup!
|
28
34
|
FileUtils::mkdir_p(SPRITE_ASSETS_PATH)
|
29
|
-
|
30
|
-
|
31
|
-
|
35
|
+
if stale?
|
36
|
+
FileUtils::rm_f(CSS_FILE_PATH)
|
37
|
+
FileUtils::rm_f(SPRITE_IMG_PATH)
|
38
|
+
write_new_assets
|
39
|
+
end
|
32
40
|
end
|
33
41
|
|
34
42
|
def write_new_assets
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auto_sprite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Blackstone
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-02-19 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -28,7 +28,7 @@ files:
|
|
28
28
|
- ./rails/init.rb
|
29
29
|
- ./lib/auto_sprite.rb
|
30
30
|
has_rdoc: true
|
31
|
-
homepage: http://
|
31
|
+
homepage: http://github.com/sblackstone/auto_sprite
|
32
32
|
licenses: []
|
33
33
|
|
34
34
|
post_install_message:
|