Grid image subcommand.
This commit is contained in:
parent
12dcccad5d
commit
8b5868ca00
@ -47,7 +47,7 @@ misc commands
|
||||
-------------
|
||||
|
||||
# Generate a background image that can be used to verify grid alignment
|
||||
compass grid-background W+GxH [path/to/image.png]
|
||||
compass grid-img W+GxH [path/to/grid.png]
|
||||
|
||||
# Emit the version of compass
|
||||
compass version
|
||||
|
@ -4,8 +4,65 @@ require 'compass/grid_builder'
|
||||
|
||||
module Compass
|
||||
module Commands
|
||||
module GridBackgroundOptionsParser
|
||||
def set_options(opts)
|
||||
banner = %Q{Usage: compass grid-img W+GxH [path/to/grid.png]
|
||||
|
||||
Description:
|
||||
Generates a background image that can be used to check grid alignment.
|
||||
|
||||
Height is optional and defaults to 20px
|
||||
|
||||
By default, the image generated will be named "grid.png"
|
||||
and be found in the images directory.
|
||||
|
||||
This command requires that you have both ImageMagick and RMagick installed.
|
||||
|
||||
Examples:
|
||||
|
||||
compass grid-img 40+10 # 40px column, 10px gutter, 20px height
|
||||
compass grid-img 40+20x28 # 40px column, 20px gutter, 28px height
|
||||
compass grid-img 60+20x28 images/wide_grid.png
|
||||
|
||||
Options:
|
||||
}
|
||||
opts.banner = banner
|
||||
|
||||
super
|
||||
end
|
||||
end
|
||||
class GenerateGridBackground < ProjectBase
|
||||
|
||||
include Actions
|
||||
|
||||
register :"grid-img"
|
||||
|
||||
class << self
|
||||
def option_parser(arguments)
|
||||
parser = Compass::Exec::CommandOptionParser.new(arguments)
|
||||
parser.extend(Compass::Exec::GlobalOptionsParser)
|
||||
parser.extend(GridBackgroundOptionsParser)
|
||||
end
|
||||
|
||||
def usage
|
||||
option_parser([]).to_s
|
||||
end
|
||||
|
||||
def description(command)
|
||||
"Generates a grid background image."
|
||||
end
|
||||
|
||||
def parse!(arguments)
|
||||
parser = option_parser(arguments)
|
||||
parser.parse!
|
||||
if arguments.size == 0
|
||||
raise OptionParser::ParseError, "Please specify the grid dimensions."
|
||||
end
|
||||
parser.options[:grid_dimensions] = arguments.shift
|
||||
parser.options[:grid_filename] = arguments.shift
|
||||
parser.options
|
||||
end
|
||||
end
|
||||
def initialize(working_path, options)
|
||||
super
|
||||
assert_project_directory_exists!
|
||||
@ -22,7 +79,8 @@ module Compass
|
||||
column_width = $1.to_i
|
||||
gutter_width = $2.to_i
|
||||
height = $3.to_i if $3
|
||||
unless GridBuilder.new(options.merge(:column_width => column_width, :gutter_width => gutter_width, :height => height, :output_path => projectize(project_images_subdirectory), :working_path => self.working_path)).generate!
|
||||
filename = options[:grid_filename] || projectize("#{project_images_subdirectory}/grid.png")
|
||||
unless GridBuilder.new(options.merge(:column_width => column_width, :gutter_width => gutter_width, :height => height, :filename => filename, :working_path => self.working_path)).generate!
|
||||
puts "ERROR: Some library dependencies appear to be missing."
|
||||
puts "Have you installed rmagick? If not, please run:"
|
||||
puts "sudo gem install rmagick"
|
||||
|
@ -16,21 +16,21 @@ module Compass
|
||||
rescue Exception => e
|
||||
end
|
||||
|
||||
attr_reader :column_width, :gutter_width, :output_path, :able_to_generate, :options
|
||||
attr_reader :column_width, :gutter_width, :filename, :able_to_generate, :options
|
||||
|
||||
# ==== Options
|
||||
# * <tt>options</tt>
|
||||
# * <tt>:column_width</tt> -- Width (in pixels) of current grid column
|
||||
# * <tt>:gutter_width</tt> -- Width (in pixels) of current grid gutter
|
||||
# * <tt>:height</tt> -- Height (in pixels) of a row
|
||||
# * <tt>:output_path</tt> -- Output path of grid.png file
|
||||
# * <tt>:filename</tt> -- Output path of grid.png file
|
||||
def initialize(options={})
|
||||
@able_to_generate = Magick::Long_version rescue false
|
||||
return unless @able_to_generate
|
||||
@column_width = options[:column_width]
|
||||
@gutter_width = options[:gutter_width]
|
||||
@height = options[:height] || 20
|
||||
@output_path = options[:output_path]
|
||||
@filename = options[:filename]
|
||||
@options = options
|
||||
end
|
||||
|
||||
@ -56,7 +56,6 @@ module Compass
|
||||
end
|
||||
end
|
||||
|
||||
filename = File.join(self.output_path, "grid.png")
|
||||
if File.exists?(filename)
|
||||
if options[:force]
|
||||
overwrite = true
|
||||
@ -65,9 +64,13 @@ module Compass
|
||||
raise Compass::FilesystemConflict.new(msg)
|
||||
end
|
||||
end
|
||||
directory self.output_path
|
||||
directory File.dirname(filename)
|
||||
logger.record((overwrite ? :overwrite : :create), basename(filename))
|
||||
unless options[:dry_run]
|
||||
rvg.draw.write(filename)
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user