From 6a44d58b7c64d669f098b85eb1bfbab78da3c6f0 Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Sun, 12 Sep 2010 14:58:07 -0700 Subject: [PATCH] Rename Lemonade to Compass::Sprites --- lib/compass.rb | 4 +--- lib/{lemonade.rb => compass/sprites.rb} | 16 ++++++++-------- .../sprites}/sass_extension.rb | 8 ++++---- .../sprites}/sass_functions.rb | 10 +++++----- lib/{lemonade => compass/sprites}/sprite_info.rb | 2 +- lib/lemonade/version.rb | 3 --- spec/lemonade_spec.rb | 8 ++++---- spec/sass_functions_spec.rb | 2 +- spec/spec_helper.rb | 2 +- spec/sprite_info_spec.rb | 6 +++--- 10 files changed, 28 insertions(+), 33 deletions(-) rename lib/{lemonade.rb => compass/sprites.rb} (88%) rename lib/{lemonade => compass/sprites}/sass_extension.rb (52%) rename lib/{lemonade => compass/sprites}/sass_functions.rb (92%) rename lib/{lemonade => compass/sprites}/sprite_info.rb (91%) delete mode 100644 lib/lemonade/version.rb diff --git a/lib/compass.rb b/lib/compass.rb index 2141806e..f9375ba0 100644 --- a/lib/compass.rb +++ b/lib/compass.rb @@ -15,8 +15,6 @@ module Compass module_function :base_directory, :lib_directory 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}" end - -require "lemonade" diff --git a/lib/lemonade.rb b/lib/compass/sprites.rb similarity index 88% rename from lib/lemonade.rb rename to lib/compass/sprites.rb index 8dbe971d..6db3135f 100644 --- a/lib/lemonade.rb +++ b/lib/compass/sprites.rb @@ -1,7 +1,7 @@ require 'chunky_png' -require 'lemonade/sprite_info.rb' +require 'compass/sprites/sprite_info' -module Lemonade +module Compass::Sprites @@sprites = {} @@sprites_path = nil @@images_path = nil @@ -45,8 +45,8 @@ module Lemonade def extend_sass! require 'sass' require 'sass/plugin' - require File.expand_path('../lemonade/sass_functions', __FILE__) - require File.expand_path('../lemonade/sass_extension', __FILE__) + require 'compass/sprites/sass_functions' + require 'compass/sprites/sass_extension' end def sprite_changed?(sprite_name, sprite) @@ -68,7 +68,7 @@ module Lemonade private 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 def timestamps(sprite) @@ -108,7 +108,7 @@ module Lemonade y = sprite_item[:y].value sprite_image.replace sprite_item_image, x, y end - sprite_image.save File.join(Lemonade.images_path, sprite[:file]) + sprite_image.save File.join(Compass::Sprites.images_path, sprite[:file]) end end @@ -119,9 +119,9 @@ end if defined?(ActiveSupport) and Sass::Util.has?(:public_method, ActiveSupport, :on_load) # Rails 3.0 ActiveSupport.on_load :before_initialize do - Lemonade.extend_sass! + Compass::Sprites.extend_sass! end else - Lemonade.extend_sass! + Compass::Sprites.extend_sass! end diff --git a/lib/lemonade/sass_extension.rb b/lib/compass/sprites/sass_extension.rb similarity index 52% rename from lib/lemonade/sass_extension.rb rename to lib/compass/sprites/sass_extension.rb index 1854345a..16153756 100644 --- a/lib/lemonade/sass_extension.rb +++ b/lib/compass/sprites/sass_extension.rb @@ -4,12 +4,12 @@ module Sass class RootNode < Node - alias_method :render_without_lemonade, :render + alias_method :render_without_sprites, :render def render - if result = render_without_lemonade - Lemonade.generate_sprites + if result = render_without_sprites + Compass::Sprites.generate_sprites result = ERB.new(result).result(binding) - Lemonade.reset + Compass::Sprites.reset return result end end diff --git a/lib/lemonade/sass_functions.rb b/lib/compass/sprites/sass_functions.rb similarity index 92% rename from lib/lemonade/sass_functions.rb rename to lib/compass/sprites/sass_functions.rb index d883f667..e1b819b3 100644 --- a/lib/lemonade/sass_functions.rb +++ b/lib/compass/sprites/sass_functions.rb @@ -44,20 +44,20 @@ module Sass::Script::Functions private 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 end 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) - filestr = File.join(Lemonade.sprites_path, file.value) + filestr = File.join(Compass::Sprites.sprites_path, file.value) sprite_file = "#{dir}#{name}.png" sprite = sprite_for(sprite_file) 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 - 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] end @@ -76,7 +76,7 @@ private def sprite_for(file) file = "#{file}.png" unless file =~ /\.png$/ - Lemonade.sprites[file] ||= { + Compass::Sprites.sprites[file] ||= { :file => "#{file}", :height => 0, :width => 0, @@ -111,7 +111,7 @@ private end image 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 raise Sass::SyntaxError, "#{file} is not a recognized png file, can't use for sprite creation" end diff --git a/lib/lemonade/sprite_info.rb b/lib/compass/sprites/sprite_info.rb similarity index 91% rename from lib/lemonade/sprite_info.rb rename to lib/compass/sprites/sprite_info.rb index 442f7c80..76d32517 100644 --- a/lib/lemonade/sprite_info.rb +++ b/lib/compass/sprites/sprite_info.rb @@ -43,7 +43,7 @@ module Sass::Script if @sprite_item[:index] == 0 and (@position_y_shift.nil? or @position_y_shift.value == 0) "#{x.inspect} 0" 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 "#{x.inspect} <%= #{expression} %>" end diff --git a/lib/lemonade/version.rb b/lib/lemonade/version.rb deleted file mode 100644 index 0b19c534..00000000 --- a/lib/lemonade/version.rb +++ /dev/null @@ -1,3 +0,0 @@ -module Lemonade - Version = "1.0.0.beta.1" -end diff --git a/spec/lemonade_spec.rb b/spec/lemonade_spec.rb index 4665a134..fbcf141b 100644 --- a/spec/lemonade_spec.rb +++ b/spec/lemonade_spec.rb @@ -1,6 +1,6 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper') -describe Lemonade do +describe Compass::Sprites do before :each do @sprite = { @@ -13,14 +13,14 @@ describe Lemonade do @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')) end ### describe '#remember_sprite_info' do - subject { Lemonade } + subject { Compass::Sprites } 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) @@ -32,7 +32,7 @@ describe Lemonade do ### describe '#sprite_changed?' do - subject { Lemonade } + subject { Compass::Sprites } it 'should be false if nothing changed' do File.should_receive(:open).and_yield(@file) diff --git a/spec/sass_functions_spec.rb b/spec/sass_functions_spec.rb index a0b8b78e..136daaf0 100644 --- a/spec/sass_functions_spec.rb +++ b/spec/sass_functions_spec.rb @@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe Sass::Script::Functions do before :each do - Lemonade.reset + Compass::Sprites.reset FileUtils.cp_r File.dirname(__FILE__) + '/images', IMAGES_TMP_PATH end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 410abc33..a07f52fb 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,7 +7,7 @@ require 'spec' require 'spec/autorun' 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| diff --git a/spec/sprite_info_spec.rb b/spec/sprite_info_spec.rb index 3b51f291..726b60b5 100644 --- a/spec/sprite_info_spec.rb +++ b/spec/sprite_info_spec.rb @@ -20,7 +20,7 @@ describe Sass::Script::SpriteInfo do sprite_item = { :y => Sass::Script::Number.new(20, ['px']), :index => 1 } x = Sass::Script::Number.new(10, ['px']) 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 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']) y_shift = Sass::Script::Number.new(3, ['px']) 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 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 } x = Sass::Script::Number.new(100, ['%']) 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 it "should output the url" do