Class: AhoyCaptain::Tables::DynamicTableComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- AhoyCaptain::Tables::DynamicTableComponent
- Defined in:
- app/components/ahoy_captain/tables/dynamic_table_component.rb
Defined Under Namespace
Classes: TableDefinition
Class Method Summary collapse
Instance Method Summary collapse
- #for(item) ⇒ Object
- #headers ⇒ Object
-
#initialize(klass, table, options = {}) ⇒ DynamicTableComponent
constructor
A new instance of DynamicTableComponent.
- #row(item, view_context) ⇒ Object
Constructor Details
#initialize(klass, table, options = {}) ⇒ DynamicTableComponent
Returns a new instance of DynamicTableComponent.
184 185 186 187 188 |
# File 'app/components/ahoy_captain/tables/dynamic_table_component.rb', line 184 def initialize(klass, table, = {}) @klass = klass @table = table @options = end |
Class Method Details
.build(klass, options = {}, &block) ⇒ Object
176 177 178 179 180 181 182 |
# File 'app/components/ahoy_captain/tables/dynamic_table_component.rb', line 176 def self.build(klass, = {}, &block) if .key?(:fixed_height) [:header_options] = { fixed_height: .delete(:fixed_height) } end table = TableDefinition.new(klass).instance_exec(&block) new(klass, table, ) end |
Instance Method Details
#for(item) ⇒ Object
190 191 192 193 |
# File 'app/components/ahoy_captain/tables/dynamic_table_component.rb', line 190 def for(item) @item = item self end |
#headers ⇒ Object
199 200 201 |
# File 'app/components/ahoy_captain/tables/dynamic_table_component.rb', line 199 def headers HeaderComponent.new(@table.rows.map.with_index { |row, index| { label: row.header, grow: index.zero? } }, @options[:header_options] || {}) end |
#row(item, view_context) ⇒ Object
195 196 197 |
# File 'app/components/ahoy_captain/tables/dynamic_table_component.rb', line 195 def row(item, view_context) @table.row(item, view_context) end |