Class: Compass::GridBuilder

Inherits:
PNG
  • Object
show all
Includes:
Actions
Defined in:
lib/compass/grid_builder.rb

Constant Summary

Constants inherited from PNG

PNG::BITS, PNG::CRC_TABLE, PNG::NONE, PNG::RGB

Instance Attribute Summary collapse

Attributes included from Actions

#logger

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 PNG

chunk, crc, #png_join, #to_blob

Constructor Details

#initialize(options = {}) ⇒ GridBuilder

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

    • :filename – Output path of grid.png file



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/compass/grid_builder.rb', line 66

def initialize(options={})
  @column_width = options[:column_width] || 0
  gutter_width = options[:gutter_width] || 0

  height = options[:height] || 20
  width = @column_width + gutter_width
  width = 10 if width == 0

  @filename = options[:filename]
  @options = options

  super(width, height, [0xe9,0xe9,0xe9])
end

Instance Attribute Details

#able_to_generateObject (readonly)

Returns the value of attribute able_to_generate.



58
59
60
# File 'lib/compass/grid_builder.rb', line 58

def able_to_generate
  @able_to_generate
end

#column_widthObject (readonly)

Returns the value of attribute column_width.



58
59
60
# File 'lib/compass/grid_builder.rb', line 58

def column_width
  @column_width
end

#filenameObject (readonly)

Returns the value of attribute filename.



58
59
60
# File 'lib/compass/grid_builder.rb', line 58

def filename
  @filename
end

#gutter_widthObject (readonly)

Returns the value of attribute gutter_width.



58
59
60
# File 'lib/compass/grid_builder.rb', line 58

def gutter_width
  @gutter_width
end

#optionsObject (readonly)

Returns the value of attribute options.



58
59
60
# File 'lib/compass/grid_builder.rb', line 58

def options
  @options
end

Instance Method Details

#generate!Object

generates (overwriting if necessary) grid.png image to be tiled in background



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/compass/grid_builder.rb', line 85

def generate!
  (0...@height-1).each do |line|
    @data[line] = Array.new(@width){|x| x < @column_width ? [0xe8, 0xef, 0xfb] : [0xff,0xff,0xff] }
  end

  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 File.dirname(filename)
  write_file(filename, self.to_blob, options, true)
end

#working_pathObject



80
81
82
# File 'lib/compass/grid_builder.rb', line 80

def working_path
  options[:working_path]
end