lemonade 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.md ADDED
@@ -0,0 +1,26 @@
1
+ Changelog
2
+ =========
3
+
4
+
5
+ 0.3.0
6
+ -----
7
+
8
+ * Switched from RMagick to chunky_png gem
9
+ * No RMagick/ImageMagick required anymore (Rails 2.3.x sometimes crashed)
10
+ * Only PNG files are supported (both input and output)
11
+ * Don’t compose the same image twice (use background-position of first image instead)
12
+ * Space between images now works as expected if more than 1 output image (path) is used
13
+ * Wrote this changelog
14
+
15
+
16
+ 0.2.0
17
+ -----
18
+
19
+ * Support for background-positions
20
+ * Support for 100%/right aligned images
21
+
22
+
23
+ 0.1.0
24
+ -----
25
+
26
+ * Initial release
data/README.md CHANGED
@@ -35,6 +35,7 @@ Background
35
35
  * No Rake task needed
36
36
  * No additional classes
37
37
  * No configuration
38
+ * No RMagick required (but full support for PNG)
38
39
 
39
40
 
40
41
  Installation
@@ -88,7 +89,6 @@ Right aligned images are possible:
88
89
 
89
90
  The original image will be placed on the right side of the sprite image.
90
91
  Use this, if you have a link with an arrow on the right side (like Apple).
91
-
92
92
 
93
93
 
94
94
  Note on Patches/Pull Requests
@@ -102,6 +102,7 @@ Note on Patches/Pull Requests
102
102
  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
103
103
  * Send me a pull request. Bonus points for topic branches.
104
104
 
105
+
105
106
  Copyright
106
107
  ---------
107
108
 
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ begin
12
12
  gem.authors = ["Nico Hagenburger"]
13
13
  gem.add_dependency "haml", ">= 3.0.0"
14
14
  gem.add_dependency "compass", ">= 0.10.0"
15
- gem.add_dependency "rmagick"
15
+ gem.add_dependency "chunky_png", ">= 0.7.3"
16
16
  gem.add_development_dependency "rspec", ">= 1.2.9"
17
17
  end
18
18
  Jeweler::GemcutterTasks.new
data/TODO.md ADDED
@@ -0,0 +1,5 @@
1
+ Todo
2
+ ====
3
+
4
+ * Rails 3 support (currently Rails 2.3.x, Staticmatic, command line/`compass watch`)
5
+ * Remove Compass from requirements (should work with Sass only)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
data/lemonade.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{lemonade}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nico Hagenburger"]
12
- s.date = %q{2010-05-21}
12
+ s.date = %q{2010-06-25}
13
13
  s.description = %q{Generates sprites on the fly by using `background: sprite-image("sprites/logo.png")`.}
14
14
  s.email = %q{gems@hagenburger.net}
15
15
  s.extra_rdoc_files = [
@@ -18,15 +18,18 @@ Gem::Specification.new do |s|
18
18
  s.files = [
19
19
  ".document",
20
20
  ".gitignore",
21
+ "CHANGELOG.md",
21
22
  "MIT-LICENSE",
22
23
  "README.md",
23
24
  "Rakefile",
25
+ "TODO.md",
24
26
  "VERSION",
25
27
  "lemonade.gemspec",
26
28
  "lib/lemonade.rb",
27
29
  "lib/lemonade/lemonade.rb",
28
30
  "lib/lemonade/sass_extensions/functions/lemonade.rb",
29
31
  "spec/images/other_images/more-images/sprites/test.png",
32
+ "spec/images/other_images/test.png",
30
33
  "spec/images/sprites/10x10.png",
31
34
  "spec/images/sprites/150x10.png",
32
35
  "spec/images/sprites/20x20.png",
@@ -38,7 +41,7 @@ Gem::Specification.new do |s|
38
41
  s.homepage = %q{http://github.com/hagenburger/lemonade}
39
42
  s.rdoc_options = ["--charset=UTF-8"]
40
43
  s.require_paths = ["lib"]
41
- s.rubygems_version = %q{1.3.7}
44
+ s.rubygems_version = %q{1.3.6}
42
45
  s.summary = %q{On the fly sprite generator for Sass/Compass}
43
46
  s.test_files = [
44
47
  "spec/lemonade_spec.rb",
@@ -49,21 +52,21 @@ Gem::Specification.new do |s|
49
52
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50
53
  s.specification_version = 3
51
54
 
52
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
53
56
  s.add_runtime_dependency(%q<haml>, [">= 3.0.0"])
54
57
  s.add_runtime_dependency(%q<compass>, [">= 0.10.0"])
55
- s.add_runtime_dependency(%q<rmagick>, [">= 0"])
58
+ s.add_runtime_dependency(%q<chunky_png>, [">= 0.7.3"])
56
59
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
57
60
  else
58
61
  s.add_dependency(%q<haml>, [">= 3.0.0"])
59
62
  s.add_dependency(%q<compass>, [">= 0.10.0"])
60
- s.add_dependency(%q<rmagick>, [">= 0"])
63
+ s.add_dependency(%q<chunky_png>, [">= 0.7.3"])
61
64
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
62
65
  end
63
66
  else
64
67
  s.add_dependency(%q<haml>, [">= 3.0.0"])
65
68
  s.add_dependency(%q<compass>, [">= 0.10.0"])
66
- s.add_dependency(%q<rmagick>, [">= 0"])
69
+ s.add_dependency(%q<chunky_png>, [">= 0.7.3"])
67
70
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
68
71
  end
69
72
  end
data/lib/lemonade.rb CHANGED
@@ -8,7 +8,7 @@ end
8
8
  require 'rubygems'
9
9
  require 'compass'
10
10
  require 'sass/plugin'
11
- require 'rmagick'
11
+ require 'chunky_png'
12
12
  require File.dirname(__FILE__) + '/lemonade/sass_extensions/functions/lemonade'
13
13
  require File.dirname(__FILE__) + '/lemonade/lemonade'
14
14
 
@@ -2,21 +2,18 @@ module Lemonade
2
2
  def self.generate_sprites
3
3
  if $lemonade_sprites
4
4
  $lemonade_sprites.each do |sprite_name, sprite|
5
- sprite_image = Magick::Image.new(sprite[:width], sprite[:height]) do
6
- self.background_color = 'transparent'
7
- end
5
+ sprite_image = ChunkyPNG::Image.new(sprite[:width], sprite[:height], ChunkyPNG::Color::TRANSPARENT)
8
6
  y = 0
9
7
  sprite[:images].each do |image|
10
8
  file = File.join(Compass.configuration.images_path, image[:file])
11
- single_image = Magick::Image::read(file).first
9
+ single_image = ChunkyPNG::Image.from_file(file)
12
10
  x = (sprite[:width] - image[:width]) * image[:x]
13
- sprite_image.composite!(single_image, x, image[:y], Magick::OverCompositeOp)
11
+ sprite_image.compose single_image, x, image[:y]
14
12
  end
15
13
  file = File.join(Compass.configuration.images_path, "#{ sprite_name }.png")
16
- sprite_image.write file
14
+ sprite_image.save file#, :fast_rgba
17
15
  end
18
16
  $lemonade_sprites = nil
19
- $lemonade_space_bottom = 0
20
17
  end
21
18
  end
22
19
  end
@@ -6,22 +6,34 @@ module Lemonade::SassExtensions::Functions::Lemonade
6
6
  raise Sass::SyntaxError, 'Please provide a file in a folder: e.g. sprites/button.png'
7
7
  end
8
8
  dir, name, filename = $1, $2, $3
9
- height = image_height(file).value
10
- width = image_width(file).value
11
- margin_top = calculate_margin_top(margin_top_or_both, margin_bottom)
9
+ filestr = file.to_s.gsub('"', '')
12
10
 
13
11
  $lemonade_sprites ||= {}
14
- sprite = $lemonade_sprites["#{ dir }/#{ name }"] ||= { :height => 0, :width => 0, :images => [] }
15
- x = (add_x and add_x.numerator_units == %w(%)) ? add_x.value / 100 : 0
16
- y = sprite[:height] + margin_top
17
- sprite[:height] += height + margin_top
18
- sprite[:width] = width if width > sprite[:width]
19
- sprite[:images] << { :file => file.to_s.gsub('"', ''), :height => height, :width => width, :x => x, :y => y }
12
+ sprite = $lemonade_sprites["#{ dir }/#{ name }"] ||= {
13
+ :height => 0,
14
+ :width => 0,
15
+ :images => [],
16
+ :margin_bottom => 0
17
+ }
20
18
 
19
+ if image = sprite[:images].detect{ |image| image[:file] == filestr }
20
+ y = image[:y]
21
+ else
22
+ height = image_height(file).value
23
+ width = image_width(file).value
24
+ margin_top = calculate_margin_top(sprite, margin_top_or_both, margin_bottom)
25
+ x = (add_x and add_x.numerator_units == %w(%)) ? add_x.value / 100 : 0
26
+ y = sprite[:height] + margin_top
27
+ sprite[:height] += height + margin_top
28
+ sprite[:width] = width if width > sprite[:width]
29
+ sprite[:images] << { :file => filestr, :height => height, :width => width, :x => x, :y => y }
30
+ end
31
+
21
32
  position = background_position(0, y, add_x, add_y)
22
- file = image_url(Sass::Script::String.new("#{ dir }#{ name }.png"))
23
- Sass::Script::String.new("#{ file }#{ position }")
33
+ output_file = image_url(Sass::Script::String.new("#{ dir }#{ name }.png"))
34
+ Sass::Script::String.new("#{ output_file }#{ position }")
24
35
  end
36
+ alias_method :sprite_img, :sprite_image
25
37
 
26
38
  private
27
39
 
@@ -34,10 +46,10 @@ private
34
46
  end
35
47
  end
36
48
 
37
- def calculate_margin_top(margin_top_or_both, margin_bottom)
49
+ def calculate_margin_top(sprite, margin_top_or_both, margin_bottom)
38
50
  margin_top_or_both = margin_top_or_both ? margin_top_or_both.value : 0
39
- margin_top = ($lemonade_margin_bottom ||= 0) > margin_top_or_both ? $lemonade_margin_bottom : margin_top_or_both
40
- $lemonade_margin_bottom = margin_bottom ? margin_bottom.value : margin_top_or_both
51
+ margin_top = (sprite[:margin_bottom] ||= 0) > margin_top_or_both ? sprite[:margin_bottom] : margin_top_or_both
52
+ sprite[:margin_bottom] = margin_bottom ? margin_bottom.value : margin_top_or_both
41
53
  margin_top
42
54
  end
43
55
 
Binary file
@@ -25,6 +25,10 @@ describe Lemonade::SassExtensions::Functions::Lemonade do
25
25
  evaluate('sprite-image("sprites/30x30.png")').should == "url('/sprites.png')"
26
26
  end
27
27
 
28
+ it "should also work with `sprite-img`" do
29
+ evaluate('sprite-img("sprites/30x30.png")').should == "url('/sprites.png')"
30
+ end
31
+
28
32
  it "should work in folders with dashes and underscores" do
29
33
  evaluate('sprite-image("other_images/more-images/sprites/test.png")').should ==
30
34
  "url('/other_images/more-images/sprites.png')"
@@ -89,6 +93,12 @@ describe Lemonade::SassExtensions::Functions::Lemonade do
89
93
  image_size('sprites.png').should == [30, 100]
90
94
  end
91
95
 
96
+ it "should calculate empty space correctly when 2 output images are uses" do
97
+ evaluate('sprite-image("sprites/10x10.png", 0, 0, 0, 30px)').should == "url('/sprites.png')"
98
+ evaluate('sprite-image("other_images/test.png")').should == "url('/other_images.png')"
99
+ evaluate('sprite-image("sprites/20x20.png", 0, 0, 20px, 5px)').should == "url('/sprites.png') 0 -40px"
100
+ end
101
+
92
102
  it "should allow % for x positions" do
93
103
  # Resulting sprite should look like (1 line = 10px height, X = placed image):
94
104
 
@@ -99,4 +109,11 @@ describe Lemonade::SassExtensions::Functions::Lemonade do
99
109
  evaluate('sprite-image("sprites/10x10.png", 100%)').should == "url('/sprites.png') 100% -10px"
100
110
  end
101
111
 
112
+ it "should not compose the same image twice" do
113
+ evaluate('sprite-image("sprites/10x10.png")').should == "url('/sprites.png')"
114
+ evaluate('sprite-image("sprites/20x20.png")').should == "url('/sprites.png') 0 -10px"
115
+ evaluate('sprite-image("sprites/20x20.png")').should == "url('/sprites.png') 0 -10px" # reuse image from line above
116
+ image_size('sprites.png').should == [20, 30]
117
+ end
118
+
102
119
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 0.2.0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nico Hagenburger
@@ -14,14 +14,13 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-21 00:00:00 +02:00
17
+ date: 2010-06-25 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: haml
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
24
  requirements:
26
25
  - - ">="
27
26
  - !ruby/object:Gem::Version
@@ -36,7 +35,6 @@ dependencies:
36
35
  name: compass
37
36
  prerelease: false
38
37
  requirement: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
38
  requirements:
41
39
  - - ">="
42
40
  - !ruby/object:Gem::Version
@@ -48,23 +46,23 @@ dependencies:
48
46
  type: :runtime
49
47
  version_requirements: *id002
50
48
  - !ruby/object:Gem::Dependency
51
- name: rmagick
49
+ name: chunky_png
52
50
  prerelease: false
53
51
  requirement: &id003 !ruby/object:Gem::Requirement
54
- none: false
55
52
  requirements:
56
53
  - - ">="
57
54
  - !ruby/object:Gem::Version
58
55
  segments:
59
56
  - 0
60
- version: "0"
57
+ - 7
58
+ - 3
59
+ version: 0.7.3
61
60
  type: :runtime
62
61
  version_requirements: *id003
63
62
  - !ruby/object:Gem::Dependency
64
63
  name: rspec
65
64
  prerelease: false
66
65
  requirement: &id004 !ruby/object:Gem::Requirement
67
- none: false
68
66
  requirements:
69
67
  - - ">="
70
68
  - !ruby/object:Gem::Version
@@ -86,15 +84,18 @@ extra_rdoc_files:
86
84
  files:
87
85
  - .document
88
86
  - .gitignore
87
+ - CHANGELOG.md
89
88
  - MIT-LICENSE
90
89
  - README.md
91
90
  - Rakefile
91
+ - TODO.md
92
92
  - VERSION
93
93
  - lemonade.gemspec
94
94
  - lib/lemonade.rb
95
95
  - lib/lemonade/lemonade.rb
96
96
  - lib/lemonade/sass_extensions/functions/lemonade.rb
97
97
  - spec/images/other_images/more-images/sprites/test.png
98
+ - spec/images/other_images/test.png
98
99
  - spec/images/sprites/10x10.png
99
100
  - spec/images/sprites/150x10.png
100
101
  - spec/images/sprites/20x20.png
@@ -112,7 +113,6 @@ rdoc_options:
112
113
  require_paths:
113
114
  - lib
114
115
  required_ruby_version: !ruby/object:Gem::Requirement
115
- none: false
116
116
  requirements:
117
117
  - - ">="
118
118
  - !ruby/object:Gem::Version
@@ -120,7 +120,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
120
  - 0
121
121
  version: "0"
122
122
  required_rubygems_version: !ruby/object:Gem::Requirement
123
- none: false
124
123
  requirements:
125
124
  - - ">="
126
125
  - !ruby/object:Gem::Version
@@ -130,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
129
  requirements: []
131
130
 
132
131
  rubyforge_project:
133
- rubygems_version: 1.3.7
132
+ rubygems_version: 1.3.6
134
133
  signing_key:
135
134
  specification_version: 3
136
135
  summary: On the fly sprite generator for Sass/Compass