Module: ActiveAdmin::Xls::DSL

Defined in:
lib/active_admin/xls/dsl.rb

Overview

Extends activeadmin dsl to include xls

Instance Method Summary collapse

Instance Method Details

#xls(options = {}, &block) ⇒ Object

Creates a default XLS Builder to respond to xls requests for this resource. Options are passed to the Builder initialize method.

Examples:

Using the DSL

xls(i18n_scope: [:active_admin, :xls, :post],
    header_format: { weight: :bold, color: :blue }) do
  # Specify that you want to white list column output.
  # whitelist

  # Do not serialize the header, only output data.
  # skip_header

  # restrict columns to a list without customization
  # only_columns :title, :author

  # deleting columns from the report
  delete_columns :id, :created_at, :updated_at

  # adding a column to the report with customization
  column(:author) do |post|
    "#{post.author.first_name} #{post.author.last_name}"
  end

  # inserting additional data with after_filter
  after_filter do |sheet|
    # todo
  end

  # inserting data with before_filter
  before_filter do |sheet|
    # todo
  end
end

Parameters:

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

    the options for the builder

  • block (Block)

    block given will evaluated against the instance of Builder. That means you can call any method on the builder from within that block.

Options Hash (options):

  • :header_format (Hash)

    a hash of format properties to apply to the header row. Any properties specified will be merged with the default header styles.

  • :i18n_scope (Array)

    the I18n scope to use when looking up localized column headers.

Returns:

  • A new instance of Builder

See Also:



65
66
67
68
69
70
71
# File 'lib/active_admin/xls/dsl.rb', line 65

def xls(options = {}, &block)
  config.xls_builder = ActiveAdmin::Xls::Builder.new(
    config.resource_class,
    options,
    &block
  )
end