csv_builder 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +8 -0
- data/Gemfile +3 -0
- data/README.md +4 -5
- data/Rakefile +2 -28
- data/VERSION +1 -1
- data/{csv_streamer.gemspec → csv_builder.gemspec} +10 -36
- data/lib/csv_builder.rb +1 -1
- data/lib/csv_builder/template_handler.rb +24 -24
- data/lib/csv_builder/transliterating_filter.rb +44 -12
- metadata +44 -48
- data/spec/controllers/csv_builder_spec.rb +0 -87
- data/spec/rails_app/.gitignore +0 -5
- data/spec/rails_app/Gemfile +0 -7
- data/spec/rails_app/README +0 -1
- data/spec/rails_app/app/controllers/application_controller.rb +0 -3
- data/spec/rails_app/app/helpers/application_helper.rb +0 -2
- data/spec/rails_app/app/views/layouts/application.html.erb +0 -14
- data/spec/rails_app/config.ru +0 -4
- data/spec/rails_app/config/application.rb +0 -42
- data/spec/rails_app/config/boot.rb +0 -6
- data/spec/rails_app/config/database.yml +0 -22
- data/spec/rails_app/config/environment.rb +0 -5
- data/spec/rails_app/config/environments/development.rb +0 -26
- data/spec/rails_app/config/environments/production.rb +0 -49
- data/spec/rails_app/config/environments/test.rb +0 -35
- data/spec/rails_app/config/routes.rb +0 -58
- data/spec/rails_app/db/seeds.rb +0 -7
- data/spec/spec_helper.rb +0 -22
- data/spec/templates/csv_builder_reports/complex.csv.csvbuilder +0 -3
- data/spec/templates/csv_builder_reports/encoding.csv.csvbuilder +0 -1
- data/spec/templates/csv_builder_reports/massive.csv.csvbuilder +0 -3
- data/spec/templates/csv_builder_reports/simple.csv.csvbuilder +0 -1
- data/spec/templates/csv_builder_reports/simple.html.erb +0 -1
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
== 2.1.1 release 2012-07-15
|
2
|
+
|
3
|
+
* Fix deprecation warning in 1.9 by removing iconv dependency (Joel Chippendale)
|
4
|
+
* Change name of default output encoding for 1.9 encoding support (Joel Chippendale)
|
5
|
+
* Add Gemfile for development (Joel Chippendale)
|
6
|
+
* Fix for IE under SSL (tkiley)
|
7
|
+
* Fix for filenames with spaces. (Ramihajamalala Hery)
|
8
|
+
|
1
9
|
== 2.1.0 release 2011-11-25
|
2
10
|
* Implemented streaming support. (fawce.com)
|
3
11
|
* Temporarily renamed to csv_streamer to facilitate publishing to rubygems. (fawce.com)
|
data/Gemfile
ADDED
data/README.md
CHANGED
@@ -26,8 +26,6 @@ docs](https://github.com/econsultancy/csv_builder) for more details.
|
|
26
26
|
### Install as a gem (recommended)
|
27
27
|
|
28
28
|
$ gem install csv_builder
|
29
|
-
_or for streaming_
|
30
|
-
$ gem install csv_streamer
|
31
29
|
|
32
30
|
If you are using Bundler then [you know what to do](http://gembundler.com).
|
33
31
|
|
@@ -51,7 +49,7 @@ your controller's action method e.g.
|
|
51
49
|
@filename = 'report.csv'
|
52
50
|
|
53
51
|
You can set the input encoding and output encoding by setting `@input_encoding` and `@output_encoding` instance
|
54
|
-
variables. These default to 'UTF-8' and '
|
52
|
+
variables. These default to 'UTF-8' and 'ISO-8859-1' respectively. e.g.
|
55
53
|
|
56
54
|
@output_encoding = 'UTF-8'
|
57
55
|
|
@@ -60,8 +58,8 @@ You can set `@csv_options` instance variable to define options for FasterCSV gen
|
|
60
58
|
@csv_options = { :force_quotes => true, :col_sep => ';' }
|
61
59
|
|
62
60
|
You can optionally stream your results line by line as they are generated. Results will stream if the underlying Rack server supports streaming, otherwise the results will be buffered and sent when the template finishes rendering. Just set `@streaming` to true:
|
63
|
-
|
64
|
-
|
61
|
+
|
62
|
+
@streaming = true
|
65
63
|
|
66
64
|
You can respond with csv in your controller as well:
|
67
65
|
|
@@ -79,6 +77,7 @@ including a snippet like the following in your mailer method
|
|
79
77
|
end
|
80
78
|
|
81
79
|
## Streaming Support
|
80
|
+
|
82
81
|
Many csv files are quite large, and need to be streamed rather than return in a single shot. Csv stream handling is based on [an epic answer on stackoverflow about rails and streaming.](http://stackoverflow.com/questions/3507594/ruby-on-rails-3-streaming-data-through-rails-to-client). Streaming requires configuration of your rails app - you need to use a Rack that supports streaming. I've tested with Unicorn, and created [a separate sample](https://github.com/fawce/test_csv_streamer) project to facilitate testing on Heroku.
|
83
82
|
|
84
83
|
|
data/Rakefile
CHANGED
@@ -1,14 +1,13 @@
|
|
1
|
-
require '
|
1
|
+
require 'rdoc/task'
|
2
2
|
require 'rspec/core'
|
3
3
|
require 'rspec/core/rake_task'
|
4
|
-
require 'jeweler'
|
5
4
|
|
6
5
|
desc 'Generate documentation for the csv_builder plugin.'
|
7
6
|
Rake::RDocTask.new(:rdoc) do |rdoc|
|
8
7
|
rdoc.rdoc_dir = 'rdoc'
|
9
8
|
rdoc.title = 'CSV Builder'
|
10
9
|
rdoc.options << '--line-numbers' << '--inline-source'
|
11
|
-
rdoc.rdoc_files.include('README.
|
10
|
+
rdoc.rdoc_files.include('README.md')
|
12
11
|
rdoc.rdoc_files.include('CHANGELOG.rdoc')
|
13
12
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
14
13
|
end
|
@@ -20,28 +19,3 @@ end
|
|
20
19
|
|
21
20
|
desc 'Default: run specs.'
|
22
21
|
task :default => :spec
|
23
|
-
|
24
|
-
Jeweler::Tasks.new do |gem|
|
25
|
-
gem.name = "csv_builder"
|
26
|
-
gem.homepage = "http://github.com/dasil003/csv_builder"
|
27
|
-
gem.license = "MIT"
|
28
|
-
gem.summary = %Q{CSV template handler for Rails}
|
29
|
-
gem.description = %Q{CSV template handler for Rails. Enables :format => 'csv' in controllers, with templates of the form report.csv.csvbuilder.}
|
30
|
-
gem.email = "gabe@websaviour.com"
|
31
|
-
gem.authors = ['Econsultancy', 'Vidmantas Kabosis', "Gabe da Silveira"]
|
32
|
-
|
33
|
-
gem.files.exclude 'spec'
|
34
|
-
|
35
|
-
gem.add_dependency 'actionpack', '>=3.0.0'
|
36
|
-
|
37
|
-
gem.add_development_dependency 'rails', '>= 3.0.0'
|
38
|
-
gem.add_development_dependency 'rspec', '~> 2.5'
|
39
|
-
gem.add_development_dependency 'rspec-rails', '~> 2.5'
|
40
|
-
gem.add_development_dependency 'jeweler'
|
41
|
-
gem.add_development_dependency 'rack'
|
42
|
-
gem.add_development_dependency 'sqlite3'
|
43
|
-
|
44
|
-
gem.requirements << 'iconv'
|
45
|
-
gem.requirements << 'Ruby 1.9.x or FasterCSV'
|
46
|
-
end
|
47
|
-
Jeweler::RubygemsDotOrgTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.1.
|
1
|
+
2.1.1
|
@@ -1,15 +1,10 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
1
|
Gem::Specification.new do |s|
|
7
2
|
s.name = %q{csv_builder}
|
8
|
-
s.version = "2.
|
3
|
+
s.version = "2.1.1"
|
9
4
|
|
10
5
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = [%q{Econsultancy}, %q{Vidmantas Kabosis}, %q{Gabe da Silveira}
|
12
|
-
s.date = %q{
|
6
|
+
s.authors = [%q{Econsultancy}, %q{Vidmantas Kabosis}, %q{Gabe da Silveira}]
|
7
|
+
s.date = %q{2012-05-24}
|
13
8
|
s.description = %q{CSV template handler for Rails. Enables :format => 'csv' in controllers, with templates of the form report.csv.csvbuilder.}
|
14
9
|
s.email = %q{gabe@websaviour.com}
|
15
10
|
s.extra_rdoc_files = [
|
@@ -17,6 +12,7 @@ Gem::Specification.new do |s|
|
|
17
12
|
]
|
18
13
|
s.files = [
|
19
14
|
"CHANGELOG.rdoc",
|
15
|
+
"Gemfile",
|
20
16
|
"MIT-LICENSE",
|
21
17
|
"README.md",
|
22
18
|
"Rakefile",
|
@@ -26,34 +22,12 @@ Gem::Specification.new do |s|
|
|
26
22
|
"lib/csv_builder/railtie.rb",
|
27
23
|
"lib/csv_builder/template_handler.rb",
|
28
24
|
"lib/csv_builder/transliterating_filter.rb",
|
29
|
-
"rails/init.rb"
|
30
|
-
"spec/controllers/csv_builder_spec.rb",
|
31
|
-
"spec/rails_app/.gitignore",
|
32
|
-
"spec/rails_app/Gemfile",
|
33
|
-
"spec/rails_app/README",
|
34
|
-
"spec/rails_app/app/controllers/application_controller.rb",
|
35
|
-
"spec/rails_app/app/helpers/application_helper.rb",
|
36
|
-
"spec/rails_app/app/views/layouts/application.html.erb",
|
37
|
-
"spec/rails_app/config.ru",
|
38
|
-
"spec/rails_app/config/application.rb",
|
39
|
-
"spec/rails_app/config/boot.rb",
|
40
|
-
"spec/rails_app/config/database.yml",
|
41
|
-
"spec/rails_app/config/environment.rb",
|
42
|
-
"spec/rails_app/config/environments/development.rb",
|
43
|
-
"spec/rails_app/config/environments/production.rb",
|
44
|
-
"spec/rails_app/config/environments/test.rb",
|
45
|
-
"spec/rails_app/config/routes.rb",
|
46
|
-
"spec/rails_app/db/seeds.rb",
|
47
|
-
"spec/spec_helper.rb",
|
48
|
-
"spec/templates/csv_builder_reports/complex.csv.csvbuilder",
|
49
|
-
"spec/templates/csv_builder_reports/encoding.csv.csvbuilder",
|
50
|
-
"spec/templates/csv_builder_reports/simple.csv.csvbuilder",
|
51
|
-
"spec/templates/csv_builder_reports/simple.html.erb"
|
25
|
+
"rails/init.rb"
|
52
26
|
]
|
53
|
-
s.homepage = %q{
|
27
|
+
s.homepage = %q{http://github.com/dasil003/csv_builder}
|
54
28
|
s.licenses = [%q{MIT}]
|
55
29
|
s.require_paths = [%q{lib}]
|
56
|
-
s.requirements = [%q{iconv
|
30
|
+
s.requirements = [%q{iconv or Ruby 1.9}]
|
57
31
|
s.rubygems_version = %q{1.8.6}
|
58
32
|
s.summary = %q{CSV template handler for Rails}
|
59
33
|
|
@@ -62,27 +36,27 @@ Gem::Specification.new do |s|
|
|
62
36
|
|
63
37
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
64
38
|
s.add_runtime_dependency(%q<actionpack>, [">= 3.0.0"])
|
39
|
+
s.add_runtime_dependency('fastercsv') if RUBY_VERSION.to_f < 1.9
|
65
40
|
s.add_development_dependency(%q<rails>, [">= 3.0.0"])
|
66
41
|
s.add_development_dependency(%q<rspec>, ["~> 2.5"])
|
67
42
|
s.add_development_dependency(%q<rspec-rails>, ["~> 2.5"])
|
68
|
-
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
69
43
|
s.add_development_dependency(%q<rack>, [">= 0"])
|
70
44
|
s.add_development_dependency(%q<sqlite3>, [">= 0"])
|
71
45
|
else
|
72
46
|
s.add_dependency(%q<actionpack>, [">= 3.0.0"])
|
47
|
+
s.add_dependency('fastercsv') if RUBY_VERSION.to_f < 1.9
|
73
48
|
s.add_dependency(%q<rails>, [">= 3.0.0"])
|
74
49
|
s.add_dependency(%q<rspec>, ["~> 2.5"])
|
75
50
|
s.add_dependency(%q<rspec-rails>, ["~> 2.5"])
|
76
|
-
s.add_dependency(%q<jeweler>, [">= 0"])
|
77
51
|
s.add_dependency(%q<rack>, [">= 0"])
|
78
52
|
s.add_dependency(%q<sqlite3>, [">= 0"])
|
79
53
|
end
|
80
54
|
else
|
81
55
|
s.add_dependency(%q<actionpack>, [">= 3.0.0"])
|
56
|
+
s.add_dependency('fastercsv') if RUBY_VERSION.to_f < 1.9
|
82
57
|
s.add_dependency(%q<rails>, [">= 3.0.0"])
|
83
58
|
s.add_dependency(%q<rspec>, ["~> 2.5"])
|
84
59
|
s.add_dependency(%q<rspec-rails>, ["~> 2.5"])
|
85
|
-
s.add_dependency(%q<jeweler>, [">= 0"])
|
86
60
|
s.add_dependency(%q<rack>, [">= 0"])
|
87
61
|
s.add_dependency(%q<sqlite3>, [">= 0"])
|
88
62
|
end
|
data/lib/csv_builder.rb
CHANGED
@@ -5,13 +5,13 @@ module CsvBuilder
|
|
5
5
|
require 'csv'
|
6
6
|
CSV_LIB = CSV
|
7
7
|
else
|
8
|
+
require 'iconv'
|
8
9
|
require 'fastercsv'
|
9
10
|
CSV_LIB = FasterCSV
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
13
14
|
require 'action_view'
|
14
|
-
require 'iconv'
|
15
15
|
require 'csv_builder/transliterating_filter'
|
16
16
|
require 'csv_builder/template_handler'
|
17
17
|
require 'csv_builder/railtie'
|
@@ -19,7 +19,7 @@ module CsvBuilder # :nodoc:
|
|
19
19
|
#
|
20
20
|
# You can also set the input encoding and output encoding by setting
|
21
21
|
# <tt>@input_encoding</tt> and <tt>@output_encoding</tt> instance variables.
|
22
|
-
# These default to 'UTF-8' and '
|
22
|
+
# These default to 'UTF-8' and 'ISO-8859-1' respectively. e.g.
|
23
23
|
#
|
24
24
|
# @output_encoding = 'UTF-8'
|
25
25
|
|
@@ -28,7 +28,7 @@ module CsvBuilder # :nodoc:
|
|
28
28
|
include ActionView::Template::Handlers::Compilable
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
# The ruby csv class will try to infer a separator to use, if the csv options
|
33
33
|
# do not set it. ruby's csv calls pos, eof?, read, and rewind to check the first line
|
34
34
|
# of the io to infer a separator. Rails' output object does not support these methods
|
@@ -40,37 +40,37 @@ module CsvBuilder # :nodoc:
|
|
40
40
|
def initialize(yielder)
|
41
41
|
@yielder = yielder
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
# always indicate that we are at the start of the io stream
|
45
45
|
def pos
|
46
46
|
return 0
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
# always indicate that we have reached the end of the file
|
50
50
|
def eof?
|
51
51
|
return true
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
#do nothing, we haven't moved forward
|
55
55
|
def rewind
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
#despite indicating that we have no data with pos and eof, we still need to return a newline
|
59
59
|
#otherwise CSV will enter an infinite loop with read.
|
60
60
|
def read(arg1)
|
61
61
|
return "\n"
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
# this is the method that ultimately yields to the block with output.
|
65
65
|
# the block is passed by Rails into the Streamer class' each method.
|
66
|
-
# Streamer provides a Proc to this class, which simply invokes yield
|
66
|
+
# Streamer provides a Proc to this class, which simply invokes yield
|
67
67
|
# from within the context of the each block.
|
68
68
|
def <<(data)
|
69
69
|
@yielder.call data
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
# Streamer implements an each method to facilitate streaming back through the Rails stack. It requires
|
75
75
|
# the template to be passed to it as a proc. An instance of this class is returned from the template handler's
|
76
76
|
# compile method, and will receive calls to each. Data is streamed by yielding back to the containing block.
|
@@ -78,44 +78,44 @@ module CsvBuilder # :nodoc:
|
|
78
78
|
def initialize(template_proc)
|
79
79
|
@template_proc = template_proc
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
def each
|
83
83
|
yielder = CsvBuilder::Yielder.new(Proc.new{|data| yield data})
|
84
|
-
csv_stream = CsvBuilder::CSV_LIB.new(yielder, @csv_options || {})
|
85
|
-
csv = CsvBuilder::TransliteratingFilter.new(csv_stream, @input_encoding || 'UTF-8', @output_encoding || '
|
84
|
+
csv_stream = CsvBuilder::CSV_LIB.new(yielder, @csv_options || {})
|
85
|
+
csv = CsvBuilder::TransliteratingFilter.new(csv_stream, @input_encoding || 'UTF-8', @output_encoding || 'ISO-8859-1')
|
86
86
|
@template_proc.call(csv)
|
87
87
|
end
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
class TemplateHandler
|
91
91
|
def self.call(template)
|
92
|
-
|
92
|
+
|
93
93
|
<<-EOV
|
94
94
|
begin
|
95
|
-
|
95
|
+
|
96
96
|
unless defined?(ActionMailer) && defined?(ActionMailer::Base) && controller.is_a?(ActionMailer::Base)
|
97
97
|
@filename ||= "\#{controller.action_name}.csv"
|
98
98
|
if controller.request.env['HTTP_USER_AGENT'] =~ /msie/i
|
99
|
-
response.headers['Pragma'] = '
|
99
|
+
response.headers['Pragma'] = 'must-revalidate'
|
100
100
|
response.headers["Content-type"] = "text/plain"
|
101
|
-
response.headers['Cache-Control'] = '
|
102
|
-
response.headers['Content-Disposition'] = "attachment; filename
|
101
|
+
response.headers['Cache-Control'] = 'must-revalidate, post-check=0, pre-check=0'
|
102
|
+
response.headers['Content-Disposition'] = "attachment; filename=\\"\#{@filename}\\""
|
103
103
|
response.headers['Expires'] = "0"
|
104
104
|
else
|
105
105
|
response.headers["Content-Type"] ||= 'text/csv'
|
106
|
-
response.headers["Content-Disposition"] = "attachment; filename
|
106
|
+
response.headers["Content-Disposition"] = "attachment; filename=\\"\#{@filename}\\""
|
107
107
|
response.headers["Content-Transfer-Encoding"] = "binary"
|
108
108
|
end
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
if @streaming
|
112
112
|
template = Proc.new {|csv|
|
113
113
|
#{template.source}
|
114
114
|
}
|
115
115
|
CsvBuilder::Streamer.new(template)
|
116
|
-
else
|
116
|
+
else
|
117
117
|
output = CsvBuilder::CSV_LIB.generate(@csv_options || {}) do |faster_csv|
|
118
|
-
csv = CsvBuilder::TransliteratingFilter.new(faster_csv, @input_encoding || 'UTF-8', @output_encoding || '
|
118
|
+
csv = CsvBuilder::TransliteratingFilter.new(faster_csv, @input_encoding || 'UTF-8', @output_encoding || 'ISO-8859-1')
|
119
119
|
#{template.source}
|
120
120
|
end
|
121
121
|
output
|
@@ -126,7 +126,7 @@ module CsvBuilder # :nodoc:
|
|
126
126
|
end
|
127
127
|
EOV
|
128
128
|
end
|
129
|
-
|
129
|
+
|
130
130
|
def compile(template)
|
131
131
|
self.class.call(template)
|
132
132
|
end
|
@@ -1,23 +1,55 @@
|
|
1
1
|
#encoding: utf-8
|
2
2
|
|
3
|
+
# Transliterate into the required encoding if necessary
|
4
|
+
#
|
5
|
+
# We can't rely on the encoding option in the Ruby 1.9 version CSV because this
|
6
|
+
# is ignored when it is 'compatible' (see <tt>Encoding.compatible?</tt>with the
|
7
|
+
# input for example:
|
8
|
+
#
|
9
|
+
# CSV.generate(:encoding => 'ASCII') { |csv| '£12.34'.encoding('UTF-8') }
|
10
|
+
#
|
11
|
+
# will generate a UTF-8 encoded string.
|
3
12
|
class CsvBuilder::TransliteratingFilter
|
4
13
|
# Transliterate into the required encoding if necessary
|
5
|
-
def initialize(
|
6
|
-
|
14
|
+
def initialize(csv, input_encoding = 'UTF-8', output_encoding = 'ISO-8859-1')
|
15
|
+
self.csv = csv
|
7
16
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
if RUBY_VERSION.to_f < 1.9
|
18
|
+
# TODO: do some checking to make sure iconv works correctly in
|
19
|
+
# current environment. See <tt>ActiveSupport::Inflector#transliterate</tt>
|
20
|
+
# definition for details
|
21
|
+
#
|
22
|
+
# Not using the more standard //IGNORE//TRANSLIT because it raises
|
23
|
+
# <tt>Iconv::IllegalSequence,/tt> for some inputs
|
24
|
+
self.iconv = Iconv.new("#{output_encoding}//TRANSLIT//IGNORE", input_encoding) if input_encoding != output_encoding
|
25
|
+
else
|
26
|
+
# <tt>input_encoding</tt> is ignored because we know what this it is
|
27
|
+
self.output_encoding = output_encoding
|
28
|
+
end
|
15
29
|
end
|
16
30
|
|
17
|
-
# Transliterate before passing to
|
31
|
+
# Transliterate before passing to CSV so that the right characters
|
32
|
+
# (e.g. quotes) get escaped
|
18
33
|
def <<(row)
|
19
|
-
@
|
34
|
+
@csv << convert_row(row)
|
20
35
|
end
|
21
|
-
|
22
36
|
alias :add_row :<<
|
37
|
+
|
38
|
+
private
|
39
|
+
attr_accessor :csv
|
40
|
+
|
41
|
+
private
|
42
|
+
if RUBY_VERSION.to_f < 1.9
|
43
|
+
attr_accessor :iconv
|
44
|
+
|
45
|
+
def convert_row(row)
|
46
|
+
if iconv then row.map { |value| iconv.iconv(value.to_s) } else row end
|
47
|
+
end
|
48
|
+
else
|
49
|
+
attr_accessor :output_encoding
|
50
|
+
|
51
|
+
def convert_row(row)
|
52
|
+
row.map { |value| value.to_s.encode(output_encoding, :undef => :replace) }
|
53
|
+
end
|
54
|
+
end
|
23
55
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csv_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,11 +11,11 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2012-05-24 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: actionpack
|
18
|
-
requirement:
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ! '>='
|
@@ -23,10 +23,15 @@ dependencies:
|
|
23
23
|
version: 3.0.0
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements:
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ! '>='
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 3.0.0
|
27
32
|
- !ruby/object:Gem::Dependency
|
28
33
|
name: rails
|
29
|
-
requirement:
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
30
35
|
none: false
|
31
36
|
requirements:
|
32
37
|
- - ! '>='
|
@@ -34,10 +39,15 @@ dependencies:
|
|
34
39
|
version: 3.0.0
|
35
40
|
type: :development
|
36
41
|
prerelease: false
|
37
|
-
version_requirements:
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.0.0
|
38
48
|
- !ruby/object:Gem::Dependency
|
39
49
|
name: rspec
|
40
|
-
requirement:
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
41
51
|
none: false
|
42
52
|
requirements:
|
43
53
|
- - ~>
|
@@ -45,10 +55,15 @@ dependencies:
|
|
45
55
|
version: '2.5'
|
46
56
|
type: :development
|
47
57
|
prerelease: false
|
48
|
-
version_requirements:
|
58
|
+
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ~>
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '2.5'
|
49
64
|
- !ruby/object:Gem::Dependency
|
50
65
|
name: rspec-rails
|
51
|
-
requirement:
|
66
|
+
requirement: !ruby/object:Gem::Requirement
|
52
67
|
none: false
|
53
68
|
requirements:
|
54
69
|
- - ~>
|
@@ -56,10 +71,15 @@ dependencies:
|
|
56
71
|
version: '2.5'
|
57
72
|
type: :development
|
58
73
|
prerelease: false
|
59
|
-
version_requirements:
|
74
|
+
version_requirements: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ~>
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '2.5'
|
60
80
|
- !ruby/object:Gem::Dependency
|
61
|
-
name:
|
62
|
-
requirement:
|
81
|
+
name: rack
|
82
|
+
requirement: !ruby/object:Gem::Requirement
|
63
83
|
none: false
|
64
84
|
requirements:
|
65
85
|
- - ! '>='
|
@@ -67,21 +87,15 @@ dependencies:
|
|
67
87
|
version: '0'
|
68
88
|
type: :development
|
69
89
|
prerelease: false
|
70
|
-
version_requirements:
|
71
|
-
- !ruby/object:Gem::Dependency
|
72
|
-
name: rack
|
73
|
-
requirement: &70319189609620 !ruby/object:Gem::Requirement
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
91
|
none: false
|
75
92
|
requirements:
|
76
93
|
- - ! '>='
|
77
94
|
- !ruby/object:Gem::Version
|
78
95
|
version: '0'
|
79
|
-
type: :development
|
80
|
-
prerelease: false
|
81
|
-
version_requirements: *70319189609620
|
82
96
|
- !ruby/object:Gem::Dependency
|
83
97
|
name: sqlite3
|
84
|
-
requirement:
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
85
99
|
none: false
|
86
100
|
requirements:
|
87
101
|
- - ! '>='
|
@@ -89,7 +103,12 @@ dependencies:
|
|
89
103
|
version: '0'
|
90
104
|
type: :development
|
91
105
|
prerelease: false
|
92
|
-
version_requirements:
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
93
112
|
description: CSV template handler for Rails. Enables :format => 'csv' in controllers,
|
94
113
|
with templates of the form report.csv.csvbuilder.
|
95
114
|
email: gabe@websaviour.com
|
@@ -99,39 +118,17 @@ extra_rdoc_files:
|
|
99
118
|
- README.md
|
100
119
|
files:
|
101
120
|
- CHANGELOG.rdoc
|
121
|
+
- Gemfile
|
102
122
|
- MIT-LICENSE
|
103
123
|
- README.md
|
104
124
|
- Rakefile
|
105
125
|
- VERSION
|
106
|
-
-
|
126
|
+
- csv_builder.gemspec
|
107
127
|
- lib/csv_builder.rb
|
108
128
|
- lib/csv_builder/railtie.rb
|
109
129
|
- lib/csv_builder/template_handler.rb
|
110
130
|
- lib/csv_builder/transliterating_filter.rb
|
111
131
|
- rails/init.rb
|
112
|
-
- spec/controllers/csv_builder_spec.rb
|
113
|
-
- spec/rails_app/.gitignore
|
114
|
-
- spec/rails_app/Gemfile
|
115
|
-
- spec/rails_app/README
|
116
|
-
- spec/rails_app/app/controllers/application_controller.rb
|
117
|
-
- spec/rails_app/app/helpers/application_helper.rb
|
118
|
-
- spec/rails_app/app/views/layouts/application.html.erb
|
119
|
-
- spec/rails_app/config.ru
|
120
|
-
- spec/rails_app/config/application.rb
|
121
|
-
- spec/rails_app/config/boot.rb
|
122
|
-
- spec/rails_app/config/database.yml
|
123
|
-
- spec/rails_app/config/environment.rb
|
124
|
-
- spec/rails_app/config/environments/development.rb
|
125
|
-
- spec/rails_app/config/environments/production.rb
|
126
|
-
- spec/rails_app/config/environments/test.rb
|
127
|
-
- spec/rails_app/config/routes.rb
|
128
|
-
- spec/rails_app/db/seeds.rb
|
129
|
-
- spec/spec_helper.rb
|
130
|
-
- spec/templates/csv_builder_reports/complex.csv.csvbuilder
|
131
|
-
- spec/templates/csv_builder_reports/encoding.csv.csvbuilder
|
132
|
-
- spec/templates/csv_builder_reports/massive.csv.csvbuilder
|
133
|
-
- spec/templates/csv_builder_reports/simple.csv.csvbuilder
|
134
|
-
- spec/templates/csv_builder_reports/simple.html.erb
|
135
132
|
homepage: http://github.com/dasil003/csv_builder
|
136
133
|
licenses:
|
137
134
|
- MIT
|
@@ -152,10 +149,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
149
|
- !ruby/object:Gem::Version
|
153
150
|
version: '0'
|
154
151
|
requirements:
|
155
|
-
- iconv
|
156
|
-
- Ruby 1.9.x or FasterCSV
|
152
|
+
- iconv or Ruby 1.9
|
157
153
|
rubyforge_project:
|
158
|
-
rubygems_version: 1.8.
|
154
|
+
rubygems_version: 1.8.24
|
159
155
|
signing_key:
|
160
156
|
specification_version: 3
|
161
157
|
summary: CSV template handler for Rails
|
@@ -1,87 +0,0 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
|
3
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
4
|
-
|
5
|
-
class CsvBuilderReportsController < ApplicationController
|
6
|
-
before_filter {|c| c.prepend_view_path(File.expand_path(File.dirname(__FILE__) + '/../templates')) }
|
7
|
-
|
8
|
-
def simple
|
9
|
-
# dummy
|
10
|
-
respond_to do |format|
|
11
|
-
format.html
|
12
|
-
format.csv
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def complex
|
17
|
-
respond_to do |format|
|
18
|
-
format.csv do
|
19
|
-
@filename = 'some_complex_filename.csv'
|
20
|
-
@csv_options = { :col_sep => "\t" }
|
21
|
-
@data = TEST_DATA
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def encoding
|
27
|
-
respond_to do |format|
|
28
|
-
format.csv { @output_encoding = 'UTF-16' }
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def massive
|
33
|
-
respond_to do |format|
|
34
|
-
@streaming = true
|
35
|
-
format.csv
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
if defined?(Rails) and Rails.version < '3'
|
42
|
-
ActionController::Routing::Routes.draw { |map| map.connect ':controller/:action' }
|
43
|
-
else
|
44
|
-
Rails.application.routes.draw { get ':controller/:action' }
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
describe CsvBuilderReportsController do
|
49
|
-
render_views
|
50
|
-
|
51
|
-
describe "Simple layout" do
|
52
|
-
it "still responds to HTML" do
|
53
|
-
get 'simple'
|
54
|
-
response.should be_success
|
55
|
-
end
|
56
|
-
|
57
|
-
it "responds to CSV" do
|
58
|
-
get 'simple', :format => 'csv'
|
59
|
-
response.should be_success
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe "Layout with options" do
|
64
|
-
it "sets output encoding correctly" do
|
65
|
-
get 'encoding', :format => 'csv'
|
66
|
-
correct_output = generate({}, [Iconv.iconv('UTF-16//TRANSLIT//IGNORE', 'UTF-8', 'ąčęėįšųūž')])
|
67
|
-
response.body.to_s.should == correct_output
|
68
|
-
end
|
69
|
-
|
70
|
-
it "passes csv options" do
|
71
|
-
get 'complex', :format => 'csv'
|
72
|
-
response.body.to_s.should == generate({ :col_sep => "\t" })
|
73
|
-
end
|
74
|
-
|
75
|
-
it "sets filename" do
|
76
|
-
get 'complex', :format => 'csv'
|
77
|
-
response.headers['Content-Disposition'].should match(/filename=some_complex_filename.csv/)
|
78
|
-
end
|
79
|
-
|
80
|
-
#TODO: unfortunately, this test only verifies that streaming will behave like single-shot response, because rspec's testresponse doesn't
|
81
|
-
#support streaming. Streaming has to be manually verified with a browser and stand-alone test application. see https://github.com/fawce/test_csv_streamer
|
82
|
-
it "handles very large downloads without timing out" do
|
83
|
-
get 'massive', :format => 'csv'
|
84
|
-
response.body.to_s.length.should == 24890
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
data/spec/rails_app/.gitignore
DELETED
data/spec/rails_app/Gemfile
DELETED
data/spec/rails_app/README
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Test app for csvbuilder
|
data/spec/rails_app/config.ru
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
require File.expand_path('../boot', __FILE__)
|
2
|
-
|
3
|
-
require 'rails/all'
|
4
|
-
|
5
|
-
# If you have a Gemfile, require the gems listed there, including any gems
|
6
|
-
# you've limited to :test, :development, or :production.
|
7
|
-
Bundler.require(:default, Rails.env) if defined?(Bundler)
|
8
|
-
|
9
|
-
module RailsApp
|
10
|
-
class Application < Rails::Application
|
11
|
-
# Settings in config/environments/* take precedence over those specified here.
|
12
|
-
# Application configuration should go into files in config/initializers
|
13
|
-
# -- all .rb files in that directory are automatically loaded.
|
14
|
-
|
15
|
-
# Custom directories with classes and modules you want to be autoloadable.
|
16
|
-
# config.autoload_paths += %W(#{config.root}/extras)
|
17
|
-
|
18
|
-
# Only load the plugins named here, in the order given (default is alphabetical).
|
19
|
-
# :all can be used as a placeholder for all plugins not explicitly named.
|
20
|
-
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
21
|
-
|
22
|
-
# Activate observers that should always be running.
|
23
|
-
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
24
|
-
|
25
|
-
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
26
|
-
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
27
|
-
# config.time_zone = 'Central Time (US & Canada)'
|
28
|
-
|
29
|
-
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
30
|
-
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
31
|
-
# config.i18n.default_locale = :de
|
32
|
-
|
33
|
-
# JavaScript files you want as :defaults (application.js is always included).
|
34
|
-
# config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
|
35
|
-
|
36
|
-
# Configure the default encoding used in templates for Ruby 1.9.
|
37
|
-
config.encoding = "utf-8"
|
38
|
-
|
39
|
-
# Configure sensitive parameters which will be filtered from the log file.
|
40
|
-
config.filter_parameters += [:password]
|
41
|
-
end
|
42
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# SQLite version 3.x
|
2
|
-
# gem install sqlite3
|
3
|
-
development:
|
4
|
-
adapter: sqlite3
|
5
|
-
database: db/development.sqlite3
|
6
|
-
pool: 5
|
7
|
-
timeout: 5000
|
8
|
-
|
9
|
-
# Warning: The database defined as "test" will be erased and
|
10
|
-
# re-generated from your development database when you run "rake".
|
11
|
-
# Do not set this db to the same as development or production.
|
12
|
-
test:
|
13
|
-
adapter: sqlite3
|
14
|
-
database: db/test.sqlite3
|
15
|
-
pool: 5
|
16
|
-
timeout: 5000
|
17
|
-
|
18
|
-
production:
|
19
|
-
adapter: sqlite3
|
20
|
-
database: db/production.sqlite3
|
21
|
-
pool: 5
|
22
|
-
timeout: 5000
|
@@ -1,26 +0,0 @@
|
|
1
|
-
RailsApp::Application.configure do
|
2
|
-
# Settings specified here will take precedence over those in config/application.rb
|
3
|
-
|
4
|
-
# In the development environment your application's code is reloaded on
|
5
|
-
# every request. This slows down response time but is perfect for development
|
6
|
-
# since you don't have to restart the webserver when you make code changes.
|
7
|
-
config.cache_classes = false
|
8
|
-
|
9
|
-
# Log error messages when you accidentally call methods on nil.
|
10
|
-
config.whiny_nils = true
|
11
|
-
|
12
|
-
# Show full error reports and disable caching
|
13
|
-
config.consider_all_requests_local = true
|
14
|
-
config.action_view.debug_rjs = true
|
15
|
-
config.action_controller.perform_caching = false
|
16
|
-
|
17
|
-
# Don't care if the mailer can't send
|
18
|
-
config.action_mailer.raise_delivery_errors = false
|
19
|
-
|
20
|
-
# Print deprecation notices to the Rails logger
|
21
|
-
config.active_support.deprecation = :log
|
22
|
-
|
23
|
-
# Only use best-standards-support built into browsers
|
24
|
-
config.action_dispatch.best_standards_support = :builtin
|
25
|
-
end
|
26
|
-
|
@@ -1,49 +0,0 @@
|
|
1
|
-
RailsApp::Application.configure do
|
2
|
-
# Settings specified here will take precedence over those in config/application.rb
|
3
|
-
|
4
|
-
# The production environment is meant for finished, "live" apps.
|
5
|
-
# Code is not reloaded between requests
|
6
|
-
config.cache_classes = true
|
7
|
-
|
8
|
-
# Full error reports are disabled and caching is turned on
|
9
|
-
config.consider_all_requests_local = false
|
10
|
-
config.action_controller.perform_caching = true
|
11
|
-
|
12
|
-
# Specifies the header that your server uses for sending files
|
13
|
-
config.action_dispatch.x_sendfile_header = "X-Sendfile"
|
14
|
-
|
15
|
-
# For nginx:
|
16
|
-
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
|
17
|
-
|
18
|
-
# If you have no front-end server that supports something like X-Sendfile,
|
19
|
-
# just comment this out and Rails will serve the files
|
20
|
-
|
21
|
-
# See everything in the log (default is :info)
|
22
|
-
# config.log_level = :debug
|
23
|
-
|
24
|
-
# Use a different logger for distributed setups
|
25
|
-
# config.logger = SyslogLogger.new
|
26
|
-
|
27
|
-
# Use a different cache store in production
|
28
|
-
# config.cache_store = :mem_cache_store
|
29
|
-
|
30
|
-
# Disable Rails's static asset server
|
31
|
-
# In production, Apache or nginx will already do this
|
32
|
-
config.serve_static_assets = false
|
33
|
-
|
34
|
-
# Enable serving of images, stylesheets, and javascripts from an asset server
|
35
|
-
# config.action_controller.asset_host = "http://assets.example.com"
|
36
|
-
|
37
|
-
# Disable delivery errors, bad email addresses will be ignored
|
38
|
-
# config.action_mailer.raise_delivery_errors = false
|
39
|
-
|
40
|
-
# Enable threaded mode
|
41
|
-
# config.threadsafe!
|
42
|
-
|
43
|
-
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
44
|
-
# the I18n.default_locale when a translation can not be found)
|
45
|
-
config.i18n.fallbacks = true
|
46
|
-
|
47
|
-
# Send deprecation notices to registered listeners
|
48
|
-
config.active_support.deprecation = :notify
|
49
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
RailsApp::Application.configure do
|
2
|
-
# Settings specified here will take precedence over those in config/application.rb
|
3
|
-
|
4
|
-
# The test environment is used exclusively to run your application's
|
5
|
-
# test suite. You never need to work with it otherwise. Remember that
|
6
|
-
# your test database is "scratch space" for the test suite and is wiped
|
7
|
-
# and recreated between test runs. Don't rely on the data there!
|
8
|
-
config.cache_classes = true
|
9
|
-
|
10
|
-
# Log error messages when you accidentally call methods on nil.
|
11
|
-
config.whiny_nils = true
|
12
|
-
|
13
|
-
# Show full error reports and disable caching
|
14
|
-
config.consider_all_requests_local = true
|
15
|
-
config.action_controller.perform_caching = false
|
16
|
-
|
17
|
-
# Raise exceptions instead of rendering exception templates
|
18
|
-
config.action_dispatch.show_exceptions = false
|
19
|
-
|
20
|
-
# Disable request forgery protection in test environment
|
21
|
-
config.action_controller.allow_forgery_protection = false
|
22
|
-
|
23
|
-
# Tell Action Mailer not to deliver emails to the real world.
|
24
|
-
# The :test delivery method accumulates sent emails in the
|
25
|
-
# ActionMailer::Base.deliveries array.
|
26
|
-
config.action_mailer.delivery_method = :test
|
27
|
-
|
28
|
-
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
29
|
-
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
30
|
-
# like if you have constraints or database-specific column types
|
31
|
-
# config.active_record.schema_format = :sql
|
32
|
-
|
33
|
-
# Print deprecation notices to the stderr
|
34
|
-
config.active_support.deprecation = :stderr
|
35
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
RailsApp::Application.routes.draw do
|
2
|
-
# The priority is based upon order of creation:
|
3
|
-
# first created -> highest priority.
|
4
|
-
|
5
|
-
# Sample of regular route:
|
6
|
-
# match 'products/:id' => 'catalog#view'
|
7
|
-
# Keep in mind you can assign values other than :controller and :action
|
8
|
-
|
9
|
-
# Sample of named route:
|
10
|
-
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
|
11
|
-
# This route can be invoked with purchase_url(:id => product.id)
|
12
|
-
|
13
|
-
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
14
|
-
# resources :products
|
15
|
-
|
16
|
-
# Sample resource route with options:
|
17
|
-
# resources :products do
|
18
|
-
# member do
|
19
|
-
# get 'short'
|
20
|
-
# post 'toggle'
|
21
|
-
# end
|
22
|
-
#
|
23
|
-
# collection do
|
24
|
-
# get 'sold'
|
25
|
-
# end
|
26
|
-
# end
|
27
|
-
|
28
|
-
# Sample resource route with sub-resources:
|
29
|
-
# resources :products do
|
30
|
-
# resources :comments, :sales
|
31
|
-
# resource :seller
|
32
|
-
# end
|
33
|
-
|
34
|
-
# Sample resource route with more complex sub-resources
|
35
|
-
# resources :products do
|
36
|
-
# resources :comments
|
37
|
-
# resources :sales do
|
38
|
-
# get 'recent', :on => :collection
|
39
|
-
# end
|
40
|
-
# end
|
41
|
-
|
42
|
-
# Sample resource route within a namespace:
|
43
|
-
# namespace :admin do
|
44
|
-
# # Directs /admin/products/* to Admin::ProductsController
|
45
|
-
# # (app/controllers/admin/products_controller.rb)
|
46
|
-
# resources :products
|
47
|
-
# end
|
48
|
-
|
49
|
-
# You can have the root of your site routed with "root"
|
50
|
-
# just remember to delete public/index.html.
|
51
|
-
# root :to => "welcome#index"
|
52
|
-
|
53
|
-
# See how all your routes lay out with "rake routes"
|
54
|
-
|
55
|
-
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
56
|
-
# Note: This route will make all actions in every controller accessible via GET requests.
|
57
|
-
# match ':controller(/:action(/:id(.:format)))'
|
58
|
-
end
|
data/spec/rails_app/db/seeds.rb
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
# This file should contain all the record creation needed to seed the database with its default values.
|
2
|
-
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
3
|
-
#
|
4
|
-
# Examples:
|
5
|
-
#
|
6
|
-
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
|
7
|
-
# Mayor.create(:name => 'Daley', :city => cities.first)
|
data/spec/spec_helper.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
ENV["RAILS_ENV"] ||= 'test'
|
4
|
-
rails_root = File.expand_path('../rails_app', __FILE__)
|
5
|
-
require rails_root + '/config/environment.rb'
|
6
|
-
|
7
|
-
require 'rspec/rails'
|
8
|
-
|
9
|
-
TEST_DATA = [
|
10
|
-
['Lorem', 'ipsum'],
|
11
|
-
['Lorem ipsum dolor sit amet,' 'consectetur adipiscing elit. Sed id '],
|
12
|
-
['augue! "3" !@#$^&*()_+_', 'sed risus laoreet condimentum ac nec dui.'],
|
13
|
-
['\'Aenean sagittis lorem ac', 'lorem comm<s>odo nec eleifend risus']
|
14
|
-
]
|
15
|
-
|
16
|
-
def generate(options = {}, data = TEST_DATA)
|
17
|
-
CsvBuilder::CSV_LIB.generate(options) do |csv|
|
18
|
-
data.each do |row|
|
19
|
-
csv << row
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
csv << ['ąčęėįšųūž']
|
@@ -1 +0,0 @@
|
|
1
|
-
csv << [ 'cell 1', 'cell 2' ]
|
@@ -1 +0,0 @@
|
|
1
|
-
Hello world
|