Class: Compendium::Presenters::Table
- Defined in:
- app/classes/compendium/presenters/table.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#records ⇒ Object
readonly
Returns the value of attribute records.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
-
#totals ⇒ Object
readonly
Returns the value of attribute totals.
Instance Method Summary collapse
-
#initialize {|@settings| ... } ⇒ Table
constructor
A new instance of Table.
- #render ⇒ Object
Methods inherited from Base
Constructor Details
#initialize {|@settings| ... } ⇒ Table
Returns a new instance of Table.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/classes/compendium/presenters/table.rb', line 5 def initialize(*) super @records = results.records @settings = settings_class.new(query) @settings.set_headings(results.keys) @settings.update(&query.table_settings) if query.table_settings yield @settings if block_given? if has_totals_row? @totals = @records.pop totals[totals.keys.first] = translate(:total) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Compendium::Presenters::Base
Instance Attribute Details
#records ⇒ Object (readonly)
Returns the value of attribute records.
3 4 5 |
# File 'app/classes/compendium/presenters/table.rb', line 3 def records @records end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
3 4 5 |
# File 'app/classes/compendium/presenters/table.rb', line 3 def settings @settings end |
#totals ⇒ Object (readonly)
Returns the value of attribute totals.
3 4 5 |
# File 'app/classes/compendium/presenters/table.rb', line 3 def totals @totals end |
Instance Method Details
#render ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/classes/compendium/presenters/table.rb', line 21 def render content_tag(:table, class: @settings.table_class) do table = ActiveSupport::SafeBuffer.new table << content_tag(:thead, build_row(headings, settings.header_class, :th, &heading_proc)) table << content_tag(:tbody) do tbody = ActiveSupport::SafeBuffer.new records.each { |row| tbody << build_row(row, settings.row_class, &data_proc) } tbody end table << content_tag(:tfoot, build_row(totals, @settings.totals_class, :th, &totals_proc)) if has_totals_row? table end end |