csv_builder 2.0.1 → 2.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 42494f2dda5820b75c3bc9e4233f4cad10fc4e055720303ba5d2931d4b1d6dea
4
+ data.tar.gz: 64ad90de9a0a8cd9a12402d602083f2849c29cf5f5d7bf0a48a349dcf588d505
5
+ SHA512:
6
+ metadata.gz: 45a9c336e740960a0d483c31132490a6ea7143c7120baeaa21e26b258654c9a04959f157736a9dd7c8bf9a0a6fc52935fa874ea87ff40d0b882d4816edcb5165
7
+ data.tar.gz: 0d215da613325d6732cd660d165b1c5ac7ae07d6d8ff2d7b1c566a4c8f6e2e68c33814329bd9596fcd2bd12fc7a0fa0a13fda9fc747f98520ebbf8afc2dcf773
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,28 @@
1
+ == 2.1.3 release 2021-02-07
2
+
3
+ * Ruby 3.0 compatibility (Uwe Kubosch)
4
+
5
+ == 2.1.2 release 2019-10-25
6
+
7
+ * Fix deprecation for Rails 6 single-arity template handlers (Prajjwal Singh)
8
+
9
+ == 2.1.1 release 2012-07-15
10
+
11
+ * Fix deprecation warning in 1.9 by removing iconv dependency (Joel Chippendale)
12
+ * Change name of default output encoding for 1.9 encoding support (Joel Chippendale)
13
+ * Add Gemfile for development (Joel Chippendale)
14
+ * Fix for IE under SSL (tkiley)
15
+ * Fix for filenames with spaces. (Ramihajamalala Hery)
16
+
17
+ == 2.1.0 release 2011-11-25
18
+ * Implemented streaming support. (fawce.com)
19
+ * Temporarily renamed to csv_streamer to facilitate publishing to rubygems. (fawce.com)
20
+ * Merged back fawce's patch so it can be used in mainline csv_builder. (nbudin)
21
+
22
+ == 2.0.2 release 2011-09-26
23
+ * Rails 3.1 deprecation warning fix (Scott Gonyea, Tom Anderson, Sergio Cambra)
24
+ * Added dependencies and simplified contributor setup
25
+
1
26
  == 2.0.1 release 2011-04-22
2
27
  * Remove cruft from test app
3
28
  * Exclude spec from release
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://www.rubygems.org"
2
+
3
+ gemspec
data/README.md CHANGED
@@ -1,20 +1,20 @@
1
1
  **Important Note** Though I did not write this code, I did convert it to a gem and I'm currently the sole owner on
2
2
  rubygems. With Joel Chippindale's approval I've taken over defacto maintainership of this gem. My use case is
3
- primarily under rails 3, but I will accept patches for the 2.3.x version as well.
3
+ primarily under rails 3, and the current version is not backwards compatible, but I will maintain a 2.3.x branch as well
4
+ if anyone has patches.
4
5
 
5
6
  # CSV Builder
6
7
 
7
8
  The CSV Builder Rails plugin provides a simple templating system for serving dynamically generated CSV files from your
8
9
  application.
9
10
 
10
-
11
-
12
11
  ## Requirements
13
12
 
14
13
  The current version of CSV Builder works with:
15
14
 
16
15
  * Rails 3.x
17
16
  * Ruby 1.8 or 1.9
17
+ * Unicorn _is required for streaming_ see [the example streaming app](https://github.com/fawce/test_csv_streamer) for more details.
18
18
 
19
19
  The legacy version (1.1.x) was originally developed and tested for Rails 2.1. See [the legacy
20
20
  docs](https://github.com/econsultancy/csv_builder) for more details.
@@ -49,7 +49,7 @@ your controller's action method e.g.
49
49
  @filename = 'report.csv'
50
50
 
51
51
  You can set the input encoding and output encoding by setting `@input_encoding` and `@output_encoding` instance
52
- variables. These default to 'UTF-8' and 'LATIN1' respectively. e.g.
52
+ variables. These default to 'UTF-8' and 'ISO-8859-1' respectively. e.g.
53
53
 
54
54
  @output_encoding = 'UTF-8'
55
55
 
@@ -57,6 +57,10 @@ You can set `@csv_options` instance variable to define options for FasterCSV gen
57
57
 
58
58
  @csv_options = { :force_quotes => true, :col_sep => ';' }
59
59
 
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:
61
+
62
+ @streaming = true
63
+
60
64
  You can respond with csv in your controller as well:
61
65
 
62
66
  respond_to do |format|
@@ -72,14 +76,18 @@ including a snippet like the following in your mailer method
72
76
  attachment.filename = 'report.csv'
73
77
  end
74
78
 
79
+ ## Streaming Support
80
+
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.
75
82
 
76
83
 
77
84
  ## Contributions
78
85
 
79
86
  As of version 2.0 this gem has a rudimentary spec suite for Rails 3. The test suite has been run under both Ruby 1.8
80
- and 1.9. The requirements are in the Gemfile within the test spec directory. So first you can run:
87
+ and 1.9. The requirements are in the Gemfile within the test spec directory. You will need Bundler installed and then
88
+ you can run:
81
89
 
82
- cd spec/rails_app && bundle install
90
+ cd spec/rails_app && bundle install && cd ../..
83
91
 
84
92
  To install the main testing requirements. Then return back to the root directory and run:
85
93
 
@@ -88,12 +96,12 @@ To install the main testing requirements. Then return back to the root director
88
96
  I will also take patches for Rails 2.3.x, though I personally have no further need of that branch.
89
97
 
90
98
 
91
-
92
- == Troubleshooting
99
+ ## Troubleshooting
93
100
 
94
101
  There's a known bug of encoding error in Ruby 1.9
95
102
 
96
103
  For more details see https://rails.lighthouseapp.com/projects/8994/tickets/2188-i18n-fails-with-multibyte-strings-in-ruby-19-similar-to-2038
97
104
 
98
105
 
99
- Copyright (c) 2008 Econsultancy.com, 2009 Vidmantas Kabošis & 2011 Gabe da Silveira released under the MIT license
106
+ Original content Copyright (c) 2008 Econsultancy.com, 2009 Vidmantas Kabošis & 2011 Gabe da Silveira released under the MIT license
107
+ Updated content for streaming, Copyright (c) 2011 John Fawcett released under the MIT license
data/Rakefile CHANGED
@@ -1,14 +1,21 @@
1
- require 'rake/rdoctask'
1
+ require 'rdoc/task'
2
2
  require 'rspec/core'
3
3
  require 'rspec/core/rake_task'
4
- require 'jeweler'
4
+
5
+ # Temporary hack from https://stackoverflow.com/questions/35893584/nomethoderror-undefined-method-last-comment-after-upgrading-to-rake-11
6
+ module TempFixForRakeLastComment
7
+ def last_comment
8
+ last_description
9
+ end
10
+ end
11
+ Rake::Application.send :include, TempFixForRakeLastComment
5
12
 
6
13
  desc 'Generate documentation for the csv_builder plugin.'
7
14
  Rake::RDocTask.new(:rdoc) do |rdoc|
8
15
  rdoc.rdoc_dir = 'rdoc'
9
16
  rdoc.title = 'CSV Builder'
10
17
  rdoc.options << '--line-numbers' << '--inline-source'
11
- rdoc.rdoc_files.include('README.rdoc')
18
+ rdoc.rdoc_files.include('README.md')
12
19
  rdoc.rdoc_files.include('CHANGELOG.rdoc')
13
20
  rdoc.rdoc_files.include('lib/**/*.rb')
14
21
  end
@@ -20,16 +27,3 @@ end
20
27
 
21
28
  desc 'Default: run specs.'
22
29
  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
- end
35
- Jeweler::RubygemsDotOrgTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.1
1
+ 2.1.3
@@ -0,0 +1,64 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{csv_builder}
3
+ s.version = "2.1.3"
4
+
5
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
+ s.authors = [%q{Econsultancy}, %q{Vidmantas Kabosis}, %q{Gabe da Silveira}]
7
+ s.date = %q{2012-05-24}
8
+ s.description = %q{CSV template handler for Rails. Enables :format => 'csv' in controllers, with templates of the form report.csv.csvbuilder.}
9
+ s.email = %q{gabe@websaviour.com}
10
+ s.extra_rdoc_files = [
11
+ "README.md"
12
+ ]
13
+ s.files = [
14
+ "CHANGELOG.rdoc",
15
+ "Gemfile",
16
+ "MIT-LICENSE",
17
+ "README.md",
18
+ "Rakefile",
19
+ "VERSION",
20
+ "csv_builder.gemspec",
21
+ "lib/csv_builder.rb",
22
+ "lib/csv_builder/railtie.rb",
23
+ "lib/csv_builder/template_handler.rb",
24
+ "lib/csv_builder/transliterating_filter.rb",
25
+ "rails/init.rb"
26
+ ]
27
+ s.homepage = %q{https://github.com/gtd/csv_builder}
28
+ s.licenses = [%q{MIT}]
29
+ s.require_paths = [%q{lib}]
30
+ s.requirements = [%q{iconv or Ruby 1.9}]
31
+ s.rubygems_version = %q{1.8.6}
32
+ s.summary = %q{CSV template handler for Rails}
33
+
34
+ if s.respond_to? :specification_version then
35
+ s.specification_version = 3
36
+
37
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
38
+ s.add_runtime_dependency(%q<actionpack>, [">= 3.0.0"])
39
+ s.add_runtime_dependency('fastercsv') if RUBY_VERSION.to_f < 1.9
40
+ s.add_development_dependency(%q<rails>, [">= 4.0.0", "< 5.0"])
41
+ s.add_development_dependency(%q<rspec>, ["~> 2.5"])
42
+ s.add_development_dependency(%q<rspec-rails>, ["~> 2.5"])
43
+ s.add_development_dependency(%q<rack>, [">= 0"])
44
+ s.add_development_dependency(%q<sqlite3>, [">= 0", "< 1.4"])
45
+ else
46
+ s.add_dependency(%q<actionpack>, [">= 3.0.0"])
47
+ s.add_dependency('fastercsv') if RUBY_VERSION.to_f < 1.9
48
+ s.add_dependency(%q<rails>, [">= 3.0.0"])
49
+ s.add_dependency(%q<rspec>, ["~> 2.5"])
50
+ s.add_dependency(%q<rspec-rails>, ["~> 2.5"])
51
+ s.add_dependency(%q<rack>, [">= 0"])
52
+ s.add_dependency(%q<sqlite3>, [">= 0"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<actionpack>, [">= 3.0.0"])
56
+ s.add_dependency('fastercsv') if RUBY_VERSION.to_f < 1.9
57
+ s.add_dependency(%q<rails>, [">= 3.0.0"])
58
+ s.add_dependency(%q<rspec>, ["~> 2.5"])
59
+ s.add_dependency(%q<rspec-rails>, ["~> 2.5"])
60
+ s.add_dependency(%q<rack>, [">= 0"])
61
+ s.add_dependency(%q<sqlite3>, [">= 0"])
62
+ end
63
+ end
64
+
data/lib/csv_builder.rb CHANGED
@@ -5,12 +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
- require 'iconv'
14
+ require 'action_view'
14
15
  require 'csv_builder/transliterating_filter'
15
16
  require 'csv_builder/template_handler'
16
17
  require 'csv_builder/railtie'
@@ -1,60 +1,135 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module CsvBuilder # :nodoc:
4
+ # Template handler for csv templates
5
+ #
6
+ # Add rows to your CSV file in the template by pushing arrays of columns into csv
7
+ #
8
+ # # First row
9
+ # csv << [ 'cell 1', 'cell 2' ]
10
+ # # Second row
11
+ # csv << [ 'another cell value', 'and another' ]
12
+ # # etc...
13
+ #
14
+ # You can set the default filename for that a browser will use for 'save as' by
15
+ # setting <tt>@filename</tt> instance variable in your controller's action method
16
+ # e.g.
17
+ #
18
+ # @filename = 'report.csv'
19
+ #
20
+ # You can also set the input encoding and output encoding by setting
21
+ # <tt>@input_encoding</tt> and <tt>@output_encoding</tt> instance variables.
22
+ # These default to 'UTF-8' and 'ISO-8859-1' respectively. e.g.
23
+ #
24
+ # @output_encoding = 'UTF-8'
4
25
 
5
- # Template handler for csv templates
6
- #
7
- # Add rows to your CSV file in the template by pushing arrays of columns into csv
8
- #
9
- # # First row
10
- # csv << [ 'cell 1', 'cell 2' ]
11
- # # Second row
12
- # csv << [ 'another cell value', 'and another' ]
13
- # # etc...
14
- #
15
- # You can set the default filename for that a browser will use for 'save as' by
16
- # setting <tt>@filename</tt> instance variable in your controller's action method
17
- # e.g.
18
- #
19
- # @filename = 'report.csv'
20
- #
21
- # You can also set the input encoding and output encoding by setting
22
- # <tt>@input_encoding</tt> and <tt>@output_encoding</tt> instance variables.
23
- # These default to 'UTF-8' and 'LATIN1' respectively. e.g.
24
- #
25
- # @output_encoding = 'UTF-8'
26
+ if defined?(Rails) and Rails.version < '3'
26
27
  class TemplateHandler < ActionView::Template::Handler
27
28
  include ActionView::Template::Handlers::Compilable
29
+ end
30
+ end
28
31
 
29
- def compile(template)
30
- <<-EOV
31
- begin
32
- output = CsvBuilder::CSV_LIB.generate(@csv_options || {}) do |faster_csv|
33
- csv = CsvBuilder::TransliteratingFilter.new(faster_csv, @input_encoding || 'UTF-8', @output_encoding || 'LATIN1')
34
- #{template.source}
35
- end
32
+ # The ruby csv class will try to infer a separator to use, if the csv options
33
+ # do not set it. ruby's csv calls pos, eof?, read, and rewind to check the first line
34
+ # of the io to infer a separator. Rails' output object does not support these methods
35
+ # so we provide a mock implementation to satisfy csv.
36
+ #
37
+ # See code at https://github.com/ruby/ruby/blob/trunk/lib/csv.rb#L2021 - note that @io points
38
+ # to an object of this class.
39
+ class Yielder
40
+ def initialize(yielder)
41
+ @yielder = yielder
42
+ end
43
+
44
+ # always indicate that we are at the start of the io stream
45
+ def pos
46
+ return 0
47
+ end
48
+
49
+ # always indicate that we have reached the end of the file
50
+ def eof?
51
+ return true
52
+ end
53
+
54
+ #do nothing, we haven't moved forward
55
+ def rewind
56
+ end
57
+
58
+ #despite indicating that we have no data with pos and eof, we still need to return a newline
59
+ #otherwise CSV will enter an infinite loop with read.
60
+ def read(arg1)
61
+ return "\n"
62
+ end
63
+
64
+ # this is the method that ultimately yields to the block with output.
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
67
+ # from within the context of the each block.
68
+ def <<(data)
69
+ @yielder.call data
70
+ end
71
+
72
+ end
73
+
74
+ # Streamer implements an each method to facilitate streaming back through the Rails stack. It requires
75
+ # the template to be passed to it as a proc. An instance of this class is returned from the template handler's
76
+ # compile method, and will receive calls to each. Data is streamed by yielding back to the containing block.
77
+ class Streamer
78
+ def initialize(template_proc)
79
+ @template_proc = template_proc
80
+ end
81
+
82
+ def each
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 || 'ISO-8859-1')
86
+ @template_proc.call(csv)
87
+ end
88
+ end
36
89
 
37
- unless defined?(ActionMailer) && defined?(ActionMailer::Base) && controller.is_a?(ActionMailer::Base)
38
- @filename ||= "\#{controller.action_name}.csv"
39
- if controller.request.env['HTTP_USER_AGENT'] =~ /msie/i
40
- controller.response.headers['Pragma'] = 'public'
41
- controller.response.headers["Content-type"] = "text/plain"
42
- controller.response.headers['Cache-Control'] = 'no-cache, must-revalidate, post-check=0, pre-check=0'
43
- controller.response.headers['Content-Disposition'] = "attachment; filename=\#{@filename}"
44
- controller.response.headers['Expires'] = "0"
45
- else
46
- controller.response.headers["Content-Type"] ||= 'text/csv'
47
- controller.response.headers["Content-Disposition"] = "attachment; filename=\#{@filename}"
48
- controller.response.headers["Content-Transfer-Encoding"] = "binary"
49
- end
90
+ class TemplateHandler
91
+ def self.call(template, source = nil)
92
+ source ||= template.source
93
+
94
+ <<-EOV
95
+ begin
96
+
97
+ unless defined?(ActionMailer) && defined?(ActionMailer::Base) && controller.is_a?(ActionMailer::Base)
98
+ @filename ||= "\#{controller.action_name}.csv"
99
+ if controller.request.env['HTTP_USER_AGENT'] =~ /msie/i
100
+ response.headers['Pragma'] = 'must-revalidate'
101
+ response.headers["Content-type"] = "text/plain"
102
+ response.headers['Cache-Control'] = 'must-revalidate, post-check=0, pre-check=0'
103
+ response.headers['Content-Disposition'] = "attachment; filename=\\"\#{@filename}\\""
104
+ response.headers['Expires'] = "0"
105
+ else
106
+ response.headers["Content-Type"] ||= 'text/csv'
107
+ response.headers["Content-Disposition"] = "attachment; filename=\\"\#{@filename}\\""
108
+ response.headers["Content-Transfer-Encoding"] = "binary"
50
109
  end
110
+ end
51
111
 
112
+ if @streaming
113
+ template = Proc.new {|csv|
114
+ #{source}
115
+ }
116
+ CsvBuilder::Streamer.new(template)
117
+ else
118
+ output = CsvBuilder::CSV_LIB.generate(**(@csv_options || {})) do |faster_csv|
119
+ csv = CsvBuilder::TransliteratingFilter.new(faster_csv, @input_encoding || 'UTF-8', @output_encoding || 'ISO-8859-1')
120
+ #{source}
121
+ end
52
122
  output
53
- rescue Exception => e
54
- Rails.logger.warn("Exception \#{e} \#{e.message} with class \#{e.class.name} thrown when rendering CSV")
55
- raise e
56
123
  end
57
- EOV
124
+ rescue Exception => e
125
+ Rails.logger.warn("Exception \#{e} \#{e.message} with class \#{e.class.name} thrown when rendering CSV")
126
+ raise e
58
127
  end
128
+ EOV
129
+ end
130
+
131
+ def compile(template)
132
+ self.class.call(template)
59
133
  end
134
+ end
60
135
  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(faster_csv, input_encoding = 'UTF-8', output_encoding = 'LATIN1')
6
- @faster_csv = faster_csv
14
+ def initialize(csv, input_encoding = 'UTF-8', output_encoding = 'ISO-8859-1')
15
+ self.csv = csv
7
16
 
8
- # TODO: do some checking to make sure iconv works correctly in
9
- # current environment. See ActiveSupport::Inflector#transliterate
10
- # definition for details
11
- #
12
- # Not using the more standard //IGNORE//TRANSLIT because it raises
13
- # Iconv::IllegalSequence for some inputs
14
- @iconv = Iconv.new("#{output_encoding}//TRANSLIT//IGNORE", input_encoding) if input_encoding != output_encoding
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 FasterCSV so that the right characters (e.g. quotes) get escaped
31
+ # Transliterate before passing to CSV so that the right characters
32
+ # (e.g. quotes) get escaped
18
33
  def <<(row)
19
- @faster_csv << if @iconv then row.map { |value| @iconv.iconv(value.to_s) } else row end
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,101 +1,156 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: csv_builder
3
- version: !ruby/object:Gem::Version
4
- hash: 13
5
- prerelease:
6
- segments:
7
- - 2
8
- - 0
9
- - 1
10
- version: 2.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.3
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Econsultancy
14
8
  - Vidmantas Kabosis
15
9
  - Gabe da Silveira
16
- autorequire:
10
+ autorequire:
17
11
  bindir: bin
18
12
  cert_chain: []
19
-
20
- date: 2011-04-22 00:00:00 -07:00
21
- default_executable:
22
- dependencies: []
23
-
24
- description: CSV template handler for Rails. Enables :format => 'csv' in controllers, with templates of the form report.csv.csvbuilder.
13
+ date: 2012-05-24 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: actionpack
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: 3.0.0
29
+ - !ruby/object:Gem::Dependency
30
+ name: rails
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 4.0.0
36
+ - - "<"
37
+ - !ruby/object:Gem::Version
38
+ version: '5.0'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 4.0.0
46
+ - - "<"
47
+ - !ruby/object:Gem::Version
48
+ version: '5.0'
49
+ - !ruby/object:Gem::Dependency
50
+ name: rspec
51
+ requirement: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '2.5'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '2.5'
63
+ - !ruby/object:Gem::Dependency
64
+ name: rspec-rails
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '2.5'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '2.5'
77
+ - !ruby/object:Gem::Dependency
78
+ name: rack
79
+ requirement: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ type: :development
85
+ prerelease: false
86
+ version_requirements: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ - !ruby/object:Gem::Dependency
92
+ name: sqlite3
93
+ requirement: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - - "<"
99
+ - !ruby/object:Gem::Version
100
+ version: '1.4'
101
+ type: :development
102
+ prerelease: false
103
+ version_requirements: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ - - "<"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.4'
111
+ description: CSV template handler for Rails. Enables :format => 'csv' in controllers,
112
+ with templates of the form report.csv.csvbuilder.
25
113
  email: gabe@websaviour.com
26
114
  executables: []
27
-
28
115
  extensions: []
29
-
30
- extra_rdoc_files:
116
+ extra_rdoc_files:
31
117
  - README.md
32
- files:
118
+ files:
33
119
  - CHANGELOG.rdoc
120
+ - Gemfile
34
121
  - MIT-LICENSE
35
122
  - README.md
36
123
  - Rakefile
37
124
  - VERSION
125
+ - csv_builder.gemspec
38
126
  - lib/csv_builder.rb
39
127
  - lib/csv_builder/railtie.rb
40
128
  - lib/csv_builder/template_handler.rb
41
129
  - lib/csv_builder/transliterating_filter.rb
42
130
  - rails/init.rb
43
- - spec/controllers/csv_builder_spec.rb
44
- - spec/rails_app/app/controllers/application_controller.rb
45
- - spec/rails_app/app/helpers/application_helper.rb
46
- - spec/rails_app/config/application.rb
47
- - spec/rails_app/config/boot.rb
48
- - spec/rails_app/config/environment.rb
49
- - spec/rails_app/config/environments/development.rb
50
- - spec/rails_app/config/environments/production.rb
51
- - spec/rails_app/config/environments/test.rb
52
- - spec/rails_app/config/routes.rb
53
- - spec/rails_app/db/seeds.rb
54
- - spec/spec_helper.rb
55
- has_rdoc: true
56
- homepage: http://github.com/dasil003/csv_builder
57
- licenses:
131
+ homepage: https://github.com/gtd/csv_builder
132
+ licenses:
58
133
  - MIT
59
- post_install_message:
134
+ metadata: {}
135
+ post_install_message:
60
136
  rdoc_options: []
61
-
62
- require_paths:
137
+ require_paths:
63
138
  - lib
64
- required_ruby_version: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
67
141
  - - ">="
68
- - !ruby/object:Gem::Version
69
- hash: 3
70
- segments:
71
- - 0
72
- version: "0"
73
- required_rubygems_version: !ruby/object:Gem::Requirement
74
- none: false
75
- requirements:
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
76
146
  - - ">="
77
- - !ruby/object:Gem::Version
78
- hash: 3
79
- segments:
80
- - 0
81
- version: "0"
82
- requirements: []
83
-
84
- rubyforge_project:
85
- rubygems_version: 1.5.2
86
- signing_key:
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements:
150
+ - iconv or Ruby 1.9
151
+ rubyforge_project:
152
+ rubygems_version: 2.7.6.2
153
+ signing_key:
87
154
  specification_version: 3
88
155
  summary: CSV template handler for Rails
89
- test_files:
90
- - spec/controllers/csv_builder_spec.rb
91
- - spec/rails_app/app/controllers/application_controller.rb
92
- - spec/rails_app/app/helpers/application_helper.rb
93
- - spec/rails_app/config/application.rb
94
- - spec/rails_app/config/boot.rb
95
- - spec/rails_app/config/environment.rb
96
- - spec/rails_app/config/environments/development.rb
97
- - spec/rails_app/config/environments/production.rb
98
- - spec/rails_app/config/environments/test.rb
99
- - spec/rails_app/config/routes.rb
100
- - spec/rails_app/db/seeds.rb
101
- - spec/spec_helper.rb
156
+ test_files: []
@@ -1,68 +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
- end
33
- ActionController::Routing::Routes.draw { |map| map.connect ':controller/:action' }
34
-
35
-
36
- describe CsvBuilderReportsController do
37
- render_views
38
-
39
- describe "Simple layout" do
40
- it "still responds to HTML" do
41
- get 'simple'
42
- response.should be_success
43
- end
44
-
45
- it "responds to CSV" do
46
- get 'simple', :format => 'csv'
47
- response.should be_success
48
- end
49
- end
50
-
51
- describe "Layout with options" do
52
- it "sets output encoding correctly" do
53
- get 'encoding', :format => 'csv'
54
- correct_output = generate({}, [Iconv.iconv('UTF-16//TRANSLIT//IGNORE', 'UTF-8', 'ąčęėįšųūž')])
55
- response.body.to_s.should == correct_output
56
- end
57
-
58
- it "passes csv options" do
59
- get 'complex', :format => 'csv'
60
- response.body.to_s.should == generate({ :col_sep => "\t" })
61
- end
62
-
63
- it "sets filename" do
64
- get 'complex', :format => 'csv'
65
- response.headers['Content-Disposition'].should match(/filename=some_complex_filename.csv/)
66
- end
67
- end
68
- end
@@ -1,3 +0,0 @@
1
- class ApplicationController < ActionController::Base
2
- protect_from_forgery
3
- end
@@ -1,2 +0,0 @@
1
- module ApplicationHelper
2
- end
@@ -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,6 +0,0 @@
1
- require 'rubygems'
2
-
3
- # Set up gems listed in the Gemfile.
4
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
-
6
- require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -1,5 +0,0 @@
1
- # Load the rails application
2
- require File.expand_path('../application', __FILE__)
3
-
4
- # Initialize the rails application
5
- RailsApp::Application.initialize!
@@ -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
@@ -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,20 +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
- TEST_DATA = [
8
- ['Lorem', 'ipsum'],
9
- ['Lorem ipsum dolor sit amet,' 'consectetur adipiscing elit. Sed id '],
10
- ['augue! "3" !@#$^&*()_+_', 'sed risus laoreet condimentum ac nec dui.'],
11
- ['\'Aenean sagittis lorem ac', 'lorem comm<s>odo nec eleifend risus']
12
- ]
13
-
14
- def generate(options = {}, data = TEST_DATA)
15
- CsvBuilder::CSV_LIB.generate(options) do |csv|
16
- data.each do |row|
17
- csv << row
18
- end
19
- end
20
- end