Skip to content

Commit

Permalink
add byte order mark option to csv
Browse files Browse the repository at this point in the history
  • Loading branch information
timoschilling committed Nov 13, 2014
1 parent b8c5f5a commit b9ad04e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@

* Unify DSL for index `actions` and `actions dropdown: true` [#3463][] by [@timoschilling][]
* Add DSL method `includes` for `ActiveRecord::Relation#includes` [#3464][] by [@timoschilling][]
* BOM (byte order mark) configurable for CSV download [#3519][] by [@timoschilling][]
* Column block on table index is now sortable by default [#3075][] by [@dmitry][]
* Allow Arbre to be used inside ActiveAdmin forms [#3486][] by [@varyonic][]
* Make AA ORM-agnostic [#2545][] by [@johnnyshields][]
Expand Down Expand Up @@ -976,6 +977,7 @@ of the highlights. 250 commits. Enough said.
[#3463]: https://github.com/activeadmin/activeadmin/issues/3463
[#3464]: https://github.com/activeadmin/activeadmin/issues/3464
[#3486]: https://github.com/activeadmin/activeadmin/issues/3486
[#3519]: https://github.com/activeadmin/activeadmin/issues/3519
[@Bishop]: https://github.com/Bishop
[@BoboFraggins]: https://github.com/BoboFraggins
[@DMajrekar]: https://github.com/DMajrekar
Expand Down
2 changes: 1 addition & 1 deletion features/index/format_as_csv.feature
Expand Up @@ -65,7 +65,7 @@ Feature: Format as CSV
Given a configuration of:
"""
ActiveAdmin.register Post do
csv :force_quotes => true do
csv :force_quotes => true, :byte_order_mark => "" do
column :title
column :body
end
Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin/application.rb
Expand Up @@ -71,7 +71,7 @@ def initialize
inheritable_setting :breadcrumb, true

# Default CSV options
inheritable_setting :csv_options, {col_sep: ','}
inheritable_setting :csv_options, { col_sep: ',', byte_order_mark: "\xEF\xBB\xBF" }

# Default Download Links options
inheritable_setting :download_links, true
Expand Down
4 changes: 4 additions & 0 deletions lib/active_admin/csv_builder.rb
Expand Up @@ -44,6 +44,10 @@ def build(controller, receiver)
options = ActiveAdmin.application.csv_options.merge self.options
columns = exec_columns controller.view_context

if byte_order_mark = options.delete(:byte_order_mark)
receiver << byte_order_mark
end

if options.delete(:column_names) { true }
receiver << CSV.generate_line(columns.map{ |c| encode c.name, options }, options)
end
Expand Down

0 comments on commit b9ad04e

Please sign in to comment.