Module: ActiveScaffold::Helpers::ExportHelpers
- Defined in:
- lib/active_scaffold/helpers/export_helpers.rb
Overview
Helpers that assist with the rendering of a Export Column
Instance Method Summary collapse
- #export_column_override(column) ⇒ Object
- #export_column_override?(column) ⇒ Boolean
- #format_export_column(raw_value) ⇒ Object
-
#format_export_column_header_name(column) ⇒ Object
This helper can be overridden to change the way that the headers are formatted.
- #format_plural_association_export_column(association_records) ⇒ Object
- #format_singular_association_export_column(association_record) ⇒ Object
-
#get_export_column_value(record, column) ⇒ Object
individual columns can be overridden by defining a helper method <column_name>_export_column(record) You can customize the output of all columns by overriding the following helper methods: format_export_column(raw_value) format_singular_association_export_column(association_record) format_plural_association_export_column(association_records).
Instance Method Details
#export_column_override(column) ⇒ Object
31 32 33 |
# File 'lib/active_scaffold/helpers/export_helpers.rb', line 31 def export_column_override(column) "#{column.name.to_s.gsub('?', '')}_export_column" # parse out any question marks (see issue 227) end |
#export_column_override?(column) ⇒ Boolean
35 36 37 |
# File 'lib/active_scaffold/helpers/export_helpers.rb', line 35 def export_column_override?(column) respond_to?(export_column_override(column)) end |
#format_export_column(raw_value) ⇒ Object
39 40 41 |
# File 'lib/active_scaffold/helpers/export_helpers.rb', line 39 def format_export_column(raw_value) format_value(raw_value) end |
#format_export_column_header_name(column) ⇒ Object
This helper can be overridden to change the way that the headers are formatted. For instance, you might want column.name.to_s.humanize
55 56 57 |
# File 'lib/active_scaffold/helpers/export_helpers.rb', line 55 def format_export_column_header_name(column) column.name.to_s end |
#format_plural_association_export_column(association_records) ⇒ Object
47 48 49 50 51 |
# File 'lib/active_scaffold/helpers/export_helpers.rb', line 47 def format_plural_association_export_column(association_records) firsts = association_records.first(4).collect { |v| v.to_label } firsts[3] = ' ' if firsts.length == 4 format_value(firsts.join(',')) end |
#format_singular_association_export_column(association_record) ⇒ Object
43 44 45 |
# File 'lib/active_scaffold/helpers/export_helpers.rb', line 43 def format_singular_association_export_column(association_record) format_value(association_record.to_label) end |
#get_export_column_value(record, column) ⇒ Object
individual columns can be overridden by defining a helper method <column_name>_export_column(record) You can customize the output of all columns by overriding the following helper methods: format_export_column(raw_value) format_singular_association_export_column(association_record) format_plural_association_export_column(association_records)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/active_scaffold/helpers/export_helpers.rb', line 12 def get_export_column_value(record, column) if export_column_override? column send(export_column_override(column), record) else raw_value = record.send(column.name) if column.association.nil? or column_empty?(raw_value) format_export_column(raw_value) else case column.association.macro when :has_one, :belongs_to format_singular_association_export_column(raw_value) when :has_many, :has_and_belongs_to_many format_plural_association_export_column(raw_value) end end end end |