Allow specification of a height for the grid image.

This commit is contained in:
Chris Eppstein 2009-09-01 20:20:53 -07:00
parent cb45b6d438
commit 54a459f28e
3 changed files with 18 additions and 12 deletions

View File

@ -9,11 +9,20 @@ module Compass
def initialize(working_path, options)
super
assert_project_directory_exists!
Compass.add_configuration(options)
end
def perform
column_width, gutter_width = options[:grid_dimensions].split(/\+/).map{|d| d.to_i}
unless GridBuilder.new(options.merge(:column_width => column_width, :gutter_width => gutter_width, :output_path => projectize(project_images_subdirectory), :working_path => self.working_path)).generate!
unless options[:grid_dimensions] =~ /^(\d+)\+(\d+)(?:x(\d+))?$/
puts "ERROR: '#{options[:grid_dimensions]}' is not valid."
puts "Dimensions should be specified like: 30+10x20"
puts "where 30 is the column width, 10 is the gutter width, and 20 is the (optional) height."
return
end
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!
puts "ERROR: Some library dependencies appear to be missing."
puts "Have you installed rmagick? If not, please run:"
puts "sudo gem install rmagick"

View File

@ -124,13 +124,9 @@ END
end
opts.on('--grid-img [DIMENSIONS]', 'Generate a background image to test grid alignment.',
' Dimension is given as <column_width>+<gutter_width>.',
' Defaults to 30+10.') do |dimensions|
' Dimension is given as <column_width>+<gutter_width>x<height>.',
' Defaults to 30+10x20. Height is optional.') do |dimensions|
self.options[:grid_dimensions] = dimensions || "30+10"
unless self.options[:grid_dimensions] =~ /^\d+\+\d+$/
puts "Please enter your dimensions as <column_width>+<gutter_width>. E.g. 20+5 or 30+10."
exit
end
self.options[:command] = :generate_grid_background
end

View File

@ -22,12 +22,14 @@ module Compass
# * <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
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]
@options = options
end
@ -40,18 +42,17 @@ module Compass
def generate!
return false unless self.able_to_generate
total_width = self.column_width + self.gutter_width
height = 20
RVG::dpi = 100
rvg = RVG.new((total_width.to_f/RVG::dpi).in, (height.to_f/RVG::dpi).in).viewbox(0, 0, total_width, height) do |canvas|
rvg = RVG.new((total_width.to_f/RVG::dpi).in, (@height.to_f/RVG::dpi).in).viewbox(0, 0, total_width, @height) do |canvas|
canvas.background_fill = 'white'
canvas.g do |column|
column.rect(self.column_width, height).styles(:fill => "#e8effb")
column.rect(self.column_width, @height).styles(:fill => "#e8effb")
end
canvas.g do |baseline|
baseline.line(0, (height - 1), total_width, (height- 1)).styles(:fill => "#e9e9e9")
baseline.line(0, (@height - 1), total_width, (@height- 1)).styles(:fill => "#e9e9e9")
end
end