Class: AhoyCaptain::TableComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/ahoy_captain/table_component.rb

Constant Summary collapse

DEFAULT_HEADER =
AhoyCaptain::Tables::Headers::HeaderComponent
DEFAULT_ROW =
AhoyCaptain::Tables::Rows::RowComponent

Instance Method Summary collapse

Constructor Details

#initialize(items:, category_name: nil, unit_name: nil, header: nil, row: DEFAULT_ROW, table: nil) ⇒ TableComponent

Returns a new instance of TableComponent.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/components/ahoy_captain/table_component.rb', line 7

def initialize(items:, category_name: nil, unit_name: nil, header: nil, row: DEFAULT_ROW, table: nil)
  @items = items
  @category_name = category_name
  @unit_name = unit_name
  if header.nil?
    @header = DEFAULT_HEADER.new(category_name: category_name, unit_name: unit_name)
  else
    @header = header.new
  end

  @row = row

  if table
    @table = table.table
    @header = @table.headers
  end
end

Instance Method Details

#render_row(item) ⇒ Object



25
26
27
28
29
30
31
# File 'app/components/ahoy_captain/table_component.rb', line 25

def render_row(item)
  if @table
    @table.row(item, view_context)
  else
    @row.new(table: self, item: item).render_in(view_context)
  end
end