auto_sprite 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README +62 -5
- data/auto_sprite.gemspec +4 -3
- data/lib/auto_sprite.rb +23 -19
- metadata +4 -4
data/README
CHANGED
@@ -1,13 +1,70 @@
|
|
1
1
|
AutoSprite
|
2
2
|
==========
|
3
3
|
|
4
|
-
|
4
|
+
An easy, automated CSS image sprite creator.
|
5
5
|
|
6
|
+
Install
|
7
|
+
==========
|
8
|
+
|
9
|
+
1. Install auto_sprite and RMagick.
|
10
|
+
|
11
|
+
gem install RMagick
|
12
|
+
gem install auto_sprite
|
13
|
+
|
14
|
+
2. Edit your environement.rb add config.gem "auto_sprite"
|
15
|
+
|
16
|
+
Usage
|
17
|
+
==========
|
18
|
+
1. Include the stylesheet in your layout:
|
19
|
+
|
20
|
+
<%= stylesheet_link_tag "auto_sprite" %>
|
21
|
+
|
22
|
+
2. Create a directory called sprites in your images directory (e.g. RAILS_ROOT/public/images/sprites)
|
23
|
+
|
24
|
+
3. Put the images you want to link to in your public/images/sprites directory.
|
25
|
+
|
26
|
+
3. Use your images like you normally would:
|
27
|
+
|
28
|
+
<%= image_tag 'sprites/logo.png' %>
|
29
|
+
<%= image_tag 'sprites/icon1.jpg' %> ... etc
|
30
|
+
|
31
|
+
4. Enjoy your now faster website.
|
32
|
+
|
33
|
+
|
34
|
+
Details
|
35
|
+
==========
|
36
|
+
|
37
|
+
Whenever rails reloads, it will automatically generate two files:
|
38
|
+
|
39
|
+
RAILS_ROOT/public/stylesheets/auto_sprite.css
|
40
|
+
RAILS_ROOT/public/images/auto_sprite.png
|
41
|
+
|
42
|
+
|
43
|
+
The image tag will automatically generate a div tag for any images located in the sprite directory.
|
44
|
+
|
45
|
+
<div class="_as_logo_png"></div> instead of <img src="/images/sprites/logo.png" />
|
46
|
+
|
47
|
+
|
48
|
+
Here is an exmplmple of the stylehseet that would be generated if you had two files face3.png and face4.png
|
49
|
+
|
50
|
+
._as_face3_png {
|
51
|
+
background-position:0 0px;
|
52
|
+
height:16px;
|
53
|
+
width:16px;
|
54
|
+
}
|
6
55
|
|
7
|
-
|
8
|
-
|
56
|
+
._as_face4_png{
|
57
|
+
background-position:0 -16px;
|
58
|
+
height:16px;
|
59
|
+
width:16px;
|
60
|
+
}
|
9
61
|
|
10
|
-
|
62
|
+
._as_face3_png,
|
63
|
+
._as_face3_png {
|
64
|
+
display:inline-block;
|
65
|
+
background-image:url('/images/auto_sprite.png');
|
66
|
+
background-repeat:no-repeat;
|
67
|
+
}
|
11
68
|
|
12
69
|
|
13
|
-
Copyright (c) 2010
|
70
|
+
Copyright (c) 2010 Stephen Blackstone, released under the MIT license
|
data/auto_sprite.gemspec
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
spec = Gem::Specification.new do |s|
|
2
2
|
require 'fileutils'
|
3
3
|
s.name = "auto_sprite"
|
4
|
-
s.version = "0.0.
|
4
|
+
s.version = "0.0.3"
|
5
5
|
s.author = "Stephen Blackstone"
|
6
6
|
s.email = "sblackstone@gmail.com"
|
7
|
-
|
7
|
+
s.homepage = "http://gemcutter.org/gems/auto_sprite"
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.summary = "Automagic Sprite
|
9
|
+
s.summary = "A fully-Automagic Sprite Builder"
|
10
|
+
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"
|
10
11
|
s.files = ["./README", "./auto_sprite.gemspec", "./MIT-LICENSE", "./rails", "./rails/init.rb", "./lib", "./lib/auto_sprite.rb"]
|
11
12
|
s.require_path = "lib"
|
12
13
|
s.has_rdoc = false
|
data/lib/auto_sprite.rb
CHANGED
@@ -32,19 +32,20 @@ module AutoSprite
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def write_new_assets
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
35
|
+
unless sprite_file_paths.empty?
|
36
|
+
image_list = Magick::ImageList.new(*sprite_file_paths)
|
37
|
+
image_list.append(true).write(SPRITE_IMG_PATH)
|
38
|
+
all_class_names = sprite_file_names.map { |x| '.' + generate_css_name(x) }
|
39
|
+
pos = 0
|
40
|
+
File.open(CSS_FILE_PATH, "w") do |f|
|
41
|
+
image_list.each do |img|
|
42
|
+
css_class = generate_css_name(img.filename)
|
43
|
+
f << ".#{css_class}{background-position:0 #{pos* -1}px;height:#{img.rows}px;width:#{img.columns}px;}"
|
44
|
+
pos = pos + img.rows;
|
45
|
+
end
|
46
|
+
f << all_class_names.join(",")
|
47
|
+
f << "{display:inline-block;background-image:url('#{SPRITE_IMG_URL}');background-repeat:no-repeat;}"
|
44
48
|
end
|
45
|
-
f << all_class_names.join(",")
|
46
|
-
f << "{display:inline-block;background-image:url('#{SPRITE_IMG_URL}');background-repeat:no-repeat;}"
|
47
|
-
|
48
49
|
end
|
49
50
|
end
|
50
51
|
end
|
@@ -52,13 +53,16 @@ end
|
|
52
53
|
|
53
54
|
|
54
55
|
module AutoSprite::Helpers
|
55
|
-
def
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
56
|
+
def self.included(base)
|
57
|
+
base.class_eval do
|
58
|
+
def image_tag(source, options = {})
|
59
|
+
src = path_to_image(source)
|
60
|
+
if src =~ /\/images\/sprites/
|
61
|
+
"<div class='#{AutoSprite.generate_css_name(src)}'></div>"
|
62
|
+
else
|
63
|
+
super(source,options)
|
64
|
+
end
|
65
|
+
end
|
61
66
|
end
|
62
67
|
end
|
63
68
|
end
|
64
|
-
|
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: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Blackstone
|
@@ -13,7 +13,7 @@ date: 2010-01-09 00:00:00 -05:00
|
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
16
|
-
description:
|
16
|
+
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
|
17
17
|
email: sblackstone@gmail.com
|
18
18
|
executables: []
|
19
19
|
|
@@ -29,7 +29,7 @@ files:
|
|
29
29
|
- ./lib/auto_sprite.rb
|
30
30
|
- README
|
31
31
|
has_rdoc: true
|
32
|
-
homepage:
|
32
|
+
homepage: http://gemcutter.org/gems/auto_sprite
|
33
33
|
licenses: []
|
34
34
|
|
35
35
|
post_install_message:
|
@@ -55,6 +55,6 @@ rubyforge_project:
|
|
55
55
|
rubygems_version: 1.3.5
|
56
56
|
signing_key:
|
57
57
|
specification_version: 3
|
58
|
-
summary: Automagic Sprite
|
58
|
+
summary: A fully-Automagic Sprite Builder
|
59
59
|
test_files: []
|
60
60
|
|