tests are green and config option added
This commit is contained in:
parent
a4861298a7
commit
c0a0b638b1
@ -1,7 +1,7 @@
|
|||||||
PATH
|
PATH
|
||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
compass (0.11.beta.2.03f4c23)
|
compass (0.11.beta.2.a486129)
|
||||||
chunky_png (~> 0.12.0)
|
chunky_png (~> 0.12.0)
|
||||||
sass (>= 3.1.0.alpha.218)
|
sass (>= 3.1.0.alpha.218)
|
||||||
|
|
||||||
|
@ -37,7 +37,8 @@ module Compass
|
|||||||
:line_comments,
|
:line_comments,
|
||||||
:color_output,
|
:color_output,
|
||||||
:preferred_syntax,
|
:preferred_syntax,
|
||||||
:disable_warnings
|
:disable_warnings,
|
||||||
|
:sprite_engine
|
||||||
].flatten
|
].flatten
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -128,6 +128,11 @@ module Compass
|
|||||||
def default_preferred_syntax
|
def default_preferred_syntax
|
||||||
:scss
|
:scss
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def default_sprite_engine
|
||||||
|
:chunky_png
|
||||||
|
end
|
||||||
|
|
||||||
# helper functions
|
# helper functions
|
||||||
|
|
||||||
def http_join(*segments)
|
def http_join(*segments)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
require 'compass/sass_extensions/sprites/image'
|
require 'compass/sass_extensions/sprites/image'
|
||||||
|
require 'compass/sass_extensions/sprites/engines/chunky_png_engine'
|
||||||
module Compass
|
module Compass
|
||||||
module SassExtensions
|
module SassExtensions
|
||||||
module Sprites
|
module Sprites
|
||||||
@ -12,21 +13,8 @@ module Compass
|
|||||||
new(sprites, path, name, context, kwargs)
|
new(sprites, path, name, context, kwargs)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def require_engine!
|
def require_engine!
|
||||||
begin
|
self.class.send(:include, eval("::Compass::SassExtensions::Sprites::#{modulize}Engine"))
|
||||||
require 'rmagick'
|
|
||||||
require 'compass/sass_extensions/sprites/engines/rmagick_engine'
|
|
||||||
self.class.send(:include, ::Compass::SassExtensions::Sprites::RmagickEngine)
|
|
||||||
rescue LoadError
|
|
||||||
require 'compass/sass_extensions/sprites/engines/chunky_png_engine'
|
|
||||||
begin
|
|
||||||
require 'oily_png'
|
|
||||||
rescue LoadError
|
|
||||||
require 'chunky_png'
|
|
||||||
end
|
|
||||||
self.class.send(:include, ::Compass::SassExtensions::Sprites::ChunkyPngEngine)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Changing this string will invalidate all previously generated sprite images.
|
# Changing this string will invalidate all previously generated sprite images.
|
||||||
@ -111,7 +99,6 @@ module Compass
|
|||||||
end
|
end
|
||||||
|
|
||||||
def generation_required?
|
def generation_required?
|
||||||
puts !File.exists?(filename) || outdated?
|
|
||||||
!File.exists?(filename) || outdated?
|
!File.exists?(filename) || outdated?
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -169,6 +156,13 @@ module Compass
|
|||||||
super
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def modulize
|
||||||
|
@modulize ||= Compass::configuration.sprite_engine.to_s.scan(/([^_.]+)/).flatten.map {|chunk| "#{chunk[0].chr.upcase}#{chunk[1..-1]}" }.join
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,14 @@
|
|||||||
|
begin
|
||||||
|
require 'oily_png'
|
||||||
|
rescue LoadError
|
||||||
|
require 'chunky_png'
|
||||||
|
end
|
||||||
|
|
||||||
module Compass
|
module Compass
|
||||||
module SassExtensions
|
module SassExtensions
|
||||||
module Sprites
|
module Sprites
|
||||||
module ChunkyPngEngine
|
module ChunkyPngEngine
|
||||||
|
|
||||||
# Returns a PNG object
|
# Returns a PNG object
|
||||||
def construct_sprite
|
def construct_sprite
|
||||||
#require_png_library!
|
#require_png_library!
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
module Compass
|
|
||||||
module SassExtensions
|
|
||||||
module Sprites
|
|
||||||
module RmagickEngine
|
|
||||||
class ::Magick::Image
|
|
||||||
alias :save :write
|
|
||||||
end
|
|
||||||
|
|
||||||
def composite_images(dest_image, src_image, x, y)
|
|
||||||
width = [src_image.columns + x, dest_image.columns].max
|
|
||||||
height = [src_image.rows + y, dest_image.rows].max
|
|
||||||
image = Magick::Image.new(width, height) {self.background_color = 'none'}
|
|
||||||
image.composite!(dest_image, 0, 0, Magick::CopyCompositeOp)
|
|
||||||
image.composite!(src_image, x, y, Magick::CopyCompositeOp)
|
|
||||||
image
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns a PNG object
|
|
||||||
def construct_sprite
|
|
||||||
output_png = Magick::Image.new(width, height)
|
|
||||||
output_png.background_color = 'none'
|
|
||||||
output_png.format = 'PNG24'
|
|
||||||
images.each do |image|
|
|
||||||
input_png = Magick::Image.read(image.file).first
|
|
||||||
if image.repeat == "no-repeat"
|
|
||||||
output_png = composite_images(output_png, input_png, image.left, image.top)
|
|
||||||
else
|
|
||||||
x = image.left - (image.left / image.width).ceil * image.width
|
|
||||||
while x < width do
|
|
||||||
output_png = composite_images(output_png, input_png, x, image.top)
|
|
||||||
#output_png.composite!(input_png, x, image.top, Magick::CopyCompositeOp)
|
|
||||||
x += image.width
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
output_png
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Reference in New Issue
Block a user