auto_sprite 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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 ADDED
@@ -0,0 +1,13 @@
1
+ AutoSprite
2
+ ==========
3
+
4
+ Introduction goes here.
5
+
6
+
7
+ Example
8
+ =======
9
+
10
+ Example goes here.
11
+
12
+
13
+ Copyright (c) 2010 [name of plugin creator], released under the MIT license
@@ -0,0 +1,15 @@
1
+ spec = Gem::Specification.new do |s|
2
+ require 'fileutils'
3
+ s.name = "auto_sprite"
4
+ s.version = "0.0.1"
5
+ s.author = "Stephen Blackstone"
6
+ s.email = "sblackstone@gmail.com"
7
+ #s.homepage = "http://"
8
+ s.platform = Gem::Platform::RUBY
9
+ s.summary = "Automagic Sprite Builer"
10
+ s.files = ["./README", "./auto_sprite.gemspec", "./MIT-LICENSE", "./rails", "./rails/init.rb", "./lib", "./lib/auto_sprite.rb"]
11
+ s.require_path = "lib"
12
+ s.has_rdoc = false
13
+ s.extra_rdoc_files = ["README"]
14
+ end
15
+
@@ -0,0 +1,64 @@
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_names.map {|f| File.join(SPRITE_ASSETS_PATH, f) }
13
+ end
14
+
15
+ def sprite_file_names
16
+ 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 setup!
28
+ FileUtils::mkdir_p(SPRITE_ASSETS_PATH)
29
+ FileUtils::rm_f(CSS_FILE_PATH)
30
+ FileUtils::rm_f(SPRITE_IMG_PATH)
31
+ write_new_assets
32
+ end
33
+
34
+ def write_new_assets
35
+ image_list = Magick::ImageList.new(*sprite_file_paths)
36
+ image_list.append(true).write(SPRITE_IMG_PATH)
37
+ all_class_names = sprite_file_names.map { |x| '.' + generate_css_name(x) }
38
+ pos = 0
39
+ File.open(CSS_FILE_PATH, "w") do |f|
40
+ image_list.each do |img|
41
+ css_class = generate_css_name(img.filename)
42
+ f << ".#{css_class}{background-position:0 #{pos* -1}px;height:#{img.rows}px;width:#{img.columns}px;}"
43
+ pos = pos + img.rows;
44
+ end
45
+ f << all_class_names.join(",")
46
+ f << "{display:inline-block;background-image:url('#{SPRITE_IMG_URL}');background-repeat:no-repeat;}"
47
+
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+
54
+ module AutoSprite::Helpers
55
+ def image_tag(source, options = {})
56
+ src = path_to_image(source)
57
+ if src =~ /\/images\/sprites/
58
+ "<div class='#{AutoSprite.generate_css_name(src)}'></div>"
59
+ else
60
+ super(source,options)
61
+ end
62
+ end
63
+ end
64
+
data/rails/init.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'auto_sprite'
2
+ AutoSprite.setup!
3
+ ActionView::Helpers.send(:include, AutoSprite::Helpers)
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: auto_sprite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Stephen Blackstone
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-09 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: sblackstone@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ files:
25
+ - ./README
26
+ - ./auto_sprite.gemspec
27
+ - ./MIT-LICENSE
28
+ - ./rails/init.rb
29
+ - ./lib/auto_sprite.rb
30
+ - README
31
+ has_rdoc: true
32
+ homepage:
33
+ licenses: []
34
+
35
+ post_install_message:
36
+ rdoc_options: []
37
+
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ version:
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ requirements: []
53
+
54
+ rubyforge_project:
55
+ rubygems_version: 1.3.5
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: Automagic Sprite Builer
59
+ test_files: []
60
+