Module: AwesomeTables::ViewHelpers::ActionView
- Defined in:
- lib/awesome_tables/view_helpers/action_view.rb
Instance Method Summary collapse
-
#awesome_table(table_type, collection = nil) ⇒ Object
TODO make this only need table_type and infer objects by name TODO add a render method so calling partial is not needed here e.g.
- #table_headers(table) ⇒ Object
- #table_row(object, columns) ⇒ Object
- #table_rows(table) ⇒ Object
- #td_tag(column, object) ⇒ Object
- #th_tag(column) ⇒ Object
Instance Method Details
#awesome_table(table_type, collection = nil) ⇒ Object
TODO make this only need table_type and infer objects by name TODO add a render method so calling partial is not needed here
e.g. AwesomeTables::AwesomeTable.new(table_type, data).render
7 8 9 10 11 12 13 14 15 |
# File 'lib/awesome_tables/view_helpers/action_view.rb', line 7 def awesome_table(table_type, collection = nil) if collection.nil? collection_name = "@#{table_type}" collection = instance_variable_get(collection_name) end raise AwesomeTables::BadData unless collection.is_a? Array awesome_table = AwesomeTables.new(table_type, collection) render :partial => awesome_table.template, :locals => { :table => awesome_table } end |
#table_headers(table) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/awesome_tables/view_helpers/action_view.rb', line 17 def table_headers(table) content_tag :tr do = [] table.columns.each do |column| << th_tag(column) end .join('') end end |
#table_row(object, columns) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/awesome_tables/view_helpers/action_view.rb', line 45 def table_row(object, columns) content_tag :tr do row = [] columns.each do |column| row << td_tag(column, object) end row.join('') end end |
#table_rows(table) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/awesome_tables/view_helpers/action_view.rb', line 37 def table_rows(table) rows = [] table.collection.each do |object| rows << table_row(object, table.columns) end raw(rows.join('')) end |
#td_tag(column, object) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/awesome_tables/view_helpers/action_view.rb', line 55 def td_tag(column, object) content_tag(:td) do if column[:method].is_a?(Proc) column[:method].call(object, self) elsif object.respond_to? column[:method] object.send(column[:method]).to_s else render :partial => column[:method], :locals => { :obj => object } end end end |
#th_tag(column) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/awesome_tables/view_helpers/action_view.rb', line 27 def th_tag(column) content_tag(:th, :class => column[:options][:class]) do if column[:options][:header_image] image_tag(column[:options][:header_image], :border => 0) else column[:header] end end end |