jdeerhake-compass-rmagick-engine 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .sass-cache/*
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in compass-rmagick.gemspec
4
+ gemspec
5
+
6
+ gem "rspec", '~> 2.5.0'
7
+ gem 'mocha'
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/Readme.md ADDED
@@ -0,0 +1,21 @@
1
+ # Compass Rmagick Engine
2
+
3
+ Compass Rmagick Engine is a drop in replacement for creating sprites using chunky_png.
4
+
5
+ ## Usage
6
+
7
+ ### Rails
8
+
9
+ 1. In your gem file add `gem 'compass-rmagick-engine', '~> 0.0.1'`
10
+ 2. Add `sprite_engine = :rmagick` to your compass config
11
+
12
+ Standalone
13
+
14
+ First run `gem install compass-rmagick-engine`
15
+
16
+ Then open your compass config file and add
17
+
18
+ require 'compass-rmagick-engine'
19
+ sprite_engine = :rmagick
20
+
21
+
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "compass-rmagick-engine/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "jdeerhake-compass-rmagick-engine"
7
+ s.version = Compass::Rmagick::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Scott Davis", "John Deerhake"]
10
+ s.email = ["jetviper21@gmail.com", "jdeerhake@gmail.com"]
11
+ s.homepage = "https://github.com/jetviper21/compass-rmagick-engine"
12
+ s.summary = %q{Rmagick sprite engine for compass}
13
+ s.description = %q{Drop in rmagick sprite engine for compass}
14
+
15
+ s.rubyforge_project = "compass-rmagick-engine"
16
+
17
+ s.add_dependency "compass", '~> 0.11.3'
18
+ s.add_dependency "rmagick", '~> 2.13.1'
19
+
20
+
21
+ s.files = `git ls-files`.split("\n")
22
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
+ s.require_paths = ["lib"]
25
+ end
26
+
@@ -0,0 +1,51 @@
1
+ require 'RMagick'
2
+
3
+ module Compass
4
+ module SassExtensions
5
+ module Sprites
6
+ class RmagickEngine < Compass::SassExtensions::Sprites::Engine
7
+
8
+ def construct_sprite
9
+ @canvas = Magick::Image.new(width, height) {
10
+ self.background_color = 'none'
11
+ }
12
+ @canvas.format = 'PNG24'
13
+ images.each do |image|
14
+ input_png = Magick::Image.read(image.file).first
15
+ if image.repeat == "no-repeat"
16
+ @canvas = composite_images(@canvas, input_png, image.left, image.top)
17
+ else
18
+ x = image.left - (image.left / image.width).ceil * image.width
19
+ while x < width do
20
+ @canvas = composite_images(@canvas, input_png, x, image.top)
21
+ x += image.width
22
+ end
23
+ end
24
+ end
25
+ @canvas
26
+ end
27
+
28
+ def save(filename)
29
+ if canvas.nil?
30
+ construct_sprite
31
+ end
32
+
33
+ canvas.write(filename)
34
+ end
35
+
36
+ private #===============================================================================>
37
+
38
+ def composite_images(dest_image, src_image, x, y)
39
+ width = [src_image.columns + x, dest_image.columns].max
40
+ height = [src_image.rows + y, dest_image.rows].max
41
+ image = Magick::Image.new(width, height) {self.background_color = 'none'}
42
+ image.composite!(dest_image, 0, 0, Magick::CopyCompositeOp)
43
+ image.composite!(src_image, x, y, Magick::CopyCompositeOp)
44
+ image
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+ end
51
+
@@ -0,0 +1,6 @@
1
+ module Compass
2
+ module Rmagick
3
+ VERSION = "0.0.3"
4
+ end
5
+ end
6
+
@@ -0,0 +1,77 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'compass-rmagick-engine'
3
+ require 'digest/md5'
4
+
5
+ describe Compass::SassExtensions::Sprites::RmagickEngine do
6
+
7
+ before :each do
8
+ @images_src_path = File.join(File.dirname(__FILE__), 'test_project', 'public', 'images')
9
+ @images_tmp_path = File.join(File.dirname(__FILE__), 'test_project', 'public', 'images-tmp')
10
+ ::FileUtils.cp_r @images_src_path, @images_tmp_path
11
+ file = StringIO.new("images_path = #{@images_tmp_path.inspect}\nsprite_engine = :rmagick")
12
+ Compass.add_configuration(file, "sprite_config")
13
+ Compass.configure_sass_plugin!
14
+ end
15
+
16
+ after :each do
17
+ FileUtils.rm_r @images_tmp_path
18
+ end
19
+
20
+ def map_location(file)
21
+ Dir.glob(File.join(@images_tmp_path, file)).first
22
+ end
23
+
24
+ def image_size(file)
25
+ IO.read(map_location(file))[0x10..0x18].unpack('NN')
26
+ end
27
+
28
+ def image_md5(file)
29
+ md5 = Digest::MD5.new
30
+ md5.update IO.read(map_location(file))
31
+ md5.hexdigest
32
+ end
33
+
34
+ def render(scss)
35
+ scss = %Q(@import "compass"; #{scss})
36
+ options = Compass.sass_engine_options
37
+ options[:line_comments] = false
38
+ options[:style] = :expanded
39
+ options[:syntax] = :scss
40
+ css = Sass::Engine.new(scss, options).render
41
+ # reformat to fit result of heredoc:
42
+ " #{css.gsub('@charset "UTF-8";', '').gsub(/\n/, "\n ").strip}\n"
43
+ end
44
+
45
+ it "should render sprites using rmagick" do
46
+ css = render <<-CSS
47
+ @import "squares/*.png"
48
+ CSS
49
+ File.exists?(File.join(@images_tmp_path, 'squares-161c60ad78.png'))
50
+ image_size('squares-*.png').should == [20,30]
51
+ end
52
+
53
+ it "should render aprites using spacing" do
54
+ css = render <<-SCSS
55
+ $squares-ten-by-ten-spacing: 44px;
56
+ $squares-twenty-by-twenty-spacing: 33px;
57
+ @import "squares/*.png";
58
+ @include all-squares-sprites;
59
+ SCSS
60
+ css.should == <<-CSS
61
+ .squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
62
+ background: url('/squares-s1cd84c9068.png') no-repeat;
63
+ }
64
+
65
+ .squares-ten-by-ten {
66
+ background-position: 0 0;
67
+ }
68
+
69
+ .squares-twenty-by-twenty {
70
+ background-position: 0 -54px;
71
+ }
72
+ CSS
73
+ image_size('squares-*.png').should == [20, 74]
74
+ end
75
+
76
+
77
+ end
@@ -0,0 +1,5 @@
1
+ require 'compass'
2
+
3
+ RSpec.configure do |config|
4
+ config.mock_with :mocha
5
+ end
Binary file
Binary file
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jdeerhake-compass-rmagick-engine
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
11
+ platform: ruby
12
+ authors:
13
+ - Scott Davis
14
+ - John Deerhake
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-06-23 00:00:00 -07:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: compass
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ hash: 53
31
+ segments:
32
+ - 0
33
+ - 11
34
+ - 3
35
+ version: 0.11.3
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: rmagick
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ hash: 57
47
+ segments:
48
+ - 2
49
+ - 13
50
+ - 1
51
+ version: 2.13.1
52
+ type: :runtime
53
+ version_requirements: *id002
54
+ description: Drop in rmagick sprite engine for compass
55
+ email:
56
+ - jetviper21@gmail.com
57
+ - jdeerhake@gmail.com
58
+ executables: []
59
+
60
+ extensions: []
61
+
62
+ extra_rdoc_files: []
63
+
64
+ files:
65
+ - .DS_Store
66
+ - .gitignore
67
+ - Gemfile
68
+ - Rakefile
69
+ - Readme.md
70
+ - compass-rmagick-engine.gemspec
71
+ - lib/compass-rmagick-engine.rb
72
+ - lib/compass-rmagick-engine/version.rb
73
+ - spec/rmagick_spec.rb
74
+ - spec/spec_helper.rb
75
+ - spec/test_project/.DS_Store
76
+ - spec/test_project/public/.DS_Store
77
+ - spec/test_project/public/images/.DS_Store
78
+ - spec/test_project/public/images/squares/ten-by-ten.png
79
+ - spec/test_project/public/images/squares/twenty-by-twenty.png
80
+ has_rdoc: true
81
+ homepage: https://github.com/jetviper21/compass-rmagick-engine
82
+ licenses: []
83
+
84
+ post_install_message:
85
+ rdoc_options: []
86
+
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: 3
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ requirements: []
108
+
109
+ rubyforge_project: compass-rmagick-engine
110
+ rubygems_version: 1.5.3
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: Rmagick sprite engine for compass
114
+ test_files: []
115
+