From 38699c38522ce3cd16e2b0c64b647b32264a9460 Mon Sep 17 00:00:00 2001 From: DannyB Date: Fri, 11 Mar 2016 21:58:05 +0000 Subject: [PATCH 1/4] add option to prepend utf8 bom --- lib/comma.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/comma.rb b/lib/comma.rb index 2167946..e37f741 100644 --- a/lib/comma.rb +++ b/lib/comma.rb @@ -46,9 +46,12 @@ module Comma filename = options[:filename] || 'data' extension = options[:extension] || 'csv' mime_type = options[:mime_type] || Mime::CSV + add_bom = options[:add_bom] || false #Capture any CSV optional settings passed to comma or comma specific options csv_options = options.slice(*CSV_HANDLER::DEFAULT_OPTIONS.merge(Comma::DEFAULT_OPTIONS).keys) - send_data obj.to_comma(csv_options), :type => mime_type, :disposition => "attachment; filename=\"#{filename}.#{extension}\"" + data = obj.to_comma(csv_options) + data = "\xEF\xBB\xBF#{data}" if add_bom + send_data data, :type => mime_type, :disposition => "attachment; filename=\"#{filename}.#{extension}\"" end end end From 3baaebecd95f901bcd3e9ce157e9fb56929e30fa Mon Sep 17 00:00:00 2001 From: DannyB Date: Wed, 29 Jun 2016 05:38:32 +0000 Subject: [PATCH 2/4] rename add_bom to with_bom --- lib/comma.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/comma.rb b/lib/comma.rb index e37f741..fb95cf5 100644 --- a/lib/comma.rb +++ b/lib/comma.rb @@ -46,11 +46,11 @@ module Comma filename = options[:filename] || 'data' extension = options[:extension] || 'csv' mime_type = options[:mime_type] || Mime::CSV - add_bom = options[:add_bom] || false + with_bom = options[:with_bom] || false #Capture any CSV optional settings passed to comma or comma specific options csv_options = options.slice(*CSV_HANDLER::DEFAULT_OPTIONS.merge(Comma::DEFAULT_OPTIONS).keys) data = obj.to_comma(csv_options) - data = "\xEF\xBB\xBF#{data}" if add_bom + data = "\xEF\xBB\xBF#{data}" if with_bom send_data data, :type => mime_type, :disposition => "attachment; filename=\"#{filename}.#{extension}\"" end end From 97d90bdca36db5b5686bd3b3d8948da1e554ca8b Mon Sep 17 00:00:00 2001 From: DannyB Date: Wed, 29 Jun 2016 05:50:35 +0000 Subject: [PATCH 3/4] add spec for with_bom --- spec/controllers/users_controller_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 1258844..51d67bd 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -103,6 +103,18 @@ response.content_type.should == 'text/plain' end + it 'should allow bom to be set' do + get :with_custom_options, :format => :csv, :custom_options => { :with_bom => true } + + expected_content =<<-CSV.gsub(/^\s+/,'') + \xEF\xBB\xBFFirst name,Last name + Fred,Flintstone + Wilma,Flintstone + CSV + + response.body.should == expected_content + end + describe 'headers' do it 'should allow toggling on' do From d103d6ebd60c657f375e663c7da2a30487fdf374 Mon Sep 17 00:00:00 2001 From: DannyB Date: Wed, 29 Jun 2016 05:55:04 +0000 Subject: [PATCH 4/4] bundle update sqlite3 --- Gemfile.lock | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 01dfe5f..5fe7343 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -46,7 +46,7 @@ GEM multi_json (~> 1.0) simplecov-html (~> 0.9.0) simplecov-html (0.9.0) - sqlite3 (1.3.5) + sqlite3 (1.3.11) thor (0.19.1) PLATFORMS @@ -61,3 +61,6 @@ DEPENDENCIES rest-client (> 1.6.2, < 1.7) rspec (~> 2.8.0) sqlite3 (~> 1.3.4) + +BUNDLED WITH + 1.12.5