Generate a grid background image with the --grid-img command line option.
This commit is contained in:
parent
63de13debd
commit
43fc3be14b
27
lib/compass/commands/generate_grid_background.rb
Normal file
27
lib/compass/commands/generate_grid_background.rb
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
require File.join(File.dirname(__FILE__), 'project_base')
|
||||||
|
require File.join(File.dirname(__FILE__), 'update_project')
|
||||||
|
require File.join(File.dirname(__FILE__), '..', 'grid_builder')
|
||||||
|
|
||||||
|
module Compass
|
||||||
|
module Commands
|
||||||
|
class GenerateGridBackground < ProjectBase
|
||||||
|
include Actions
|
||||||
|
def initialize(working_path, options)
|
||||||
|
super
|
||||||
|
assert_project_directory_exists!
|
||||||
|
end
|
||||||
|
|
||||||
|
def perform
|
||||||
|
read_project_configuration
|
||||||
|
Compass.configuration.set_maybe(options)
|
||||||
|
Compass.configuration.set_defaults!
|
||||||
|
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!
|
||||||
|
puts "ERROR: Some library dependencies appear to be missing."
|
||||||
|
puts "Have you installed rmagick? If not, please run:"
|
||||||
|
puts "sudo gem install rmagick"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -33,6 +33,10 @@ module Compass
|
|||||||
Compass.configuration.sass_dir
|
Compass.configuration.sass_dir
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def project_images_subdirectory
|
||||||
|
Compass.configuration.images_dir
|
||||||
|
end
|
||||||
|
|
||||||
# Read the configuration file for this project
|
# Read the configuration file for this project
|
||||||
def read_project_configuration
|
def read_project_configuration
|
||||||
if File.exists?(projectize('config.rb'))
|
if File.exists?(projectize('config.rb'))
|
||||||
|
@ -73,6 +73,10 @@ module Compass
|
|||||||
"stylesheets"
|
"stylesheets"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def default_images_dir
|
||||||
|
"images"
|
||||||
|
end
|
||||||
|
|
||||||
def default_output_style
|
def default_output_style
|
||||||
if environment == :development
|
if environment == :development
|
||||||
:expanded
|
:expanded
|
||||||
|
@ -170,6 +170,16 @@ END
|
|||||||
opts.on_tail("-v", "--version", "Print version") do
|
opts.on_tail("-v", "--version", "Print version") do
|
||||||
self.options[:command] = :print_version
|
self.options[:command] = :print_version
|
||||||
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|
|
||||||
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def do_command(command)
|
def do_command(command)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
# This file came from the Blueprint Project
|
||||||
begin
|
begin
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
gem 'rmagick'
|
gem 'rmagick'
|
||||||
@ -5,15 +6,17 @@ begin
|
|||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
end
|
end
|
||||||
|
|
||||||
module Blueprint
|
module Compass
|
||||||
# Uses ImageMagick and RMagick to generate grid.png file
|
# Uses ImageMagick and RMagick to generate grid.png file
|
||||||
class GridBuilder
|
class GridBuilder
|
||||||
|
include Actions
|
||||||
|
|
||||||
begin
|
begin
|
||||||
include Magick
|
include Magick
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :column_width, :gutter_width, :output_path, :able_to_generate
|
attr_reader :column_width, :gutter_width, :output_path, :able_to_generate, :options
|
||||||
|
|
||||||
# ==== Options
|
# ==== Options
|
||||||
# * <tt>options</tt>
|
# * <tt>options</tt>
|
||||||
@ -23,9 +26,14 @@ module Blueprint
|
|||||||
def initialize(options={})
|
def initialize(options={})
|
||||||
@able_to_generate = Magick::Long_version rescue false
|
@able_to_generate = Magick::Long_version rescue false
|
||||||
return unless @able_to_generate
|
return unless @able_to_generate
|
||||||
@column_width = options[:column_width] || Blueprint::COLUMN_WIDTH
|
@column_width = options[:column_width]
|
||||||
@gutter_width = options[:gutter_width] || Blueprint::GUTTER_WIDTH
|
@gutter_width = options[:gutter_width]
|
||||||
@output_path = options[:output_path] || Blueprint::SOURCE_PATH
|
@output_path = options[:output_path]
|
||||||
|
@options = options
|
||||||
|
end
|
||||||
|
|
||||||
|
def working_path
|
||||||
|
options[:working_path]
|
||||||
end
|
end
|
||||||
|
|
||||||
# generates (overwriting if necessary) grid.png image to be tiled in background
|
# generates (overwriting if necessary) grid.png image to be tiled in background
|
||||||
@ -46,9 +54,19 @@ module Blueprint
|
|||||||
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
|
||||||
end
|
end
|
||||||
|
|
||||||
FileUtils.mkdir self.output_path unless File.exists? self.output_path
|
filename = File.join(self.output_path, "grid.png")
|
||||||
rvg.draw.write(File.join(self.output_path, "grid.png"))
|
if File.exists?(filename)
|
||||||
|
if options[:force]
|
||||||
|
overwrite = true
|
||||||
|
else
|
||||||
|
msg = "#{filename} already exists. Overwrite with --force."
|
||||||
|
raise Compass::FilesystemConflict.new(msg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
directory self.output_path
|
||||||
|
logger.record((overwrite ? :overwrite : :create), basename(filename))
|
||||||
|
rvg.draw.write(filename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user