Module: ActiveScaffold::Helpers::ShowColumnHelpers
- Included in:
- ViewHelpers
- Defined in:
- lib/active_scaffold/helpers/show_column_helpers.rb
Overview
Helpers that assist with the rendering of a List Column
Instance Method Summary collapse
- #active_scaffold_show_horizontal(record, column, ui_options: column.options) ⇒ Object
- #active_scaffold_show_text(record, column, ui_options: column.options) ⇒ Object
- #active_scaffold_show_vertical(record, column, ui_options: column.options) ⇒ Object
- #display_link_in_show?(link, position) ⇒ Boolean
-
#override_show_column_ui(show_ui) ⇒ Object
the naming convention for overriding show types with helpers.
- #show_column_override(column) ⇒ Object
- #show_column_value(record, column, **tab_options) ⇒ Object
- #show_columns_for(record, parent_column = nil, hash = {}) ⇒ Object
- #show_label(column) ⇒ Object
Instance Method Details
#active_scaffold_show_horizontal(record, column, ui_options: column.options) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/active_scaffold/helpers/show_column_helpers.rb', line 31 def active_scaffold_show_horizontal(record, column, ui_options: column.) raise ArgumentError, ':horizontal show_ui must be used on association column' unless column.association vars = {column: column, parent_record: record, show_partial: :horizontal} render partial: 'show_association', locals: vars.merge(.slice(:tabbed_by, :tab_value, :tab_id)) end |
#active_scaffold_show_text(record, column, ui_options: column.options) ⇒ Object
27 28 29 |
# File 'lib/active_scaffold/helpers/show_column_helpers.rb', line 27 def active_scaffold_show_text(record, column, ui_options: column.) simple_format(clean_column_value(record.send(column.name)), [:html_options], ) end |
#active_scaffold_show_vertical(record, column, ui_options: column.options) ⇒ Object
38 39 40 41 42 |
# File 'lib/active_scaffold/helpers/show_column_helpers.rb', line 38 def active_scaffold_show_vertical(record, column, ui_options: column.) raise ArgumentError, ':vertical show_ui must be used on association column' unless column.association render partial: 'show_association', locals: {column: column, parent_record: record, show_partial: :vertical} end |
#display_link_in_show?(link, position) ⇒ Boolean
66 67 68 |
# File 'lib/active_scaffold/helpers/show_column_helpers.rb', line 66 def display_link_in_show?(link, position) position == :header end |
#override_show_column_ui(show_ui) ⇒ Object
the naming convention for overriding show types with helpers
61 62 63 64 |
# File 'lib/active_scaffold/helpers/show_column_helpers.rb', line 61 def override_show_column_ui(show_ui) method = "active_scaffold_show_#{show_ui}" method if respond_to? method end |
#show_column_override(column) ⇒ Object
56 57 58 |
# File 'lib/active_scaffold/helpers/show_column_helpers.rb', line 56 def show_column_override(column) override_helper column, 'show_column' end |
#show_column_value(record, column, **tab_options) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/active_scaffold/helpers/show_column_helpers.rb', line 7 def show_column_value(record, column, **) value_record = column.delegated_association ? record.send(column.delegated_association.name) : record return get_column_value(record, column) unless value_record # check for an override helper if (method = show_column_override(column)) # we only pass the record as the argument. we previously also passed the formatted_value, # but mike perham pointed out that prohibited the usage of overrides to improve on the # performance of our default formatting. see issue #138. send(method, value_record, column) # second, check if the dev has specified a valid list_ui for this column elsif column.show_ui && (method = override_show_column_ui(column.show_ui)) send(method, value_record, column, ui_options: .merge(column. || column.)) elsif column.column && (method = override_show_column_ui(column.column_type)) # rubocop:disable Lint/DuplicateBranch send(method, value_record, column) else get_column_value(value_record, column) end end |
#show_columns_for(record, parent_column = nil, hash = {}) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/active_scaffold/helpers/show_column_helpers.rb', line 44 def show_columns_for(record, parent_column = nil, hash = {}) hash[record.class] ||= begin columns = active_scaffold_config_for(record.class).show.columns columns.constraint_columns = [parent_column.association.reverse] if parent_column columns end end |
#show_label(column) ⇒ Object
52 53 54 |
# File 'lib/active_scaffold/helpers/show_column_helpers.rb', line 52 def show_label(column) column.label end |