Module: Recourse::Helpers::Cells
- Included in:
- Recourse::Helpers
- Defined in:
- lib/recourse/helpers/cells.rb
Overview
Helpers for the cells of a table and the fields of a form.
Constant Summary collapse
- TIME_FORMAT =
How a time reads on a page, e.g. 'Aug 4 at 03:47pm EDT'.
'%b %-d at %I:%M%P %Z'
Instance Method Summary collapse
-
#column(header:) ⇒ Object
One cell: a heading in the header row, the block's output in every other.
-
#editable_columns ⇒ Object
Columns a form offers, the same list
createpermits. -
#resource_cell(resource, column) ⇒ Object
Value for one cell, formatted according to what the column holds.
-
#resource_column_title(column) ⇒ Object
Heading for a column, which a host app can translate like any attribute.
-
#resource_columns ⇒ Object
Columns the table shows: every attribute that is not encrypted.
Instance Method Details
#column(header:) ⇒ Object
One cell: a heading in the header row, the block's output in every other.
37 38 39 40 41 |
# File 'lib/recourse/helpers/cells.rb', line 37 def column(header:, **, &) return tag.th(header, scope: :col, **) if @recourse_headers tag.td(capture(&), 'data-cell': header, **) end |
#editable_columns ⇒ Object
Columns a form offers, the same list create permits.
14 15 16 |
# File 'lib/recourse/helpers/cells.rb', line 14 def editable_columns Recourse.editable_columns resource_model end |
#resource_cell(resource, column) ⇒ Object
Value for one cell, formatted according to what the column holds.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/recourse/helpers/cells.rb', line 24 def resource_cell(resource, column) association = belongs_to_association column return reference_cell resource, association if association value = resource.attributes[column] return time_tag value, value.strftime(TIME_FORMAT) if value.is_a? Time return number_to_phone value if column == 'phone' value end |
#resource_column_title(column) ⇒ Object
Heading for a column, which a host app can translate like any attribute.
19 20 21 |
# File 'lib/recourse/helpers/cells.rb', line 19 def resource_column_title(column) resource_model.human_attribute_name column end |
#resource_columns ⇒ Object
Columns the table shows: every attribute that is not encrypted.
9 10 11 |
# File 'lib/recourse/helpers/cells.rb', line 9 def resource_columns resource_model.column_names - Array(resource_model.encrypted_attributes).map(&:to_s) end |