Parent

Files

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.

Attributes

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

Public Class Methods

new(pdf, options = {}) click to toggle source

:nodoc

    # File lib/prawn/layout/grid.rb, line 39
39:       def initialize(pdf, options = {})
40:         valid_options = [:columns, :rows, :gutter, :row_gutter, :column_gutter]
41:         Prawn.verify_options valid_options, options
42:       
43:         @pdf = pdf
44:         @columns = options[:columns]
45:         @rows = options[:rows]
46:         set_gutter(options)
47:       end

Public Instance Methods

column_width() click to toggle source

Calculates the base width of boxes.

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

Calculates the base height of boxes.

    # File lib/prawn/layout/grid.rb, line 55
55:       def row_height
56:        @row_height ||= subdivide(pdf.bounds.height, rows, row_gutter)
57:       end
show_all(color = "CCCCCC") click to toggle source

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

    # File lib/prawn/layout/grid.rb, line 60
60:       def show_all(color = "CCCCCC")
61:         self.rows.times do |i|
62:           self.columns.times do |j|
63:             pdf.grid(i,j).show(color)
64:           end
65:         end
66:       end

Private Instance Methods

set_gutter(options) click to toggle source
    # File lib/prawn/layout/grid.rb, line 74
74:       def set_gutter(options)
75:         if options.has_key?(:gutter)
76:           @gutter = options[:gutter].to_f
77:           @row_gutter, @column_gutter = @gutter, @gutter
78:         else
79:           @row_gutter    = options[:row_gutter].to_f
80:           @column_gutter = options[:column_gutter].to_f
81:           @gutter = 0
82:         end
83:       end
subdivide(total, num, gutter) click to toggle source
    # File lib/prawn/layout/grid.rb, line 70
70:       def subdivide(total, num, gutter)
71:         (total.to_f - (gutter * (num - 1).to_f)) / num.to_f
72:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.