dohmoose_auto_sprite 1.1.1.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +84 -0
- data/auto_sprite.gemspec +16 -0
- data/lib/auto_sprite.rb +83 -0
- data/rails/init.rb +7 -0
- metadata +72 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
|
2
|
+
=AutoSprite 1.1.0
|
3
|
+
|
4
|
+
An easy, automated CSS image sprite creator.
|
5
|
+
|
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.
|
7
|
+
|
8
|
+
|
9
|
+
==Install
|
10
|
+
|
11
|
+
1. Install auto_sprite and RMagick.
|
12
|
+
|
13
|
+
gem install RMagick auto_sprite
|
14
|
+
|
15
|
+
2. Edit your environement.rb add config.gem "auto_sprite"
|
16
|
+
|
17
|
+
==Usage
|
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
|
+
4. Use your images like you normally would:
|
27
|
+
|
28
|
+
<%= image_tag 'sprites/icon1.jpg' %>
|
29
|
+
|
30
|
+
A :title can also be passed so your icons have tooltips:
|
31
|
+
|
32
|
+
<%= image_tag "sprites/stuff.png", :title => "I like Ice Cream" %>
|
33
|
+
|
34
|
+
|
35
|
+
5. Reload after adding any new images to sprites/ and enjoy your now faster rendering website.
|
36
|
+
|
37
|
+
==Notes
|
38
|
+
- Animated images are not supported.
|
39
|
+
- Any image format supported by RMagick should work.
|
40
|
+
- Images of mixed sizes are not a problem.
|
41
|
+
- Should auto_sprite be removed, your application still works!
|
42
|
+
|
43
|
+
==Details
|
44
|
+
|
45
|
+
When rails starts, it checks whether or not the CSS or Sprite file is stale or missing.
|
46
|
+
|
47
|
+
If so, it will create:
|
48
|
+
|
49
|
+
RAILS_ROOT/public/stylesheets/auto_sprite.css
|
50
|
+
RAILS_ROOT/public/images/auto_sprite.png
|
51
|
+
|
52
|
+
|
53
|
+
The image tag will automatically generate a div tag for any images located in the sprite directory.
|
54
|
+
|
55
|
+
<span class="_as_logo_png"></span> instead of <img src="/images/sprites/logo.png" />
|
56
|
+
|
57
|
+
|
58
|
+
Here is an exmplmple of the stylehseet that would be generated if you had two files face3.png and face4.png
|
59
|
+
|
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
|
+
|
84
|
+
Copyright (c) 2010 Stephen Blackstone, released under the MIT license
|
data/auto_sprite.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
spec = Gem::Specification.new do |s|
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
s.name = "dohmoose_auto_sprite"
|
5
|
+
s.version = "1.1.1.pre"
|
6
|
+
s.authors = ["Stephen Blackstone", "Don Buchanan"]
|
7
|
+
s.email = ["sblackstone@gmail.com", "mail@donaldbuchanan.com"]
|
8
|
+
s.homepage = "http://fargle.org/auto_sprite"
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.summary = "A fully-Automagic Sprite Builder"
|
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"
|
12
|
+
s.files = ["./README.rdoc", "./auto_sprite.gemspec", "./MIT-LICENSE", "./rails", "./rails/init.rb", "./lib", "./lib/auto_sprite.rb"]
|
13
|
+
s.require_path = "lib"
|
14
|
+
s.has_rdoc = false
|
15
|
+
end
|
16
|
+
|
data/lib/auto_sprite.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'RMagick'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module AutoSprite
|
5
|
+
SPRITE_ASSETS_PATH = File.join(RAILS_ROOT, 'public', 'images', 'sprites')
|
6
|
+
CSS_FILE_PATH = File.join(RAILS_ROOT, 'public', 'stylesheets', 'auto_sprite.css')
|
7
|
+
SPRITE_IMG_PATH = File.join(RAILS_ROOT, 'public', 'images', 'auto_sprite.png')
|
8
|
+
SPRITE_IMG_URL = '/images/auto_sprite.png'
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def sprite_file_paths
|
12
|
+
@sprite_file_paths ||= sprite_file_names.map {|f| File.join(SPRITE_ASSETS_PATH, f) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def sprite_file_names
|
16
|
+
@sprite_file_names ||= Dir.entries(SPRITE_ASSETS_PATH).reject { |f|
|
17
|
+
!File.file?(File.join(SPRITE_ASSETS_PATH,f))
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def generate_css_name(f)
|
22
|
+
filename = File.basename(f).gsub(/\?.*$/, "")
|
23
|
+
filename.tr!('.', "_")
|
24
|
+
"_as_#{filename}"
|
25
|
+
end
|
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
|
+
|
33
|
+
def setup!
|
34
|
+
return if @@skip_setup
|
35
|
+
puts "setting up"
|
36
|
+
FileUtils::mkdir_p(SPRITE_ASSETS_PATH)
|
37
|
+
if stale?
|
38
|
+
FileUtils::rm_f(CSS_FILE_PATH)
|
39
|
+
FileUtils::rm_f(SPRITE_IMG_PATH)
|
40
|
+
write_new_assets
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def write_new_assets
|
45
|
+
unless sprite_file_paths.empty?
|
46
|
+
image_list = Magick::ImageList.new(*sprite_file_paths)
|
47
|
+
image_list.append(true).write(SPRITE_IMG_PATH)
|
48
|
+
all_class_names = sprite_file_names.map { |x| '.' + generate_css_name(x) }
|
49
|
+
pos = 0
|
50
|
+
File.open(CSS_FILE_PATH, "w") do |f|
|
51
|
+
image_list.each do |img|
|
52
|
+
css_class = generate_css_name(img.filename)
|
53
|
+
f << ".#{css_class}{background-position:0 #{pos * -1}px;height:#{img.rows}px;width:#{img.columns}px;}"
|
54
|
+
pos = pos + img.rows;
|
55
|
+
end
|
56
|
+
f << all_class_names.join(",")
|
57
|
+
f << "{display:inline-block;background-image:url('#{SPRITE_IMG_URL}');background-repeat:no-repeat;}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def skip_setup_on(*environments)
|
63
|
+
@@skip_setup = environments.map(&:to_s).include?(RAILS_ENV)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
module AutoSprite::Helpers
|
70
|
+
def self.included(base)
|
71
|
+
base.class_eval do
|
72
|
+
def image_tag(source, options = {})
|
73
|
+
src = path_to_image(source)
|
74
|
+
title = (options[:title].nil? or options[:title].empty?) ? "" : "title='#{options[:title]}'"
|
75
|
+
if src =~ /\/images\/sprites/
|
76
|
+
"<span #{title} class='#{AutoSprite.generate_css_name(src)}'></span>"
|
77
|
+
else
|
78
|
+
super(source,options)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/rails/init.rb
ADDED
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dohmoose_auto_sprite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: true
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
- pre
|
10
|
+
version: 1.1.1.pre
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Stephen Blackstone
|
14
|
+
- Don Buchanan
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2010-03-05 00:00:00 +11:00
|
20
|
+
default_executable:
|
21
|
+
dependencies: []
|
22
|
+
|
23
|
+
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
|
24
|
+
email:
|
25
|
+
- sblackstone@gmail.com
|
26
|
+
- mail@donaldbuchanan.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
33
|
+
files:
|
34
|
+
- ./README.rdoc
|
35
|
+
- ./auto_sprite.gemspec
|
36
|
+
- ./MIT-LICENSE
|
37
|
+
- ./rails/init.rb
|
38
|
+
- ./lib/auto_sprite.rb
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://fargle.org/auto_sprite
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
segments:
|
53
|
+
- 0
|
54
|
+
version: "0"
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
segments:
|
60
|
+
- 1
|
61
|
+
- 3
|
62
|
+
- 1
|
63
|
+
version: 1.3.1
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.3.6
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: A fully-Automagic Sprite Builder
|
71
|
+
test_files: []
|
72
|
+
|