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

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

Returns a new instance of Grid.

Parameters:

Options Hash (options):

  • :columns (Integer)

    Number of columns in the grid.

  • :rows (Integer)

    Number of rows in the grid.

  • :gutter (Number)

    Gutter size. :row_gutter and :column_gutter are ignored if specified.

  • :row_gutter (Number)

    Row gutter size.

  • :column_gutter (Number)

    Column gutter size.

Source Code
lib/prawn/grid.rb, line 104
104
def initialize(pdf, options = {})
105
  valid_options = %i[columns rows gutter row_gutter column_gutter]
106
  Prawn.verify_options(valid_options, options)
107
108
  @pdf = pdf
109
  @columns = options[:columns]
110
  @rows = options[:rows]
111
  apply_gutter(options)
112
end

Instance Attribute Details

#column_gutterNumber (readonly)

Column gutter size.

Returns:

  • (Number)
Source Code
lib/prawn/grid.rb, line 94
94
def column_gutter
95
  @column_gutter
96
end

#columnsInteger (readonly)

Number of columns in the grid.

Returns:

  • (Integer)
Source Code
lib/prawn/grid.rb, line 78
78
def columns
79
  @columns
80
end

#gutterNumber (readonly)

Gutter size.

Returns:

  • (Number)
Source Code
lib/prawn/grid.rb, line 86
86
def gutter
87
  @gutter
88
end

#row_gutterNumber (readonly)

Row gutter size.

Returns:

  • (Number)
Source Code
lib/prawn/grid.rb, line 90
90
def row_gutter
91
  @row_gutter
92
end

#rowsInteger (readonly)

Number of rows in the grid.

Returns:

  • (Integer)
Source Code
lib/prawn/grid.rb, line 82
82
def rows
83
  @rows
84
end

Instance Method Details

#column_widthFloat

Calculates the base width of boxes.

Returns:

  • (Float)
Source Code
lib/prawn/grid.rb, line 117
117
def column_width
118
  @column_width ||= subdivide(pdf.bounds.width, columns, column_gutter)
119
end

#row_heightFloat

Calculates the base height of boxes.

Returns:

  • (Float)
Source Code
lib/prawn/grid.rb, line 124
124
def row_height
125
  @row_height ||= subdivide(pdf.bounds.height, rows, row_gutter)
126
end

#show_all(color = 'CCCCCC') ⇒ void

This method returns an undefined value.

Diagnostic tool to show all of the grid boxes.

Parameters:

  • color (Color) (defaults to: 'CCCCCC')
Source Code
lib/prawn/grid.rb, line 132
132
def show_all(color = 'CCCCCC')
133
  rows.times do |row|
134
    columns.times do |column|
135
      pdf.grid(row, column).show(color)
136
    end
137
  end
138
end