Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
58 lines (48 sloc) 1.52 KB
# encoding: utf-8
require 'erb'
require 'fileutils'
#
# Get all sizes already generated by Iconic
#
sizes = []
Dir['iconic/raster/black/article_*'].each do |icon|
names = File.basename(icon, File.extname(icon)).split('_')
sizes << names.last
end
#
# Define all color / size tasks to generation
#
Dir['iconic/raster/*'].each do |color|
color = File.basename(color)
namespace color do
sizes.each do |size|
desc "Generate sprite-sheet for #{color} icons with size #{size}"
task size do
size = size.to_i
@output = ENV['output'] || "assets/iconic-#{color}"
# Generate Spritesheet
files = Dir["iconic/raster/#{color}/*#{size}.png"]
`montage #{files.join(' ')} -tile x1 -geometry #{size}x#{size}+0+0 -background none #{@output}.png`
# If has pngnq, compress the output
unless `which pngnq`.empty?
`pngnq -f #{@output}.png`
File.unlink("#{@output}.png")
FileUtils.mv("#{@output}-nq8.png", "#{@output}.png")
end
# Generate CSS
rcss = ERB.new(open("templates/#{ENV['template'] || 'default.css.erb'}").read)
# @ie6 = defined? ENV['ie6']
@color = color
@size = size
@icons = files.collect do |f|
parts = File.basename(f, File.extname(f)).split('_')
parts.pop
parts.join('-')
end
@date = Time.now.strftime('%Y-%m-%d')
css = rcss.result(binding)
File.open("#{@output}.css", "w+") {|f| f.write(css) }
end
end
end
end