Class: RGhost::Grid::Header

Inherits:
PsObject show all
Includes:
RubyToPs
Defined in:
lib/rghost/grid/header.rb

Overview

Grid’s Header. You can get a header instance using:

grid=Grid::Rails.new
grid.header

You can also define callbacks:

grid.header.before_column :only => [1,2] do
 use_tag :span
end

Constant Summary collapse

DEFAULT_OPTIONS =
{:width => 4, :align => :center, :title_align => nil, :header_width => nil, :format => :string}

Constants included from RubyToPs

RubyToPs::UTF8_ENCODINGS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RubyToPs

#array_to_stack, #hash_to_array, #pack_string, #ps_escape, #string_eval, #to_array, #to_bool, #to_string, #to_string_array

Methods inherited from PsObject

#<<, #call, #graphic_scope, #raw, #set, #to_s

Constructor Details

#initialize(headings = true, options = {}, &block) ⇒ Header

:nodoc:



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rghost/grid/header.rb', line 26

def initialize(headings=true,options={},&block) #:nodoc:
  @header=RGhost::PsObject.new
  @data_types=[]
  @options=[]
  @titles=[]
  @header.set RGhost::Variable.new(:new_page?,true)  
  @default_options=DEFAULT_OPTIONS.merge(options)
  @header.set RGhost::Variable.new(:headings?,headings)
  @size=0
  instance_eval(&block) if block

end

Instance Attribute Details

#data_typesObject (readonly)

Returns the value of attribute data_types.



24
25
26
# File 'lib/rghost/grid/header.rb', line 24

def data_types
  @data_types
end

#sizeObject (readonly)

Returns the value of attribute size.



24
25
26
# File 'lib/rghost/grid/header.rb', line 24

def size
  @size
end

#titlesObject (readonly)

Returns the value of attribute titles.



24
25
26
# File 'lib/rghost/grid/header.rb', line 24

def titles
  @titles
end

Instance Method Details

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



89
90
91
92
# File 'lib/rghost/grid/header.rb', line 89

def after_column(options={},&block)
  @header.set RGhost::Callback.new(:after_column_header,options,&block)

end

#after_create(&block) ⇒ Object



79
80
81
82
# File 'lib/rghost/grid/header.rb', line 79

def after_create(&block)
  #@header.set RGhost::Function.new(:after_header_create, &block )
  new_static_callback(:after_header_create,&block)
end

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



84
85
86
87
# File 'lib/rghost/grid/header.rb', line 84

def before_column(options={},&block)
  @header.set RGhost::Callback.new(:before_column_header, options,&block)

end

#before_create(&block) ⇒ Object



73
74
75
76
# File 'lib/rghost/grid/header.rb', line 73

def before_create(&block)
  #@header.set RGhost::Function.new(:before_header_create, &block )
  new_static_callback(:before_header_create,&block)
end

#col(name = "", options = {}) ⇒ Object

:nodoc:



50
51
52
53
54
55
56
57
58
# File 'lib/rghost/grid/header.rb', line 50

def col(name="", options={}) #:nodoc:
  
  opts=@default_options.merge(options)
  @size+=opts[:width]
  @data_types << opts[:format]
  @options << opts
  @titles <<  ps_escape(name.to_s)

end

#column(name, options = {}) ⇒ Object

:nodoc:



65
66
67
# File 'lib/rghost/grid/header.rb', line 65

def column(name,options={}) #:nodoc:
  col(name,options)
end

#default_options(opts) ⇒ Object

:nodoc:



60
61
62
63
# File 'lib/rghost/grid/header.rb', line 60

def default_options(opts) #:nodoc:
  @default_options.merge!(opts)

end

#next_column(name, options = {}) ⇒ Object

:nodoc:



69
70
71
# File 'lib/rghost/grid/header.rb', line 69

def next_column(name,options={}) #:nodoc:
  col(name,options)
end

#psObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/rghost/grid/header.rb', line 39

def ps
  
  p,h=format_header
  @header.set RGhost::Variable.new(:header_titles,to_array(@titles))
  @header.set RGhost::Variable.new(:table_params," [\n #{p}] \n")
  @header.set RGhost::Variable.new(:table_header," [\n #{h}] \n")


  @header
end