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, table_me_presenter, options = {}, &block) ⇒ TableForPresenter

Returns a new instance of TableForPresenter.



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

def initialize table_name, table_me_presenter, options = {}, &block
  @table_me_presenter = table_me_presenter

  self.options = ActiveSupport::HashWithIndifferentAccess.new(options.merge(@table_me_presenter.options))
  self.name = table_name
  @block = block

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

  setup_classes
  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



114
115
116
# File 'lib/table_me/table_for_presenter.rb', line 114

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

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#build_tableObject

build the complete table with pagination and filters if set.



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

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