Class: ActiveAdmin::Axlsx::Builder
- Inherits:
-
Object
- Object
- ActiveAdmin::Axlsx::Builder
- Includes:
- MethodOrProcHelper
- Defined in:
- lib/active_admin/axlsx/builder.rb
Overview
Builder for xlsx data using the axlsx gem.
Defined Under Namespace
Classes: Column
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
The collection we are serializing.
-
#columns ⇒ Object
readonly
The columns this builder will be serializing.
Instance Method Summary collapse
-
#after_filter(&block) ⇒ Object
The stored block that will be executed after your report is generated.
-
#before_filter(&block) ⇒ Object
the stored block that will be executed before your report is generated.
-
#clear_columns ⇒ Object
removes all columns from the builder.
-
#column(name, &block) ⇒ Object
Add a column.
-
#delete_columns(*column_names) ⇒ Object
removes columns by name each column_name should be a symbol.
-
#header_style ⇒ Hash
The default header style.
-
#header_style=(style_hash) ⇒ Object
This has can be used to override the default header style for your sheet.
-
#i18n_scope ⇒ Object
The scope to use when looking up column names to generate the report header.
-
#i18n_scope=(scope) ⇒ Object
This is the I18n scope that will be used when looking up your colum names in the current I18n locale.
-
#initialize(resource_class, options = {}, &block) ⇒ Builder
constructor
A new instance of Builder.
-
#serialize(collection) ⇒ Axlsx::Package
Serializes the collection provided.
Constructor Details
#initialize(resource_class, options = {}, &block) ⇒ Builder
Returns a new instance of Builder.
43 44 45 46 47 |
# File 'lib/active_admin/axlsx/builder.rb', line 43 def initialize(resource_class, ={}, &block) @columns = resource_columns(resource_class) instance_eval &block if block_given? end |
Instance Attribute Details
#collection ⇒ Object (readonly)
This is only available after serialize has been called,
The collection we are serializing. and is reset on each subsequent call.
95 96 97 |
# File 'lib/active_admin/axlsx/builder.rb', line 95 def collection @collection end |
#columns ⇒ Object (readonly)
The columns this builder will be serializing
90 91 92 |
# File 'lib/active_admin/axlsx/builder.rb', line 90 def columns @columns end |
Instance Method Details
#after_filter(&block) ⇒ Object
The stored block that will be executed after your report is generated.
80 81 82 |
# File 'lib/active_admin/axlsx/builder.rb', line 80 def after_filter(&block) @after_filter = block end |
#before_filter(&block) ⇒ Object
the stored block that will be executed before your report is generated.
85 86 87 |
# File 'lib/active_admin/axlsx/builder.rb', line 85 def before_filter(&block) @before_filter = block end |
#clear_columns ⇒ Object
removes all columns from the builder. This is useful when you want to only render specific columns. To remove specific columns use ignore_column.
99 100 101 |
# File 'lib/active_admin/axlsx/builder.rb', line 99 def clear_columns @columns = [] end |
#column(name, &block) ⇒ Object
Add a column
107 108 109 |
# File 'lib/active_admin/axlsx/builder.rb', line 107 def column(name, &block) @columns << Column.new(name, block) end |
#delete_columns(*column_names) ⇒ Object
removes columns by name each column_name should be a symbol
113 114 115 |
# File 'lib/active_admin/axlsx/builder.rb', line 113 def delete_columns(*column_names) @columns.delete_if { |column| column_names.include?(column.name) } end |
#header_style ⇒ Hash
The default header style
51 52 53 |
# File 'lib/active_admin/axlsx/builder.rb', line 51 def header_style @header_style ||= { :bg_color => '00', :fg_color => 'FF', :sz => 12, :alignment => { :horizontal => :center } } end |
#header_style=(style_hash) ⇒ Object
This has can be used to override the default header style for your sheet. Any values you provide will be merged with the default styles. Precidence is given to your hash create and apply style.
60 61 62 |
# File 'lib/active_admin/axlsx/builder.rb', line 60 def header_style=(style_hash) @header_style = header_style.merge(style_hash) end |
#i18n_scope ⇒ Object
The scope to use when looking up column names to generate the report header
65 66 67 |
# File 'lib/active_admin/axlsx/builder.rb', line 65 def i18n_scope @i18n_scope ||= nil end |
#i18n_scope=(scope) ⇒ Object
If you do not set this, the column name will be titleized.
This is the I18n scope that will be used when looking up your colum names in the current I18n locale. If you set it to [:active_admin, :resources, :posts] the serializer will render the value at active_admin.resources.posts.title in the current translations
75 76 77 |
# File 'lib/active_admin/axlsx/builder.rb', line 75 def i18n_scope=(scope) @i18n_scope = scope end |
#serialize(collection) ⇒ Axlsx::Package
Serializes the collection provided
119 120 121 122 123 124 125 |
# File 'lib/active_admin/axlsx/builder.rb', line 119 def serialize(collection) @collection = collection apply_filter @before_filter export_collection(collection) apply_filter @after_filter to_stream end |