Class: DiningTable::Presenters::HTMLPresenter
- Defined in:
- lib/dining-table/presenters/html_presenter.rb
Instance Attribute Summary collapse
-
#base_tags_configuration ⇒ Object
Returns the value of attribute base_tags_configuration.
- #output ⇒ Object readonly
-
#row_config_block ⇒ Object
Returns the value of attribute row_config_block.
-
#table_config_block ⇒ Object
Returns the value of attribute table_config_block.
-
#table_tags_configuration ⇒ Object
Returns the value of attribute table_tags_configuration.
-
#tags_configuration ⇒ Object
Returns the value of attribute tags_configuration.
Attributes inherited from Presenter
#options, #table, #view_context
Instance Method Summary collapse
- #end_body ⇒ Object
- #end_table ⇒ Object
- #identifier ⇒ Object
-
#initialize(options = {}) ⇒ HTMLPresenter
constructor
A new instance of HTMLPresenter.
- #render_footer ⇒ Object
- #render_header ⇒ Object
- #render_row(object) ⇒ Object
- #row_config(&block) ⇒ Object
- #start_body ⇒ Object
- #start_table ⇒ Object
- #table_config(&block) ⇒ Object
Methods inherited from Presenter
Constructor Details
#initialize(options = {}) ⇒ HTMLPresenter
Returns a new instance of HTMLPresenter.
12 13 14 15 16 17 |
# File 'lib/dining-table/presenters/html_presenter.rb', line 12 def initialize( = {} ) super self. = HTMLPresenterConfiguration::TagsConfiguration.from_hash( ) .merge_hash( ) self.output = ''.html_safe end |
Instance Attribute Details
#base_tags_configuration ⇒ Object
Returns the value of attribute base_tags_configuration.
7 8 9 |
# File 'lib/dining-table/presenters/html_presenter.rb', line 7 def @base_tags_configuration end |
#output ⇒ Object
86 87 88 |
# File 'lib/dining-table/presenters/html_presenter.rb', line 86 def output @output end |
#row_config_block ⇒ Object
Returns the value of attribute row_config_block.
7 8 9 |
# File 'lib/dining-table/presenters/html_presenter.rb', line 7 def row_config_block @row_config_block end |
#table_config_block ⇒ Object
Returns the value of attribute table_config_block.
7 8 9 |
# File 'lib/dining-table/presenters/html_presenter.rb', line 7 def table_config_block @table_config_block end |
#table_tags_configuration ⇒ Object
Returns the value of attribute table_tags_configuration.
7 8 9 |
# File 'lib/dining-table/presenters/html_presenter.rb', line 7 def @table_tags_configuration end |
#tags_configuration ⇒ Object
Returns the value of attribute tags_configuration.
7 8 9 |
# File 'lib/dining-table/presenters/html_presenter.rb', line 7 def @tags_configuration end |
Instance Method Details
#end_body ⇒ Object
42 43 44 |
# File 'lib/dining-table/presenters/html_presenter.rb', line 42 def end_body add_tag(:end, :tbody) end |
#end_table ⇒ Object
31 32 33 34 35 36 |
# File 'lib/dining-table/presenters/html_presenter.rb', line 31 def end_table add_tag(:end, :table) if [:wrap] add_tag(:end, wrap_tag ) end end |
#identifier ⇒ Object
19 20 21 |
# File 'lib/dining-table/presenters/html_presenter.rb', line 19 def identifier :html end |
#render_footer ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/dining-table/presenters/html_presenter.rb', line 70 def set_up_row_configuration( :footer, nil ) = columns.each.map(&:footer) if .map { |s| blank?(s) }.uniq != [ true ] add_tag(:start, :tfoot, (:tfoot)) add_tag(:start, :tr, ) columns.each_with_index do |column, index| value = [index] configuration = cell_configuration( , column, :footer, nil ) ( value, configuration ) end add_tag(:end, :tr) add_tag(:end, :tfoot) end end |
#render_header ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/dining-table/presenters/html_presenter.rb', line 57 def render_header set_up_row_configuration( :header, nil ) add_tag(:start, :thead, (:thead)) add_tag(:start, :tr, ) columns.each do |column| value = column.header configuration = cell_configuration( , column, :header, nil ) render_header_cell( value, configuration ) end add_tag(:end, :tr) add_tag(:end, :thead) end |
#render_row(object) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/dining-table/presenters/html_presenter.rb', line 46 def render_row( object ) set_up_row_configuration( table.index, object ) add_tag(:start, :tr, ) columns.each do |column| value = column.value( object ) configuration = cell_configuration( , column, table.index, object ) render_cell( value, configuration ) end add_tag(:end, :tr) end |
#row_config(&block) ⇒ Object
94 95 96 |
# File 'lib/dining-table/presenters/html_presenter.rb', line 94 def row_config(&block) self.row_config_block = block end |
#start_body ⇒ Object
38 39 40 |
# File 'lib/dining-table/presenters/html_presenter.rb', line 38 def start_body add_tag(:start, :tbody, (:tbody)) end |
#start_table ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/dining-table/presenters/html_presenter.rb', line 23 def start_table set_up_configuration if [:wrap] add_tag(:start, wrap_tag, ) end add_tag(:start, :table, ) end |
#table_config(&block) ⇒ Object
90 91 92 |
# File 'lib/dining-table/presenters/html_presenter.rb', line 90 def table_config(&block) self.table_config_block = block end |