Class: SortingTableFor::FormatCell

Inherits:
FormatLine show all
Defined in:
lib/sorting_table_for/format_cell.rb

Instance Method Summary collapse

Methods inherited from FormatLine

#add_cell, #render_line, #total_cells

Methods inherited from TableBuilder

#caption, #column, #columns, #footer, #footers, #header, #headers

Constructor Details

#initialize(object, args, type = nil, block = nil) ⇒ FormatCell

Returns a new instance of FormatCell.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/sorting_table_for/format_cell.rb', line 4

def initialize(object, args, type = nil, block = nil)
  @object, @type, @block = object, type, block
  if args.is_a? Array
    @options, @html_options = get_cell_and_html_options( args.extract_options! )
    @ask = args.first
    if @ask.nil? and @options.has_key?(:action)
      @type = :action 
      @ask = @options[:action]
    end
  else
    @ask = args
  end
  set_default_options
  can_sort_column?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class SortingTableFor::TableBuilder

Instance Method Details

#render_cell_tbodyObject

Return a td with the formated value or action for columns



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/sorting_table_for/format_cell.rb', line 21

def render_cell_tbody
  if @type == :action
    cell_value = action_link_to(@ask)
  elsif @ask
    cell_value = (@ask.is_a?(Symbol)) ? format_cell_value(@object[@ask], @ask) : format_cell_value(@ask)
  else
    cell_value = @block
  end
  cell_value = action_link_to(@options[:action], cell_value) if @type != :action and @options.has_key?(:action)
  (:td, cell_value, @html_options)
end

#render_cell_tfootObject



49
50
51
52
53
54
55
56
57
# File 'lib/sorting_table_for/format_cell.rb', line 49

def render_cell_tfoot
  if @ask
    cell_value = (@ask.is_a?(Symbol)) ? I18n.t(@ask, {}, :footer) : @ask
  else
    cell_value = @block
  end
  cell_value = action_link_to(@options[:action], cell_value) if @type != :action and @options.has_key?(:action)
  (:td, cell_value, @html_options)
end

#render_cell_theadObject

Return a td with the formated value or action for headers



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/sorting_table_for/format_cell.rb', line 34

def render_cell_thead
  if @ask
    cell_value = (@ask.is_a?(Symbol)) ? I18n.t(@ask, {}, :header) : @ask
  else
    cell_value = @block
  end
  if @can_sort
    sort_on = @options[:sort_as] || @ask
    @html_options.merge!(:class => "#{@html_options[:class]} #{sorting_html_class(sort_on)}".strip)
    (:th, sort_link_to(cell_value, sort_on), @html_options)
  else
    (:th, cell_value, @html_options)
  end
end