lemonade 0.1.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/.document +5 -0
- data/.gitignore +21 -0
- data/MIT-LICENSE +20 -0
- data/README.md +82 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/lemonade.gemspec +59 -0
- data/lib/lemonade.rb +26 -0
- data/lib/lemonade/lemonade.rb +20 -0
- data/lib/lemonade/sass_extensions/functions/lemonade.rb +35 -0
- data/spec/images/other_images/more-images/sprites/test-2.png +0 -0
- data/spec/images/sprites/test-1.png +0 -0
- data/spec/images/sprites/test-2.png +0 -0
- data/spec/lemonade_spec.rb +42 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +12 -0
- metadata +94 -0
data/.document
ADDED
data/.gitignore
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Nico Hagenburger
|
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.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
Lemonade—On the fly sprite generator for Sass/Compass
|
2
|
+
=====================================================
|
3
|
+
|
4
|
+
Usage (SCSS or Sass):
|
5
|
+
|
6
|
+
.fanta {
|
7
|
+
background: sprite-image("bottles/fanta.png");
|
8
|
+
}
|
9
|
+
.seven-up {
|
10
|
+
background: sprite-image("bottles/seven-up.png");
|
11
|
+
}
|
12
|
+
.coke {
|
13
|
+
background: sprite-image("cans/coke.png") no-repeat;
|
14
|
+
}
|
15
|
+
|
16
|
+
Output (CSS):
|
17
|
+
|
18
|
+
.fanta {
|
19
|
+
background: url('/images/bottles.png');
|
20
|
+
}
|
21
|
+
.seven-up {
|
22
|
+
background: url('/images/bottles.png') 0 -50px;
|
23
|
+
}
|
24
|
+
.coke {
|
25
|
+
background: url('/images/cans.png') no-repeat;
|
26
|
+
}
|
27
|
+
|
28
|
+
|
29
|
+
Background
|
30
|
+
----------
|
31
|
+
|
32
|
+
* Generates a sprite image for each folder (e. g. “bottles” and “cans”)
|
33
|
+
* Sets the background position (unless “0 0”)
|
34
|
+
* It uses the `images_dir` defined by Compass (just like `image-url()`)
|
35
|
+
* No Rake task needed
|
36
|
+
* No additional classes
|
37
|
+
* No configuration
|
38
|
+
|
39
|
+
|
40
|
+
Installation
|
41
|
+
------------
|
42
|
+
|
43
|
+
gem install haml
|
44
|
+
gem install compass
|
45
|
+
gem install rmagick
|
46
|
+
gem install lemonade
|
47
|
+
|
48
|
+
|
49
|
+
Options
|
50
|
+
-------
|
51
|
+
|
52
|
+
You can pass an additional background position.
|
53
|
+
It will be added to the calculated position:
|
54
|
+
|
55
|
+
.seven-up {
|
56
|
+
background: sprite-image("bottles/seven-up.png", 12px, 3px);
|
57
|
+
}
|
58
|
+
|
59
|
+
Output (assuming the calculated position would be “0 -50px” as shown above):
|
60
|
+
|
61
|
+
.seven-up {
|
62
|
+
background: url('/images/bottles.png') 12px -47px;
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
Note on Patches/Pull Requests
|
67
|
+
-----------------------------
|
68
|
+
|
69
|
+
* Fork the project.
|
70
|
+
* Make your feature addition or bug fix.
|
71
|
+
* Add tests for it. This is important so I don't break it in a
|
72
|
+
future version unintentionally.
|
73
|
+
* Commit, do not mess with rakefile, version, or history.
|
74
|
+
(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)
|
75
|
+
* Send me a pull request. Bonus points for topic branches.
|
76
|
+
|
77
|
+
Copyright
|
78
|
+
---------
|
79
|
+
|
80
|
+
Copyright (c) 2010 [Nico Hagenburger](http://www.hagenburger.net).
|
81
|
+
See MIT-LICENSE for details.
|
82
|
+
[Follow me](http://twitter.com/hagenburger) on twitter.
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "lemonade"
|
8
|
+
gem.summary = "On the fly sprite generator for Sass/Compass"
|
9
|
+
gem.description = "Generates sprites on the fly by using `background: sprite-image(\"sprites/logo.png\")`."
|
10
|
+
gem.email = "gems@hagenburger.net"
|
11
|
+
gem.homepage = "http://github.com/hagenburger/lemonade"
|
12
|
+
gem.authors = ["Nico Hagenburger"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
end
|
15
|
+
Jeweler::GemcutterTasks.new
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'spec/rake/spectask'
|
21
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
22
|
+
spec.libs << 'lib' << 'spec'
|
23
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
24
|
+
end
|
25
|
+
|
26
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
27
|
+
spec.libs << 'lib' << 'spec'
|
28
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
29
|
+
spec.rcov = true
|
30
|
+
end
|
31
|
+
|
32
|
+
task :spec => :check_dependencies
|
33
|
+
|
34
|
+
task :default => :spec
|
35
|
+
|
36
|
+
require 'rake/rdoctask'
|
37
|
+
Rake::RDocTask.new do |rdoc|
|
38
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
39
|
+
|
40
|
+
rdoc.rdoc_dir = 'rdoc'
|
41
|
+
rdoc.title = "lemonade #{version}"
|
42
|
+
rdoc.rdoc_files.include('README*')
|
43
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
44
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lemonade.gemspec
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{lemonade}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Nico Hagenburger"]
|
12
|
+
s.date = %q{2010-05-11}
|
13
|
+
s.description = %q{Generates sprites on the fly by using `background: sprite-image("sprites/logo.png")`.}
|
14
|
+
s.email = %q{gems@hagenburger.net}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.md"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
".gitignore",
|
21
|
+
"MIT-LICENSE",
|
22
|
+
"README.md",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"lemonade.gemspec",
|
26
|
+
"lib/lemonade.rb",
|
27
|
+
"lib/lemonade/lemonade.rb",
|
28
|
+
"lib/lemonade/sass_extensions/functions/lemonade.rb",
|
29
|
+
"spec/images/other_images/more-images/sprites/test-2.png",
|
30
|
+
"spec/images/sprites/test-1.png",
|
31
|
+
"spec/images/sprites/test-2.png",
|
32
|
+
"spec/lemonade_spec.rb",
|
33
|
+
"spec/spec.opts",
|
34
|
+
"spec/spec_helper.rb"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/hagenburger/lemonade}
|
37
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = %q{1.3.7}
|
40
|
+
s.summary = %q{On the fly sprite generator for Sass/Compass}
|
41
|
+
s.test_files = [
|
42
|
+
"spec/lemonade_spec.rb",
|
43
|
+
"spec/spec_helper.rb"
|
44
|
+
]
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
data/lib/lemonade.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Lemonade
|
2
|
+
module SassExtensions
|
3
|
+
module Functions
|
4
|
+
end
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'rubygems'
|
9
|
+
require 'compass'
|
10
|
+
require 'rmagick'
|
11
|
+
require File.dirname(__FILE__) + '/lemonade/sass_extensions/functions/lemonade'
|
12
|
+
require File.dirname(__FILE__) + '/lemonade/lemonade'
|
13
|
+
|
14
|
+
module Sass::Script::Functions
|
15
|
+
include Lemonade::SassExtensions::Functions::Lemonade
|
16
|
+
end
|
17
|
+
|
18
|
+
module Compass
|
19
|
+
class Compiler
|
20
|
+
alias_method :complile_without_comprass, :compile
|
21
|
+
def compile(sass_filename, css_filename)
|
22
|
+
complile_without_comprass sass_filename, css_filename
|
23
|
+
Lemonade::generate_sprites
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Lemonade
|
2
|
+
def self.generate_sprites
|
3
|
+
if $lemonade_sprites
|
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
|
8
|
+
y = 0
|
9
|
+
sprite[:images].each do |image|
|
10
|
+
file = File.join(Compass.configuration.images_path, image[:file])
|
11
|
+
single_image = Magick::Image::read(file).first
|
12
|
+
sprite_image.composite!(single_image, image[:x], image[:y], Magick::OverCompositeOp)
|
13
|
+
end
|
14
|
+
file = File.join(Compass.configuration.images_path, "#{ sprite_name }.png")
|
15
|
+
sprite_image.write file
|
16
|
+
end
|
17
|
+
$lemonade_sprites = nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Lemonade::SassExtensions::Functions::Lemonade
|
2
|
+
|
3
|
+
def sprite_image(file, add_x = nil, add_y = nil)
|
4
|
+
assert_type file, :String
|
5
|
+
unless (file.to_s =~ %r(^"(.+/)?(.+?)/(.+?)\.(png|gif|jpg)"$)) == 0
|
6
|
+
raise Sass::SyntaxError, 'Please provide a file in a folder: e.g. sprites/button.png'
|
7
|
+
end
|
8
|
+
dir, name, filename = $1, $2, $3
|
9
|
+
height = image_height(file).value
|
10
|
+
width = image_width(file).value
|
11
|
+
|
12
|
+
$lemonade_sprites ||= {}
|
13
|
+
sprite = $lemonade_sprites["#{ dir }/#{ name }"] ||= { :height => 0, :width => 0, :images => [] }
|
14
|
+
x, y = 0, sprite[:height]
|
15
|
+
sprite[:height] += height
|
16
|
+
sprite[:width] = width if width > sprite[:width]
|
17
|
+
position = background_position(x, y, add_x, add_y)
|
18
|
+
sprite[:images] << { :file => file.to_s.gsub('"', ''), :height => height, :width => width, :x => x, :y => y }
|
19
|
+
|
20
|
+
file = image_url(Sass::Script::String.new("#{ dir }#{ name }.png"))
|
21
|
+
Sass::Script::String.new("#{ file }#{ position }")
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def background_position(x, y, add_x, add_y)
|
27
|
+
y = -y
|
28
|
+
x += add_x.value if add_x
|
29
|
+
y += add_y.value if add_y
|
30
|
+
unless x == 0 and y == 0
|
31
|
+
" #{ x }#{ 'px' unless x == 0 } #{ y }#{ 'px' unless y == 0 }"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Lemonade::SassExtensions::Functions::Lemonade do
|
4
|
+
before :each do
|
5
|
+
@sass = Sass::Environment.new
|
6
|
+
FileUtils.cp_r File.dirname(__FILE__) + '/images', IMAGES_TMP_PATH
|
7
|
+
end
|
8
|
+
|
9
|
+
after :each do
|
10
|
+
FileUtils.rm_r IMAGES_TMP_PATH
|
11
|
+
$lemonade_sprites = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def evaluate(value)
|
15
|
+
Sass::Script::Parser.parse(value, 0, 0).perform(@sass).to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should return the sprite file name" do
|
19
|
+
evaluate('sprite-image("sprites/test-1.png")').should == "url('/sprites.png')"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should work in folders with dashes and underscores" do
|
23
|
+
evaluate('sprite-image("other_images/more-images/sprites/test-2.png")').should ==
|
24
|
+
"url('/other_images/more-images/sprites.png')"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should not work without any folder" do
|
28
|
+
lambda { evaluate('sprite-image("test.png")') }.should raise_exception(Sass::SyntaxError)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should set the background position" do
|
32
|
+
evaluate('sprite-image("sprites/test-1.png")').should == "url('/sprites.png')"
|
33
|
+
evaluate('sprite-image("sprites/test-2.png")').should == "url('/sprites.png') 0 -30px"
|
34
|
+
Lemonade::generate_sprites
|
35
|
+
File.exists?(IMAGES_TMP_PATH + '/sprites.png').should be_true
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should use the X position" do
|
39
|
+
evaluate('sprite-image("sprites/test-1.png", 5px, 0)').should == "url('/sprites.png') 5px 0"
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'lemonade'
|
4
|
+
require 'spec'
|
5
|
+
require 'spec/autorun'
|
6
|
+
|
7
|
+
IMAGES_TMP_PATH = File.dirname(__FILE__) + '/images-tmp'
|
8
|
+
Compass.configuration.images_path = IMAGES_TMP_PATH
|
9
|
+
|
10
|
+
Spec::Runner.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lemonade
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Nico Hagenburger
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-05-11 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 2
|
31
|
+
- 9
|
32
|
+
version: 1.2.9
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
description: "Generates sprites on the fly by using `background: sprite-image(\"sprites/logo.png\")`."
|
36
|
+
email: gems@hagenburger.net
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README.md
|
43
|
+
files:
|
44
|
+
- .document
|
45
|
+
- .gitignore
|
46
|
+
- MIT-LICENSE
|
47
|
+
- README.md
|
48
|
+
- Rakefile
|
49
|
+
- VERSION
|
50
|
+
- lemonade.gemspec
|
51
|
+
- lib/lemonade.rb
|
52
|
+
- lib/lemonade/lemonade.rb
|
53
|
+
- lib/lemonade/sass_extensions/functions/lemonade.rb
|
54
|
+
- spec/images/other_images/more-images/sprites/test-2.png
|
55
|
+
- spec/images/sprites/test-1.png
|
56
|
+
- spec/images/sprites/test-2.png
|
57
|
+
- spec/lemonade_spec.rb
|
58
|
+
- spec/spec.opts
|
59
|
+
- spec/spec_helper.rb
|
60
|
+
has_rdoc: true
|
61
|
+
homepage: http://github.com/hagenburger/lemonade
|
62
|
+
licenses: []
|
63
|
+
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options:
|
66
|
+
- --charset=UTF-8
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.3.7
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: On the fly sprite generator for Sass/Compass
|
92
|
+
test_files:
|
93
|
+
- spec/lemonade_spec.rb
|
94
|
+
- spec/spec_helper.rb
|