Class: Katalyst::Tables::CellComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Katalyst::Tables::CellComponent
- Includes:
- HtmlAttributes
- Defined in:
- app/components/katalyst/tables/cell_component.rb
Overview
:nodoc:
Direct Known Subclasses
Katalyst::Tables::Cells::BooleanComponent, Katalyst::Tables::Cells::CurrencyComponent, Katalyst::Tables::Cells::DateComponent, Katalyst::Tables::Cells::DateTimeComponent, Katalyst::Tables::Cells::EnumComponent, Katalyst::Tables::Cells::NumberComponent, Katalyst::Tables::Cells::OrdinalComponent, Katalyst::Tables::Cells::RichTextComponent, Katalyst::Tables::Cells::SelectComponent
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
-
#row ⇒ Object
readonly
Returns the value of attribute row.
Instance Method Summary collapse
- #call ⇒ Object
-
#heading? ⇒ Boolean
True if the cell is a heading cell (th).
-
#initialize(collection:, row:, column:, record:, label:, heading:) ⇒ CellComponent
constructor
A new instance of CellComponent.
- #inspect ⇒ Object
-
#label ⇒ Object
Return the rendered and sanitized label for the column.
-
#rendered_value ⇒ Object
Return the serialized and sanitised data value for rendering in the cell.
-
#to_s ⇒ Object
Serialize data for use in blocks, i.e.
-
#value ⇒ Object
Return the raw value of the cell (i.e. the value of the data read from the record).
-
#with_content_wrapper(component) ⇒ Object
Adds a component to wrap the content of the cell, similar to a layout in Rails views.
Constructor Details
#initialize(collection:, row:, column:, record:, label:, heading:) ⇒ CellComponent
Returns a new instance of CellComponent.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/components/katalyst/tables/cell_component.rb', line 10 def initialize(collection:, row:, column:, record:, label:, heading:, **) super(**) @collection = collection @row = row @column = column @record = record @heading = heading if @row.header? @label = Label.new(collection:, column:, label:) else @data = Data.new(record:, column:) end end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
8 9 10 |
# File 'app/components/katalyst/tables/cell_component.rb', line 8 def collection @collection end |
#column ⇒ Object (readonly)
Returns the value of attribute column.
8 9 10 |
# File 'app/components/katalyst/tables/cell_component.rb', line 8 def column @column end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
8 9 10 |
# File 'app/components/katalyst/tables/cell_component.rb', line 8 def record @record end |
#row ⇒ Object (readonly)
Returns the value of attribute row.
8 9 10 |
# File 'app/components/katalyst/tables/cell_component.rb', line 8 def row @row end |
Instance Method Details
#call ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/components/katalyst/tables/cell_component.rb', line 38 def call content = if content? self.content elsif @row.header? label else rendered_value end content = @content_wrapper.with_content(content.to_s).render_in(view_context) if @content_wrapper concat(content_tag(cell_tag, content, **html_attributes)) end |
#heading? ⇒ Boolean
Returns true if the cell is a heading cell (th).
27 28 29 |
# File 'app/components/katalyst/tables/cell_component.rb', line 27 def heading? @row.header? || @heading end |
#inspect ⇒ Object
74 75 76 |
# File 'app/components/katalyst/tables/cell_component.rb', line 74 def inspect "#<#{self.class.name} method: #{@method.inspect}>" end |
#label ⇒ Object
Return the rendered and sanitized label for the column.
53 54 55 |
# File 'app/components/katalyst/tables/cell_component.rb', line 53 def label @label&.to_s end |
#rendered_value ⇒ Object
Return the serialized and sanitised data value for rendering in the cell.
63 64 65 |
# File 'app/components/katalyst/tables/cell_component.rb', line 63 def rendered_value @data&.to_s end |
#to_s ⇒ Object
Serialize data for use in blocks, i.e.
row.text(:name) { |cell| tag.span(cell) }
69 70 71 72 |
# File 'app/components/katalyst/tables/cell_component.rb', line 69 def to_s # Note, this can't be `content` because the block is evaluated in order to produce content. rendered_value end |
#value ⇒ Object
Return the raw value of the cell (i.e. the value of the data read from the record)
58 59 60 |
# File 'app/components/katalyst/tables/cell_component.rb', line 58 def value @data&.value end |
#with_content_wrapper(component) ⇒ Object
Adds a component to wrap the content of the cell, similar to a layout in Rails views.
32 33 34 35 36 |
# File 'app/components/katalyst/tables/cell_component.rb', line 32 def with_content_wrapper(component) @content_wrapper = component self end |