Module: RGhost::Grid::CallbackFacade

Included in:
Base
Defined in:
lib/rghost/grid/callback_facade.rb

Overview

The callbacks for the grid are defined here. Let’s see them in action.

Grid::CallbackFacade examples

grid=Grid::Matrix.new :column_padding => 1
grid.column :title => "Id", :width => 1
grid.column :title => "Name", :width => 3, :align => :center
grid.column :title => "Date", :width => 3, :align => :right, :title_align => :center,  :format => lambda{|v| v.strftime("%d/%m/%Y")}
values=('A'..'E').to_a.map{|v|  [v,"Name #{v}", Time.now]}

even_row:

grid.even_row do |e|
 e.background_row(:size => grid.width)
end

Now before_row to create a top and bottom line:

grid.before_row do |b|
 b.horizontal_line(:top,    :size => grid.width )
 b.horizontal_line(:bottom, :size => grid.width)
end

before_column:

grid.before_column do |v|
 v.vertical_line_row
end

after_column:

grid.after_column {|c|  c.vertical_line_row  }

Moving to the header

grid.header.before_create do |b|
 b.horizontal_line(:top, :size => grid.width)
end

Finishing the grid lines:

grid.header.before_column do |b|
  b.vertical_line_row
end

grid.header.after_column do |b|
 b.vertical_line_row
end

Now a adding a bold font to the header

grid.header.before_create do |b|
  b.horizontal_line(:top, :size => grid.width)
  b.use_tag :bold
 end

Oops. Not quite what we expected, the entire grid used bold face. We need to use a header callback to reset the font.

grid.header.after_create do
   b.use_tag :normal
 end

Don’t forget

doc=Document.new
doc.set grid

Instance Method Summary collapse

Instance Method Details

#after_column(options = {}, &block) ⇒ Object

Executes after a column was created. Responds to :only and :except options.



106
107
108
# File 'lib/rghost/grid/callback_facade.rb', line 106

def after_column(options={},&block)
  new_dynamic_callback(:after_column,options,&block)
end

#before_column(options = {}, &block) ⇒ Object

Executes before creating a column. Responds to :only and :except options.



100
101
102
# File 'lib/rghost/grid/callback_facade.rb', line 100

def before_column(options={},&block)
  new_dynamic_callback(:before_column,options,&block)
end

#before_row(options = {}, &block) ⇒ Object

Executes before processing row. Responds to :only and :except options.



82
83
84
# File 'lib/rghost/grid/callback_facade.rb', line 82

def before_row(options={},&block)
  new_dynamic_callback(:before_row,options,&block)
end

#even_column(options = {}, &block) ⇒ Object

Executes upon creating an even column. Responds to :only and :except options.



118
119
120
# File 'lib/rghost/grid/callback_facade.rb', line 118

def even_column(options={},&block)
  new_dynamic_callback(:even_column,options,&block)
end

#even_row(options = {}, &block) ⇒ Object

Executes upon creating even rows. Responds to :only and :except options.



94
95
96
# File 'lib/rghost/grid/callback_facade.rb', line 94

def even_row(options={},&block)
  new_dynamic_callback(:even_row,options,&block)
end

#odd_column(options = {}, &block) ⇒ Object

Executes when creating an odd column. Responds to :only and :except options.



112
113
114
# File 'lib/rghost/grid/callback_facade.rb', line 112

def odd_column(options={},&block)
  new_dynamic_callback(:odd_column,options,&block)
end

#odd_row(options = {}, &block) ⇒ Object

Executes on creating an odd rows. Responds to :only and :except options.



88
89
90
# File 'lib/rghost/grid/callback_facade.rb', line 88

def odd_row(options={},&block)
  new_dynamic_callback(:odd_row,options,&block)
end