Module: TableMe::TableForHelper

Defined in:
lib/table_me/table_for_helper/table_for_helper.rb

Instance Method Summary collapse

Instance Method Details

#highlight_cell(value, colors) ⇒ Object

table_for :user do |t|

t.column :id
t.column :admin do |c|
  highlight_cell c.admin, green: [true, 'Admin'], red: [false, 'peon']
end
t.column :created_at

end



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/table_me/table_for_helper/table_for_helper.rb', line 89

def highlight_cell value, colors
  color_value = output_value = color = ''

  colors.each do |k,v|
    if v.kind_of? Array
      color_value = v[0]
      output_value = v[1]
    else
      output_value = color_value = v
    end
    
    if color_value == value
      color = k.to_s
      break
    end
  end

  unless color.empty?
    "<span class='#{color}'>#{output_value}</span>".html_safe
  else
    value
  end
end

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



61
62
63
64
65
# File 'lib/table_me/table_for_helper/table_for_helper.rb', line 61

def table_for(model, options = {}, &block)

  table_for_presenter = TableForPresenter.new(model, @table_me[model],options,&block)
  table_for_presenter.build_table
end