compass-rmagick-engine 0.0.1

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,20 @@
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
+ In your gem file add
10
+
11
+ 1. `gem 'compass-rmagick-engine'`
12
+ 2. Add `sprite_engine = :rmagick` to your compass config
13
+
14
+ Standalone
15
+
16
+ 1. run `gem install compass-rmagick-engine`
17
+ 2. open your compass config file and add `require 'compass-rmagick-engine'`
18
+ 3. and also add `sprite_engine = :rmagick`
19
+
20
+
@@ -0,0 +1,25 @@
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 = "compass-rmagick-engine"
7
+ s.version = Compass::Rmagick::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Scott Davis"]
10
+ s.email = ["jetviper21@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.beta.5'
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
@@ -0,0 +1,5 @@
1
+ module Compass
2
+ module Rmagick
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,42 @@
1
+ require 'rmagick'
2
+ module Compass
3
+ module SassExtensions
4
+ module Sprites
5
+ module RmagickEngine
6
+ class ::Magick::Image
7
+ alias :save :write
8
+ end
9
+
10
+ def construct_sprite
11
+ output_png = Magick::Image.new(width, height)
12
+ output_png.background_color = 'none'
13
+ output_png.format = 'PNG24'
14
+ images.each do |image|
15
+ input_png = Magick::Image.read(image.file).first
16
+ if image.repeat == "no-repeat"
17
+ output_png = composite_images(output_png, input_png, image.left, image.top)
18
+ else
19
+ x = image.left - (image.left / image.width).ceil * image.width
20
+ while x < width do
21
+ output_png = composite_images(output_png, input_png, x, image.top)
22
+ x += image.width
23
+ end
24
+ end
25
+ end
26
+ output_png
27
+ end
28
+
29
+ private #===============================================================================>
30
+
31
+ def composite_images(dest_image, src_image, x, y)
32
+ width = [src_image.columns + x, dest_image.columns].max
33
+ height = [src_image.rows + y, dest_image.rows].max
34
+ image = Magick::Image.new(width, height) {self.background_color = 'none'}
35
+ image.composite!(dest_image, 0, 0, Magick::CopyCompositeOp)
36
+ image.composite!(src_image, x, y, Magick::CopyCompositeOp)
37
+ image
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -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::Sprites 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-1cd84c9068.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,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: compass-rmagick-engine
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Scott Davis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-03-29 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: compass
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: 0.11.beta.5
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: rmagick
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: 2.13.1
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ description: Drop in rmagick sprite engine for compass
39
+ email:
40
+ - jetviper21@gmail.com
41
+ executables: []
42
+
43
+ extensions: []
44
+
45
+ extra_rdoc_files: []
46
+
47
+ files:
48
+ - .DS_Store
49
+ - .gitignore
50
+ - Gemfile
51
+ - Rakefile
52
+ - Readme.md
53
+ - compass-rmagick-engine.gemspec
54
+ - lib/compass-rmagick-engine.rb
55
+ - lib/compass-rmagick-engine/version.rb
56
+ - spec/rmagick_spec.rb
57
+ - spec/spec_helper.rb
58
+ - spec/test_project/.DS_Store
59
+ - spec/test_project/public/.DS_Store
60
+ - spec/test_project/public/images/.DS_Store
61
+ - spec/test_project/public/images/squares/ten-by-ten.png
62
+ - spec/test_project/public/images/squares/twenty-by-twenty.png
63
+ has_rdoc: true
64
+ homepage: https://github.com/jetviper21/compass-rmagick-engine
65
+ licenses: []
66
+
67
+ post_install_message:
68
+ rdoc_options: []
69
+
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ requirements: []
85
+
86
+ rubyforge_project: compass-rmagick-engine
87
+ rubygems_version: 1.6.2
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Rmagick sprite engine for compass
91
+ test_files:
92
+ - spec/rmagick_spec.rb
93
+ - spec/spec_helper.rb
94
+ - spec/test_project/.DS_Store
95
+ - spec/test_project/public/.DS_Store
96
+ - spec/test_project/public/images/.DS_Store
97
+ - spec/test_project/public/images/squares/ten-by-ten.png
98
+ - spec/test_project/public/images/squares/twenty-by-twenty.png