Class: TableMe::TableForPresenter

Inherits:
ActionView::Base
  • Object
show all
Includes:
ActionView::Helpers::CaptureHelper, Haml::Helpers
Defined in:
lib/table_me/table_for_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_name, options = {}, &block) ⇒ TableForPresenter

Returns a new instance of TableForPresenter.



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/table_me/table_for_presenter.rb', line 74

def initialize table_name, options = {}, &block
  # self.parent = parent
  self.options = options
  self.name = table_name
  @block = block

  # required to get capture to work with haml
  init_haml_helpers if defined?(Haml)

  process_data_attributes 
end

Instance Attribute Details

#dataObject (readonly)

get data from the table_me_presenter in the controller. This breaks encapsulation and makes this class too tightly coupled to the TableMePresenter, I wanted to keep the table data out of the class variables in the controller and view, but there has to be a better way to do it. TODO decouple this and options below



112
113
114
# File 'lib/table_me/table_for_presenter.rb', line 112

def data
  @data
end

#nameObject

Returns the value of attribute name.



71
72
73
# File 'lib/table_me/table_for_presenter.rb', line 71

def name
  @name
end

#optionsObject

same as data above, only with table options. Ideally this needs to be a value object instead of just a hash. TODO use a value object instead of a hash, see table_vo.rb



119
120
121
# File 'lib/table_me/table_for_presenter.rb', line 119

def options
  @options
end

Instance Method Details

#build_tableObject

build the complete table with pagination and filters if set.



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/table_me/table_for_presenter.rb', line 88

def build_table 
  <<-HTML.strip_heredoc.html_safe
    <div class='table-me'>
      #{table_filters}
      <div class="table-me-table #{'with-filters' if table_builder.filters}">
        #{table_pagination.pagination_info}
        <table>
          <thead>
            <tr>#{create_header}</tr>
          </thead>
          <tbody>
            #{table_rows}
          </tbody>
        </table>
        #{table_pagination.pagination_controls}
      </div>
    </div>
  HTML
end