Class: RGhost::Grid::Rails

Inherits:
Base show all
Defined in:
lib/rghost/grid/rails_grid.rb

Overview

g.column ‘accounts.first.login’, :title => Login“

Instance Attribute Summary

Attributes inherited from Base

#column_padding, #header

Instance Method Summary collapse

Methods inherited from Base

#format_field, #initialize, #proc_line, #ps, #style, #width

Methods included from CallbackFacade

#after_column, #before_column, #before_row, #even_column, #even_row, #odd_column, #odd_row

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, #initialize, #ps, #raw, #set, #to_s

Constructor Details

This class inherits a constructor from RGhost::Grid::Base

Instance Method Details

#col(field_name, options = {}) ⇒ Object

:nodoc:



60
61
62
63
64
65
66
67
68
# File 'lib/rghost/grid/rails_grid.rb', line 60

def col(field_name, options={}) #:nodoc:
  super(options[:title],options)
   
  @rails_cols||=[]
  owf=options.dup #from options with field
  owf[:field_name]||=field_name
  @rails_cols << owf

end

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

:nodoc:



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

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

#data(_data) ⇒ Object

The parameter _data is an Array of ActiveRecord::Base objects.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rghost/grid/rails_grid.rb', line 44

def data(_data)
  _data.collect do |d|
    line=@rails_cols.collect do |c|
      case c[:field_name]
        when Symbol
          d[c[:field_name]]
        when String
          d.instance_eval c[:field_name]
        when Proc
          d.instance_eval(&c[:field_name])
      end
    end
    proc_line(line)
  end
end