Class: DiningTable::Presenters::HTMLPresenter

Inherits:
Presenter
  • Object
show all
Defined in:
lib/dining-table/presenters/html_presenter.rb

Instance Attribute Summary collapse

Attributes inherited from Presenter

#options, #table, #view_context

Instance Method Summary collapse

Methods inherited from Presenter

#connect_to, #type?

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( options = {} )
  super
  self.base_tags_configuration = HTMLPresenterConfiguration::TagsConfiguration.from_hash( default_options )
  base_tags_configuration.merge_hash( options )
  self.output = ''.html_safe
end

Instance Attribute Details

#base_tags_configurationObject

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
  @base_tags_configuration
end

#outputObject



86
87
88
# File 'lib/dining-table/presenters/html_presenter.rb', line 86

def output
  @output
end

#row_config_blockObject

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_blockObject

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_configurationObject

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
  @table_tags_configuration
end

#tags_configurationObject

Returns the value of attribute tags_configuration.



7
8
9
# File 'lib/dining-table/presenters/html_presenter.rb', line 7

def tags_configuration
  @tags_configuration
end

Instance Method Details

#end_bodyObject



42
43
44
# File 'lib/dining-table/presenters/html_presenter.rb', line 42

def end_body
  add_tag(:end, :tbody)
end

#end_tableObject



31
32
33
34
35
36
# File 'lib/dining-table/presenters/html_presenter.rb', line 31

def end_table
  add_tag(:end, :table)
  if options[:wrap]
    add_tag(:end, wrap_tag )
  end
end

#identifierObject



19
20
21
# File 'lib/dining-table/presenters/html_presenter.rb', line 19

def identifier
  :html
end


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 render_footer
  set_up_row_configuration( :footer, nil )
  footers = columns.each.map(&:footer)
  if footers.map { |s| blank?(s) }.uniq != [ true ]
    add_tag(:start, :tfoot, tag_options(:tfoot))
    add_tag(:start, :tr, row_options)
    columns.each_with_index do |column, index|
      value = footers[index]
      configuration = cell_configuration( tags_configuration, column, :footer, nil )
      render_footer_cell( value, configuration )
    end
    add_tag(:end,   :tr)
    add_tag(:end,   :tfoot)
  end
end

#render_headerObject



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, tag_options(:thead))
  add_tag(:start, :tr, row_options)
  columns.each do |column|
    value = column.header
    configuration = cell_configuration( tags_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, row_options)
  columns.each do |column|
    value = column.value( object )
    configuration = cell_configuration( tags_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_bodyObject



38
39
40
# File 'lib/dining-table/presenters/html_presenter.rb', line 38

def start_body
  add_tag(:start, :tbody, tag_options(:tbody))
end

#start_tableObject



23
24
25
26
27
28
29
# File 'lib/dining-table/presenters/html_presenter.rb', line 23

def start_table
  set_up_configuration
  if options[:wrap]
    add_tag(:start, wrap_tag, wrap_options )
  end
  add_tag(:start, :table, table_options )
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