Class: Blueprint::GridBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/blueprint/grid_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

    • :output_path – Output path of grid.png file



10
11
12
13
14
# File 'lib/blueprint/grid_builder.rb', line 10

def initialize(options={})
  @column_width = options[:column_width] || Blueprint::COLUMN_WIDTH
  @gutter_width = options[:gutter_width] || Blueprint::GUTTER_WIDTH
  @output_path  = options[:output_path]  || Blueprint::SOURCE_PATH
end

Instance Attribute Details

#able_to_generateObject (readonly)

Returns the value of attribute able_to_generate



3
4
5
# File 'lib/blueprint/grid_builder.rb', line 3

def able_to_generate
  @able_to_generate
end

#column_widthObject (readonly)

Returns the value of attribute column_width



3
4
5
# File 'lib/blueprint/grid_builder.rb', line 3

def column_width
  @column_width
end

#gutter_widthObject (readonly)

Returns the value of attribute gutter_width



3
4
5
# File 'lib/blueprint/grid_builder.rb', line 3

def gutter_width
  @gutter_width
end

#output_pathObject (readonly)

Returns the value of attribute output_path



3
4
5
# File 'lib/blueprint/grid_builder.rb', line 3

def output_path
  @output_path
end

Instance Method Details

#generate!Object

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



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/blueprint/grid_builder.rb', line 17

def generate!
  total_width = self.column_width + self.gutter_width
  height      = 18

  white      = ChunkyPNG::Color.from_hex("ffffff")
  background = ChunkyPNG::Color.from_hex("e8effb")
  line       = ChunkyPNG::Color.from_hex("e9e9e9")

  png = ChunkyPNG::Image.new(total_width, height, white)
  png.rect(0, 0, column_width - 1, height, background, background)
  png.rect(0, height - 1, total_width, height - 1, line, line)

  FileUtils.mkdir(self.output_path) unless File.exists?(self.output_path)
  png.save(File.join(self.output_path, "grid.png"))
end