Class: Prawn::Document::Grid

Inherits:
Object
  • Object
show all
Defined in:
lib/prawn/layout/grid.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pdf, options = {}) ⇒ Grid

:nodoc



39
40
41
42
43
44
45
46
47
# File 'lib/prawn/layout/grid.rb', line 39

def initialize(pdf, options = {})
  valid_options = [:columns, :rows, :gutter, :row_gutter, :column_gutter]
  Prawn.verify_options valid_options, options

  @pdf = pdf
  @columns = options[:columns]
  @rows = options[:rows]
  set_gutter(options)
end

Instance Attribute Details

#column_gutterObject (readonly)

Returns the value of attribute column_gutter.



37
38
39
# File 'lib/prawn/layout/grid.rb', line 37

def column_gutter
  @column_gutter
end

#columnsObject (readonly)

Returns the value of attribute columns.



37
38
39
# File 'lib/prawn/layout/grid.rb', line 37

def columns
  @columns
end

#gutterObject (readonly)

Returns the value of attribute gutter.



37
38
39
# File 'lib/prawn/layout/grid.rb', line 37

def gutter
  @gutter
end

#pdfObject (readonly)

Returns the value of attribute pdf.



37
38
39
# File 'lib/prawn/layout/grid.rb', line 37

def pdf
  @pdf
end

#row_gutterObject (readonly)

Returns the value of attribute row_gutter.



37
38
39
# File 'lib/prawn/layout/grid.rb', line 37

def row_gutter
  @row_gutter
end

#rowsObject (readonly)

Returns the value of attribute rows.



37
38
39
# File 'lib/prawn/layout/grid.rb', line 37

def rows
  @rows
end

Instance Method Details

#column_widthObject

Calculates the base width of boxes.



50
51
52
# File 'lib/prawn/layout/grid.rb', line 50

def column_width
  @column_width ||= subdivide(pdf.bounds.width, columns, column_gutter)
end

#row_heightObject

Calculates the base height of boxes.



55
56
57
# File 'lib/prawn/layout/grid.rb', line 55

def row_height
 @row_height ||= subdivide(pdf.bounds.height, rows, row_gutter)
end

#show_all(color = "CCCCCC") ⇒ Object

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



60
61
62
63
64
65
66
# File 'lib/prawn/layout/grid.rb', line 60

def show_all(color = "CCCCCC")
  self.rows.times do |i|
    self.columns.times do |j|
      pdf.grid(i,j).show(color)
    end
  end
end