Class: Prawn::Document::Grid

Inherits:
Object
  • Object
show all
Defined in:
lib/prawn/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.

Experimental API (collapse)

Experimental API (collapse)

Constructor Details

- (Grid) initialize(pdf, options = {})

:nodoc:



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

def initialize(pdf, options = {}) # :nodoc:
  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

- (Object) column_gutter (readonly)

Returns the value of attribute column_gutter



58
59
60
# File 'lib/prawn/grid.rb', line 58

def column_gutter
  @column_gutter
end

- (Object) columns (readonly)

Returns the value of attribute columns



58
59
60
# File 'lib/prawn/grid.rb', line 58

def columns
  @columns
end

- (Object) gutter (readonly)

Returns the value of attribute gutter



58
59
60
# File 'lib/prawn/grid.rb', line 58

def gutter
  @gutter
end

- (Object) pdf (readonly)

Returns the value of attribute pdf



58
59
60
# File 'lib/prawn/grid.rb', line 58

def pdf
  @pdf
end

- (Object) row_gutter (readonly)

Returns the value of attribute row_gutter



58
59
60
# File 'lib/prawn/grid.rb', line 58

def row_gutter
  @row_gutter
end

- (Object) rows (readonly)

Returns the value of attribute rows



58
59
60
# File 'lib/prawn/grid.rb', line 58

def rows
  @rows
end

Instance Method Details

- (Object) column_width

Calculates the base width of boxes.



70
71
72
# File 'lib/prawn/grid.rb', line 70

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

- (Object) row_height

Calculates the base height of boxes.



75
76
77
# File 'lib/prawn/grid.rb', line 75

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

- (Object) show_all(color = "CCCCCC")

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



80
81
82
83
84
85
86
# File 'lib/prawn/grid.rb', line 80

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