Class: Koi::Tables::BodyRowComponent

Inherits:
Katalyst::Tables::BodyRowComponent
  • Object
show all
Defined in:
app/components/koi/tables/body_row_component.rb

Overview

Custom body row component, in order to override the default body cell component

Instance Method Summary collapse

Instance Method Details

#attachment(method, variant: :thumb, **attributes, &block) ⇒ void

This method returns an undefined value.

Generates a column that renders an ActiveStorage attachment as a downloadable link.

Examples:

Render a column containing a download link to the record’s background image

<% row.attachment :background %> # => <td><a href="...">background.png</a></td>

Parameters:

  • method (Symbol)

    the method to call on the record

  • variant (Symbol) (defaults to: :thumb)

    the variant to use when rendering the image (default :thumb)

  • attributes (Hash)

    HTML attributes to be added to the cell tag

  • block (Proc)

    optional block to alter the cell content



137
138
139
# File 'app/components/koi/tables/body_row_component.rb', line 137

def attachment(method, variant: :thumb, **attributes, &block)
  with_column(Body::AttachmentComponent.new(@table, @record, method, variant:, **attributes), &block)
end

#boolean(method, **attributes, &block) ⇒ void

This method returns an undefined value.

Generates a column from boolean values rendered as “Yes” or “No”.

Examples:

Render a boolean column indicating whether the record is active

<% row.boolean :active %> # => <td>Yes</td>

Parameters:

  • method (Symbol)

    the method to call on the record

  • attributes (Hash)

    HTML attributes to be added to the cell

  • block (Proc)

    optional block to alter the cell content



16
17
18
# File 'app/components/koi/tables/body_row_component.rb', line 16

def boolean(method, **attributes, &block)
  with_column(Body::BooleanComponent.new(@table, @record, method, **attributes), &block)
end

#currency(method, options: {}, **attributes, &block) ⇒ void

This method returns an undefined value.

Generates a column from numeric values rendered using ‘number_to_currency`.

Examples:

Render a currency column for the price of a product

<% row.currency :price %> # => <td>$3.50</td>

Parameters:

  • method (Symbol)

    the method to call on the record

  • options (Hash) (defaults to: {})

    options to be passed to ‘number_to_currency`

  • attributes (Hash)

    HTML attributes to be added to the cell tag

  • block (Proc)

    optional block to alter the cell content



73
74
75
# File 'app/components/koi/tables/body_row_component.rb', line 73

def currency(method, options: {}, **attributes, &block)
  with_column(Body::CurrencyComponent.new(@table, @record, method, options:, **attributes), &block)
end

#date(method, format: :admin, **attributes, &block) ⇒ void

This method returns an undefined value.

Generates a column from date values rendered using I18n.l. The default format is :admin, but it can be overridden.

Examples:

Render a date column describing when the record was created

<% row.date :created_at %> # => <td>29 Feb 2024</td>

Parameters:

  • method (Symbol)

    the method to call on the record

  • format (Symbol) (defaults to: :admin)

    the I18n date format to use when rendering

  • attributes (Hash)

    HTML attributes to be added to the cell tag

  • block (Proc)

    optional block to alter the cell content



31
32
33
# File 'app/components/koi/tables/body_row_component.rb', line 31

def date(method, format: :admin, **attributes, &block)
  with_column(Body::DateComponent.new(@table, @record, method, format:, **attributes), &block)
end

#datetime(method, format: :admin, **attributes, &block) ⇒ void

This method returns an undefined value.

Generates a column from datetime values rendered using I18n.l. The default format is :admin, but it can be overridden.

Examples:

Render a datetime column describing when the record was created

<% row.datetime :created_at %> # => <td>29 Feb 2024, 5:00pm</td>

Parameters:

  • method (Symbol)

    the method to call on the record

  • format (Symbol) (defaults to: :admin)

    the I18n datetime format to use when rendering

  • attributes (Hash)

    HTML attributes to be added to the cell tag

  • block (Proc)

    optional block to alter the cell content



46
47
48
# File 'app/components/koi/tables/body_row_component.rb', line 46

def datetime(method, format: :admin, **attributes, &block)
  with_column(Body::DatetimeComponent.new(@table, @record, method, format:, **attributes), &block)
end

This method returns an undefined value.

Generates a column that links to the record’s show page (by default).

or a symbol to be passed to the route helper

Examples:

Render a column containing the record’s title, linked to its show page

<% row.link :title %> # => <td><a href="/admin/post/15">About us</a></td>

Render a column containing the record’s title, linked to its edit page

<% row.link :title, url: :edit_admin_post_path do |cell| %>
   Edit <%= cell %>
<% end %>
# => <td><a href="/admin/post/15/edit">Edit About us</a></td>

Parameters:

  • method (Symbol)

    the method to call on the record

  • link (Hash) (defaults to: {})

    options to be passed to the link_to helper

  • attributes (Hash)

    HTML attributes to be added to the cell tag

  • block (Proc)

    optional block to alter the cell content

  • opts (Hash)

    a customizable set of options



110
111
112
# File 'app/components/koi/tables/body_row_component.rb', line 110

def link(method, url: [:admin, @record], link: {}, **attributes, &block)
  with_column(Body::LinkComponent.new(@table, @record, method, url:, link:, **attributes), &block)
end

#number(method, **attributes, &block) ⇒ void

This method returns an undefined value.

Generates a column from numeric values formatted appropriately.

Examples:

Render the number of comments on a post

<% row.number :comment_count %> # => <td>0</td>

Parameters:

  • method (Symbol)

    the method to call on the record

  • attributes (Hash)

    HTML attributes to be added to the cell tag

  • block (Proc)

    optional block to alter the cell content



59
60
61
# File 'app/components/koi/tables/body_row_component.rb', line 59

def number(method, **attributes, &block)
  with_column(Body::NumberComponent.new(@table, @record, method, **attributes), &block)
end

#rich_text(method, **attributes, &block) ⇒ void

Note:

This method assumes that the method returns HTML-safe content. If the content is not HTML-safe, it will be escaped.

This method returns an undefined value.

Generates a column containing HTML markup.

Examples:

Render a description column containing HTML markup

<% row.rich_text :description %> # => <td><em>Emphasis</em></td>

Parameters:

  • method (Symbol)

    the method to call on the record

  • attributes (Hash)

    HTML attributes to be added to the cell tag

  • block (Proc)

    optional block to alter the cell content



89
90
91
# File 'app/components/koi/tables/body_row_component.rb', line 89

def rich_text(method, **attributes, &block)
  with_column(Body::RichTextComponent.new(@table, @record, method, **attributes), &block)
end

#text(method, **attributes, &block) ⇒ void

This method returns an undefined value.

Generates a column that renders the contents as text.

Examples:

Render a column containing the record’s title

<% row.text :title %> # => <td>About us</td>

Parameters:

  • method (Symbol)

    the method to call on the record

  • attributes (Hash)

    HTML attributes to be added to the cell tag

  • block (Proc)

    optional block to alter the cell content



123
124
125
# File 'app/components/koi/tables/body_row_component.rb', line 123

def text(method, **attributes, &block)
  with_column(BodyCellComponent.new(@table, @record, method, **attributes), &block)
end