diff --git a/COMMAND_LINE.markdown b/COMMAND_LINE.markdown
index 591a093f..540ee905 100644
--- a/COMMAND_LINE.markdown
+++ b/COMMAND_LINE.markdown
@@ -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
diff --git a/lib/compass/commands/generate_grid_background.rb b/lib/compass/commands/generate_grid_background.rb
index 646c8d0a..06c2bc58 100644
--- a/lib/compass/commands/generate_grid_background.rb
+++ b/lib/compass/commands/generate_grid_background.rb
@@ -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"
@@ -30,4 +88,4 @@ module Compass
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/compass/grid_builder.rb b/lib/compass/grid_builder.rb
index 8112b1bc..2b5c5d34 100644
--- a/lib/compass/grid_builder.rb
+++ b/lib/compass/grid_builder.rb
@@ -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
# * options
# * :column_width -- Width (in pixels) of current grid column
# * :gutter_width -- Width (in pixels) of current grid gutter
# * :height -- Height (in pixels) of a row
- # * :output_path -- Output path of grid.png file
+ # * :filename -- 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))
- rvg.draw.write(filename)
+ unless options[:dry_run]
+ rvg.draw.write(filename)
+ else
+ true
+ end
end
end
-end
\ No newline at end of file
+end