class Prawn::Document::Grid

A Grid represents the entire grid system of a Page and calculates the column width and row height of the base box.

@group Experimental API

Attributes

column_gutter[R]
columns[R]
gutter[R]
pdf[R]
row_gutter[R]
rows[R]

Public Instance Methods

column_width() click to toggle source

Calculates the base width of boxes.

# File lib/prawn/grid.rb, line 71
def column_width
  @column_width ||= subdivide(pdf.bounds.width, columns, column_gutter)
end
row_height() click to toggle source

Calculates the base height of boxes.

# File lib/prawn/grid.rb, line 76
def row_height
  @row_height ||= subdivide(pdf.bounds.height, rows, row_gutter)
end
show_all(color = 'CCCCCC') click to toggle source

Diagnostic tool to show all of the grids. Defaults to gray.

# File lib/prawn/grid.rb, line 81
def show_all(color = 'CCCCCC')
  rows.times do |row|
    columns.times do |column|
      pdf.grid(row, column).show(color)
    end
  end
end

Private Instance Methods

apply_gutter(options) click to toggle source
# File lib/prawn/grid.rb, line 95
def apply_gutter(options)
  if options.key?(:gutter)
    @gutter = options[:gutter].to_f
    @row_gutter = @gutter
    @column_gutter = @gutter
  else
    @row_gutter = options[:row_gutter].to_f
    @column_gutter = options[:column_gutter].to_f
    @gutter = 0
  end
end
subdivide(total, num, gutter) click to toggle source
# File lib/prawn/grid.rb, line 91
def subdivide(total, num, gutter)
  (total.to_f - (gutter * (num - 1).to_f)) / num.to_f
end