Rename Lemonade to Compass::Sprites
This commit is contained in:
parent
a2f1026659
commit
757fed8888
@ -15,8 +15,6 @@ module Compass
|
|||||||
module_function :base_directory, :lib_directory
|
module_function :base_directory, :lib_directory
|
||||||
end
|
end
|
||||||
|
|
||||||
%w(configuration frameworks app_integration actions compiler).each do |lib|
|
%w(configuration frameworks app_integration actions compiler sprites).each do |lib|
|
||||||
require "compass/#{lib}"
|
require "compass/#{lib}"
|
||||||
end
|
end
|
||||||
|
|
||||||
require "lemonade"
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
require 'chunky_png'
|
require 'chunky_png'
|
||||||
require 'lemonade/sprite_info.rb'
|
require 'compass/sprites/sprite_info'
|
||||||
|
|
||||||
module Lemonade
|
module Compass::Sprites
|
||||||
@@sprites = {}
|
@@sprites = {}
|
||||||
@@sprites_path = nil
|
@@sprites_path = nil
|
||||||
@@images_path = nil
|
@@images_path = nil
|
||||||
@ -45,8 +45,8 @@ module Lemonade
|
|||||||
def extend_sass!
|
def extend_sass!
|
||||||
require 'sass'
|
require 'sass'
|
||||||
require 'sass/plugin'
|
require 'sass/plugin'
|
||||||
require File.expand_path('../lemonade/sass_functions', __FILE__)
|
require 'compass/sprites/sass_functions'
|
||||||
require File.expand_path('../lemonade/sass_extension', __FILE__)
|
require 'compass/sprites/sass_extension'
|
||||||
end
|
end
|
||||||
|
|
||||||
def sprite_changed?(sprite_name, sprite)
|
def sprite_changed?(sprite_name, sprite)
|
||||||
@ -68,7 +68,7 @@ module Lemonade
|
|||||||
private
|
private
|
||||||
|
|
||||||
def sprite_info_file(sprite_name)
|
def sprite_info_file(sprite_name)
|
||||||
File.join(Lemonade.images_path, "#{sprite_name}.sprite_info.yml")
|
File.join(Compass::Sprites.images_path, "#{sprite_name}.sprite_info.yml")
|
||||||
end
|
end
|
||||||
|
|
||||||
def timestamps(sprite)
|
def timestamps(sprite)
|
||||||
@ -108,7 +108,7 @@ module Lemonade
|
|||||||
y = sprite_item[:y].value
|
y = sprite_item[:y].value
|
||||||
sprite_image.replace sprite_item_image, x, y
|
sprite_image.replace sprite_item_image, x, y
|
||||||
end
|
end
|
||||||
sprite_image.save File.join(Lemonade.images_path, sprite[:file])
|
sprite_image.save File.join(Compass::Sprites.images_path, sprite[:file])
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -119,9 +119,9 @@ end
|
|||||||
if defined?(ActiveSupport) and Sass::Util.has?(:public_method, ActiveSupport, :on_load)
|
if defined?(ActiveSupport) and Sass::Util.has?(:public_method, ActiveSupport, :on_load)
|
||||||
# Rails 3.0
|
# Rails 3.0
|
||||||
ActiveSupport.on_load :before_initialize do
|
ActiveSupport.on_load :before_initialize do
|
||||||
Lemonade.extend_sass!
|
Compass::Sprites.extend_sass!
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
Lemonade.extend_sass!
|
Compass::Sprites.extend_sass!
|
||||||
end
|
end
|
||||||
|
|
@ -4,12 +4,12 @@ module Sass
|
|||||||
|
|
||||||
class RootNode < Node
|
class RootNode < Node
|
||||||
|
|
||||||
alias_method :render_without_lemonade, :render
|
alias_method :render_without_sprites, :render
|
||||||
def render
|
def render
|
||||||
if result = render_without_lemonade
|
if result = render_without_sprites
|
||||||
Lemonade.generate_sprites
|
Compass::Sprites.generate_sprites
|
||||||
result = ERB.new(result).result(binding)
|
result = ERB.new(result).result(binding)
|
||||||
Lemonade.reset
|
Compass::Sprites.reset
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -44,20 +44,20 @@ module Sass::Script::Functions
|
|||||||
private
|
private
|
||||||
|
|
||||||
def sprite_file_list_from_folder(folder)
|
def sprite_file_list_from_folder(folder)
|
||||||
dir = File.join(Lemonade.sprites_path, folder.value)
|
dir = File.join(Compass::Sprites.sprites_path, folder.value)
|
||||||
Dir.glob(File.join(dir, '*.png')).sort
|
Dir.glob(File.join(dir, '*.png')).sort
|
||||||
end
|
end
|
||||||
|
|
||||||
def sprite_url_and_position(file, position_x = nil, position_y_shift = nil, margin_top_or_both = nil, margin_bottom = nil)
|
def sprite_url_and_position(file, position_x = nil, position_y_shift = nil, margin_top_or_both = nil, margin_bottom = nil)
|
||||||
dir, name, basename = extract_names(file, :check_file => true)
|
dir, name, basename = extract_names(file, :check_file => true)
|
||||||
filestr = File.join(Lemonade.sprites_path, file.value)
|
filestr = File.join(Compass::Sprites.sprites_path, file.value)
|
||||||
|
|
||||||
sprite_file = "#{dir}#{name}.png"
|
sprite_file = "#{dir}#{name}.png"
|
||||||
sprite = sprite_for(sprite_file)
|
sprite = sprite_for(sprite_file)
|
||||||
sprite_item = image_for(sprite, filestr, position_x, position_y_shift, margin_top_or_both, margin_bottom)
|
sprite_item = image_for(sprite, filestr, position_x, position_y_shift, margin_top_or_both, margin_bottom)
|
||||||
|
|
||||||
# Create a temporary destination file so compass doesn't complain about a missing image
|
# Create a temporary destination file so compass doesn't complain about a missing image
|
||||||
FileUtils.touch File.join(Lemonade.images_path, sprite_file) unless File.exists?(File.join(Lemonade.images_path, sprite_file))
|
FileUtils.touch File.join(Compass::Sprites.images_path, sprite_file) unless File.exists?(File.join(Compass::Sprites.images_path, sprite_file))
|
||||||
|
|
||||||
[sprite, sprite_item]
|
[sprite, sprite_item]
|
||||||
end
|
end
|
||||||
@ -76,7 +76,7 @@ private
|
|||||||
|
|
||||||
def sprite_for(file)
|
def sprite_for(file)
|
||||||
file = "#{file}.png" unless file =~ /\.png$/
|
file = "#{file}.png" unless file =~ /\.png$/
|
||||||
Lemonade.sprites[file] ||= {
|
Compass::Sprites.sprites[file] ||= {
|
||||||
:file => "#{file}",
|
:file => "#{file}",
|
||||||
:height => 0,
|
:height => 0,
|
||||||
:width => 0,
|
:width => 0,
|
||||||
@ -111,7 +111,7 @@ private
|
|||||||
end
|
end
|
||||||
image
|
image
|
||||||
rescue Errno::ENOENT
|
rescue Errno::ENOENT
|
||||||
raise Sass::SyntaxError, "#{file} does not exist in sprites_dir #{Lemonade.sprites_path}"
|
raise Sass::SyntaxError, "#{file} does not exist in sprites_dir #{Compass::Sprites.sprites_path}"
|
||||||
rescue ChunkyPNG::SignatureMismatch
|
rescue ChunkyPNG::SignatureMismatch
|
||||||
raise Sass::SyntaxError, "#{file} is not a recognized png file, can't use for sprite creation"
|
raise Sass::SyntaxError, "#{file} is not a recognized png file, can't use for sprite creation"
|
||||||
end
|
end
|
@ -43,7 +43,7 @@ module Sass::Script
|
|||||||
if @sprite_item[:index] == 0 and (@position_y_shift.nil? or @position_y_shift.value == 0)
|
if @sprite_item[:index] == 0 and (@position_y_shift.nil? or @position_y_shift.value == 0)
|
||||||
"#{x.inspect} 0"
|
"#{x.inspect} 0"
|
||||||
else
|
else
|
||||||
expression = "Lemonade.sprites['#{@sprite[:file]}'][:images][#{@sprite_item[:index]}][:y].unary_minus"
|
expression = "Compass::Sprites.sprites['#{@sprite[:file]}'][:images][#{@sprite_item[:index]}][:y].unary_minus"
|
||||||
expression << ".plus(Sass::Script::Number.new(#{@position_y_shift.value}, ['px']))" if @position_y_shift
|
expression << ".plus(Sass::Script::Number.new(#{@position_y_shift.value}, ['px']))" if @position_y_shift
|
||||||
"#{x.inspect} <%= #{expression} %>"
|
"#{x.inspect} <%= #{expression} %>"
|
||||||
end
|
end
|
@ -1,3 +0,0 @@
|
|||||||
module Lemonade
|
|
||||||
Version = "1.0.0.beta.1"
|
|
||||||
end
|
|
@ -1,6 +1,6 @@
|
|||||||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
||||||
|
|
||||||
describe Lemonade do
|
describe Compass::Sprites do
|
||||||
|
|
||||||
before :each do
|
before :each do
|
||||||
@sprite = {
|
@sprite = {
|
||||||
@ -13,14 +13,14 @@ describe Lemonade do
|
|||||||
|
|
||||||
@file = ""
|
@file = ""
|
||||||
File.stub!(:read => @file)
|
File.stub!(:read => @file)
|
||||||
Lemonade.stub(:images_path).and_return('image_path')
|
Compass::Sprites.stub(:images_path).and_return('image_path')
|
||||||
File.stub!(:ctime => Time.parse('2010-01-01 12:00'))
|
File.stub!(:ctime => Time.parse('2010-01-01 12:00'))
|
||||||
end
|
end
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|
||||||
describe '#remember_sprite_info' do
|
describe '#remember_sprite_info' do
|
||||||
subject { Lemonade }
|
subject { Compass::Sprites }
|
||||||
|
|
||||||
it 'should save sprite info into a file' do
|
it 'should save sprite info into a file' do
|
||||||
File.should_receive(:open).with(File.join('image_path', 'the_sprite.sprite_info.yml'), 'w').and_yield(@file)
|
File.should_receive(:open).with(File.join('image_path', 'the_sprite.sprite_info.yml'), 'w').and_yield(@file)
|
||||||
@ -32,7 +32,7 @@ describe Lemonade do
|
|||||||
###
|
###
|
||||||
|
|
||||||
describe '#sprite_changed?' do
|
describe '#sprite_changed?' do
|
||||||
subject { Lemonade }
|
subject { Compass::Sprites }
|
||||||
|
|
||||||
it 'should be false if nothing changed' do
|
it 'should be false if nothing changed' do
|
||||||
File.should_receive(:open).and_yield(@file)
|
File.should_receive(:open).and_yield(@file)
|
||||||
|
@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|||||||
describe Sass::Script::Functions do
|
describe Sass::Script::Functions do
|
||||||
|
|
||||||
before :each do
|
before :each do
|
||||||
Lemonade.reset
|
Compass::Sprites.reset
|
||||||
FileUtils.cp_r File.dirname(__FILE__) + '/images', IMAGES_TMP_PATH
|
FileUtils.cp_r File.dirname(__FILE__) + '/images', IMAGES_TMP_PATH
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ require 'spec'
|
|||||||
require 'spec/autorun'
|
require 'spec/autorun'
|
||||||
|
|
||||||
IMAGES_TMP_PATH = File.join(File.dirname(__FILE__), 'images-tmp')
|
IMAGES_TMP_PATH = File.join(File.dirname(__FILE__), 'images-tmp')
|
||||||
Lemonade.images_path = IMAGES_TMP_PATH
|
Compass::Sprites.images_path = IMAGES_TMP_PATH
|
||||||
|
|
||||||
Spec::Runner.configure do |config|
|
Spec::Runner.configure do |config|
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ describe Sass::Script::SpriteInfo do
|
|||||||
sprite_item = { :y => Sass::Script::Number.new(20, ['px']), :index => 1 }
|
sprite_item = { :y => Sass::Script::Number.new(20, ['px']), :index => 1 }
|
||||||
x = Sass::Script::Number.new(10, ['px'])
|
x = Sass::Script::Number.new(10, ['px'])
|
||||||
sprite_info(:position, sprite, sprite_item, x).should ==
|
sprite_info(:position, sprite, sprite_item, x).should ==
|
||||||
"10px <%= Lemonade.sprites['sprites.png'][:images][1][:y].unary_minus %>"
|
"10px <%= Compass::Sprites.sprites['sprites.png'][:images][1][:y].unary_minus %>"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should output the position with y shift" do
|
it "should output the position with y shift" do
|
||||||
@ -29,7 +29,7 @@ describe Sass::Script::SpriteInfo do
|
|||||||
x = Sass::Script::Number.new(10, ['px'])
|
x = Sass::Script::Number.new(10, ['px'])
|
||||||
y_shift = Sass::Script::Number.new(3, ['px'])
|
y_shift = Sass::Script::Number.new(3, ['px'])
|
||||||
sprite_info(:position, sprite, sprite_item, x, y_shift).should ==
|
sprite_info(:position, sprite, sprite_item, x, y_shift).should ==
|
||||||
"10px <%= Lemonade.sprites['sprites.png'][:images][1][:y].unary_minus.plus(Sass::Script::Number.new(3, ['px'])) %>"
|
"10px <%= Compass::Sprites.sprites['sprites.png'][:images][1][:y].unary_minus.plus(Sass::Script::Number.new(3, ['px'])) %>"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should output the position with percentage" do
|
it "should output the position with percentage" do
|
||||||
@ -37,7 +37,7 @@ describe Sass::Script::SpriteInfo do
|
|||||||
sprite_item = { :y => Sass::Script::Number.new(20, ['px']), :index => 2 }
|
sprite_item = { :y => Sass::Script::Number.new(20, ['px']), :index => 2 }
|
||||||
x = Sass::Script::Number.new(100, ['%'])
|
x = Sass::Script::Number.new(100, ['%'])
|
||||||
sprite_info(:position, sprite, sprite_item, x).should ==
|
sprite_info(:position, sprite, sprite_item, x).should ==
|
||||||
"100% <%= Lemonade.sprites['sprites.png'][:images][2][:y].unary_minus %>"
|
"100% <%= Compass::Sprites.sprites['sprites.png'][:images][2][:y].unary_minus %>"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should output the url" do
|
it "should output the url" do
|
||||||
|
Loading…
Reference in New Issue
Block a user