Class: Compass::Commands::GenerateGridBackground

Inherits:
ProjectBase show all
Includes:
Actions
Defined in:
lib/compass/commands/generate_grid_background.rb

Instance Attribute Summary

Attributes included from Actions

#logger

Attributes inherited from ProjectBase

#options, #project_name

Attributes inherited from Base

#options, #working_path

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Actions

#basename, #copy, #directory, #log_action, #process_erb, #relativize, #remove, #separate, #strip_trailing_separator, #write_file

Methods inherited from ProjectBase

#execute

Methods inherited from Base

#execute, #failed!, register, #successful?

Constructor Details

#initialize(working_path, options) ⇒ GenerateGridBackground

Returns a new instance of GenerateGridBackground.



69
70
71
72
73
# File 'lib/compass/commands/generate_grid_background.rb', line 69

def initialize(working_path, options)
  super
  assert_project_directory_exists!
  Compass.add_configuration(options, 'command_line')
end

Class Method Details

.description(command) ⇒ Object



54
55
56
# File 'lib/compass/commands/generate_grid_background.rb', line 54

def description(command)
  "Generates a grid background image."
end

.option_parser(arguments) ⇒ Object



44
45
46
47
48
# File 'lib/compass/commands/generate_grid_background.rb', line 44

def option_parser(arguments)
  parser = Compass::Exec::CommandOptionParser.new(arguments)
  parser.extend(Compass::Exec::GlobalOptionsParser)
  parser.extend(GridBackgroundOptionsParser)
end

.parse!(arguments) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# File 'lib/compass/commands/generate_grid_background.rb', line 58

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

.usageObject



50
51
52
# File 'lib/compass/commands/generate_grid_background.rb', line 50

def usage
  option_parser([]).to_s
end

Instance Method Details

#performObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/compass/commands/generate_grid_background.rb', line 75

def perform
  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
  logger.yellow do
    $stderr.puts "Unless you need to check layouts in legacy browsers, it's preferable"
    $stderr.puts "to use the pure CSS3-based grid background mixin:"
    $stderr.puts
    $stderr.puts "http://compass-style.org/reference/compass/layout/grid_background/"
  end
  column_width = $1.to_i
  gutter_width = $2.to_i
  height = $3.to_i if $3
  filename = options[:grid_filename] || projectize("#{project_images_subdirectory}/grid.png")
  GridBuilder.new(options.merge(:column_width => column_width, :gutter_width => gutter_width, :height => height, :filename => filename, :working_path => self.working_path)).generate!
end