module ActiveScaffold::Helpers::ExportHelpers
Helpers
that assist with the rendering of a Export Column
Public Instance Methods
export_column_override(column)
click to toggle source
# File lib/active_scaffold/helpers/export_helpers.rb, line 30 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)
click to toggle source
# File lib/active_scaffold/helpers/export_helpers.rb, line 34 def export_column_override?(column) respond_to?(export_column_override(column)) end
format_export_column(raw_value)
click to toggle source
# File lib/active_scaffold/helpers/export_helpers.rb, line 38 def format_export_column(raw_value) format_value_for_csv(raw_value) end
format_export_column_header_name(column)
click to toggle source
This helper can be overridden to change the way that the headers
are formatted. For instance, you might want column.name.to_s.humanize
# File lib/active_scaffold/helpers/export_helpers.rb, line 66 def format_export_column_header_name(column) column.label end
format_plural_association_export_column(association_records)
click to toggle source
# File lib/active_scaffold/helpers/export_helpers.rb, line 58 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)
click to toggle source
# File lib/active_scaffold/helpers/export_helpers.rb, line 54 def format_singular_association_export_column(association_record) format_value(association_record.to_label) end
format_value_for_csv(column_value)
click to toggle source
# File lib/active_scaffold/helpers/export_helpers.rb, line 42 def format_value_for_csv(column_value) value = if column_empty?(column_value) active_scaffold_config.list.empty_field_text elsif column_value.is_a?(Time) || column_value.is_a?(Date) l(column_value, :format => :default) elsif [FalseClass, TrueClass].include?(column_value.class) as_(column_value.to_s.to_sym) else column_value.to_s end end
get_export_column_value(record, column, csv = true)
click to toggle source
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)
# File lib/active_scaffold/helpers/export_helpers.rb, line 12 def get_export_column_value(record, column, csv = true) 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) csv ? format_export_column(raw_value) : raw_value # xlsx needs original data type elsif column.association if column.association.collection? format_plural_association_export_column(raw_value) else format_singular_association_export_column(raw_value) end end end end