csv_builder 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ == 2.0.2 release 2011-09-26
2
+ * Rails 3.1 deprecation warning fix (Scott Gonyea, Tom Anderson, Sergio Cambra)
3
+ * Added dependencies and simplified contributor setup
4
+
1
5
  == 2.0.1 release 2011-04-22
2
6
  * Remove cruft from test app
3
7
  * Exclude spec from release
data/README.md CHANGED
@@ -1,6 +1,7 @@
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
 
@@ -77,9 +78,10 @@ including a snippet like the following in your mailer method
77
78
  ## Contributions
78
79
 
79
80
  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:
81
+ and 1.9. The requirements are in the Gemfile within the test spec directory. You will need Bundler installed and then
82
+ you can run:
81
83
 
82
- cd spec/rails_app && bundle install
84
+ cd spec/rails_app && bundle install && cd ../..
83
85
 
84
86
  To install the main testing requirements. Then return back to the root directory and run:
85
87
 
@@ -89,7 +91,7 @@ I will also take patches for Rails 2.3.x, though I personally have no further ne
89
91
 
90
92
 
91
93
 
92
- == Troubleshooting
94
+ ## Troubleshooting
93
95
 
94
96
  There's a known bug of encoding error in Ruby 1.9
95
97
 
data/Rakefile CHANGED
@@ -31,5 +31,17 @@ Jeweler::Tasks.new do |gem|
31
31
  gem.authors = ['Econsultancy', 'Vidmantas Kabosis', "Gabe da Silveira"]
32
32
 
33
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'
34
46
  end
35
47
  Jeweler::RubygemsDotOrgTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.1
1
+ 2.0.2
@@ -0,0 +1,90 @@
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
+ Gem::Specification.new do |s|
7
+ s.name = %q{csv_builder}
8
+ s.version = "2.0.2"
9
+
10
+ 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{2011-09-26}
13
+ s.description = %q{CSV template handler for Rails. Enables :format => 'csv' in controllers, with templates of the form report.csv.csvbuilder.}
14
+ s.email = %q{gabe@websaviour.com}
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ "CHANGELOG.rdoc",
20
+ "MIT-LICENSE",
21
+ "README.md",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "csv_builder.gemspec",
25
+ "lib/csv_builder.rb",
26
+ "lib/csv_builder/railtie.rb",
27
+ "lib/csv_builder/template_handler.rb",
28
+ "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"
52
+ ]
53
+ s.homepage = %q{http://github.com/dasil003/csv_builder}
54
+ s.licenses = [%q{MIT}]
55
+ s.require_paths = [%q{lib}]
56
+ s.requirements = [%q{iconv}, %q{Ruby 1.9.x or FasterCSV}]
57
+ s.rubygems_version = %q{1.8.6}
58
+ s.summary = %q{CSV template handler for Rails}
59
+
60
+ if s.respond_to? :specification_version then
61
+ s.specification_version = 3
62
+
63
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
64
+ s.add_runtime_dependency(%q<actionpack>, [">= 3.0.0"])
65
+ s.add_development_dependency(%q<rails>, [">= 3.0.0"])
66
+ s.add_development_dependency(%q<rspec>, ["~> 2.5"])
67
+ s.add_development_dependency(%q<rspec-rails>, ["~> 2.5"])
68
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
69
+ s.add_development_dependency(%q<rack>, [">= 0"])
70
+ s.add_development_dependency(%q<sqlite3>, [">= 0"])
71
+ else
72
+ s.add_dependency(%q<actionpack>, [">= 3.0.0"])
73
+ s.add_dependency(%q<rails>, [">= 3.0.0"])
74
+ s.add_dependency(%q<rspec>, ["~> 2.5"])
75
+ s.add_dependency(%q<rspec-rails>, ["~> 2.5"])
76
+ s.add_dependency(%q<jeweler>, [">= 0"])
77
+ s.add_dependency(%q<rack>, [">= 0"])
78
+ s.add_dependency(%q<sqlite3>, [">= 0"])
79
+ end
80
+ else
81
+ s.add_dependency(%q<actionpack>, [">= 3.0.0"])
82
+ s.add_dependency(%q<rails>, [">= 3.0.0"])
83
+ s.add_dependency(%q<rspec>, ["~> 2.5"])
84
+ s.add_dependency(%q<rspec-rails>, ["~> 2.5"])
85
+ s.add_dependency(%q<jeweler>, [">= 0"])
86
+ s.add_dependency(%q<rack>, [">= 0"])
87
+ s.add_dependency(%q<sqlite3>, [">= 0"])
88
+ end
89
+ end
90
+
@@ -10,6 +10,7 @@ module CsvBuilder
10
10
  end
11
11
  end
12
12
 
13
+ require 'action_view'
13
14
  require 'iconv'
14
15
  require 'csv_builder/transliterating_filter'
15
16
  require 'csv_builder/template_handler'
@@ -1,60 +1,68 @@
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 'LATIN1' 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
+ class TemplateHandler
33
+ def self.call(template)
34
+ <<-EOV
35
+ begin
36
+ output = CsvBuilder::CSV_LIB.generate(@csv_options || {}) do |faster_csv|
37
+ csv = CsvBuilder::TransliteratingFilter.new(faster_csv, @input_encoding || 'UTF-8', @output_encoding || 'LATIN1')
38
+ #{template.source}
39
+ end
36
40
 
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
41
+ unless defined?(ActionMailer) && defined?(ActionMailer::Base) && controller.is_a?(ActionMailer::Base)
42
+ @filename ||= "\#{controller.action_name}.csv"
43
+ if controller.request.env['HTTP_USER_AGENT'] =~ /msie/i
44
+ controller.response.headers['Pragma'] = 'public'
45
+ controller.response.headers["Content-type"] = "text/plain"
46
+ controller.response.headers['Cache-Control'] = 'no-cache, must-revalidate, post-check=0, pre-check=0'
47
+ controller.response.headers['Content-Disposition'] = "attachment; filename=\#{@filename}"
48
+ controller.response.headers['Expires'] = "0"
49
+ else
50
+ controller.response.headers["Content-Type"] ||= 'text/csv'
51
+ controller.response.headers["Content-Disposition"] = "attachment; filename=\#{@filename}"
52
+ controller.response.headers["Content-Transfer-Encoding"] = "binary"
50
53
  end
51
-
52
- 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
54
  end
57
- EOV
55
+
56
+ output
57
+ rescue Exception => e
58
+ Rails.logger.warn("Exception \#{e} \#{e.message} with class \#{e.class.name} thrown when rendering CSV")
59
+ raise e
58
60
  end
61
+ EOV
62
+ end
63
+
64
+ def compile(template)
65
+ self.class.call(template)
59
66
  end
67
+ end
60
68
  end
@@ -0,0 +1,5 @@
1
+ .bundle
2
+ db/*.sqlite3
3
+ log/*.log
4
+ tmp/
5
+ Gemfile.lock
@@ -0,0 +1,7 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec :path => File.expand_path(File.join(File.dirname(__FILE__), '../..'))
4
+
5
+ gem 'csv_builder', :path => '../..'
6
+
7
+ gem 'fastercsv', :platforms => :ruby_18
@@ -0,0 +1 @@
1
+ Test app for csvbuilder
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>RailsApp</title>
5
+ <%= stylesheet_link_tag :all %>
6
+ <%= javascript_include_tag :defaults %>
7
+ <%= csrf_meta_tag %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run RailsApp::Application
@@ -0,0 +1,22 @@
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
@@ -4,6 +4,8 @@ ENV["RAILS_ENV"] ||= 'test'
4
4
  rails_root = File.expand_path('../rails_app', __FILE__)
5
5
  require rails_root + '/config/environment.rb'
6
6
 
7
+ require 'rspec/rails'
8
+
7
9
  TEST_DATA = [
8
10
  ['Lorem', 'ipsum'],
9
11
  ['Lorem ipsum dolor sit amet,' 'consectetur adipiscing elit. Sed id '],
@@ -0,0 +1,3 @@
1
+ @data.each do |row|
2
+ csv << row
3
+ end
@@ -0,0 +1 @@
1
+ csv << ['ąčęėįšųūž']
@@ -0,0 +1 @@
1
+ csv << [ 'cell 1', 'cell 2' ]
metadata CHANGED
@@ -1,50 +1,125 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: csv_builder
3
- version: !ruby/object:Gem::Version
4
- hash: 13
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.2
5
5
  prerelease:
6
- segments:
7
- - 2
8
- - 0
9
- - 1
10
- version: 2.0.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Econsultancy
14
9
  - Vidmantas Kabosis
15
10
  - Gabe da Silveira
16
11
  autorequire:
17
12
  bindir: bin
18
13
  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.
14
+ date: 2011-09-26 00:00:00.000000000Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: actionpack
18
+ requirement: &70256232057580 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: 3.0.0
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *70256232057580
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: &70256232051300 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: 3.0.0
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: *70256232051300
38
+ - !ruby/object:Gem::Dependency
39
+ name: rspec
40
+ requirement: &70256232042780 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.5'
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *70256232042780
49
+ - !ruby/object:Gem::Dependency
50
+ name: rspec-rails
51
+ requirement: &70256232034560 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: '2.5'
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *70256232034560
60
+ - !ruby/object:Gem::Dependency
61
+ name: jeweler
62
+ requirement: &70256232513000 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *70256232513000
71
+ - !ruby/object:Gem::Dependency
72
+ name: rack
73
+ requirement: &70256232512520 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *70256232512520
82
+ - !ruby/object:Gem::Dependency
83
+ name: sqlite3
84
+ requirement: &70256232512040 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: *70256232512040
93
+ description: CSV template handler for Rails. Enables :format => 'csv' in controllers,
94
+ with templates of the form report.csv.csvbuilder.
25
95
  email: gabe@websaviour.com
26
96
  executables: []
27
-
28
97
  extensions: []
29
-
30
- extra_rdoc_files:
98
+ extra_rdoc_files:
31
99
  - README.md
32
- files:
100
+ files:
33
101
  - CHANGELOG.rdoc
34
102
  - MIT-LICENSE
35
103
  - README.md
36
104
  - Rakefile
37
105
  - VERSION
106
+ - csv_builder.gemspec
38
107
  - lib/csv_builder.rb
39
108
  - lib/csv_builder/railtie.rb
40
109
  - lib/csv_builder/template_handler.rb
41
110
  - lib/csv_builder/transliterating_filter.rb
42
111
  - rails/init.rb
43
112
  - spec/controllers/csv_builder_spec.rb
113
+ - spec/rails_app/.gitignore
114
+ - spec/rails_app/Gemfile
115
+ - spec/rails_app/README
44
116
  - spec/rails_app/app/controllers/application_controller.rb
45
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
46
120
  - spec/rails_app/config/application.rb
47
121
  - spec/rails_app/config/boot.rb
122
+ - spec/rails_app/config/database.yml
48
123
  - spec/rails_app/config/environment.rb
49
124
  - spec/rails_app/config/environments/development.rb
50
125
  - spec/rails_app/config/environments/production.rb
@@ -52,50 +127,35 @@ files:
52
127
  - spec/rails_app/config/routes.rb
53
128
  - spec/rails_app/db/seeds.rb
54
129
  - spec/spec_helper.rb
55
- has_rdoc: true
130
+ - spec/templates/csv_builder_reports/complex.csv.csvbuilder
131
+ - spec/templates/csv_builder_reports/encoding.csv.csvbuilder
132
+ - spec/templates/csv_builder_reports/simple.csv.csvbuilder
133
+ - spec/templates/csv_builder_reports/simple.html.erb
56
134
  homepage: http://github.com/dasil003/csv_builder
57
- licenses:
135
+ licenses:
58
136
  - MIT
59
137
  post_install_message:
60
138
  rdoc_options: []
61
-
62
- require_paths:
139
+ require_paths:
63
140
  - lib
64
- required_ruby_version: !ruby/object:Gem::Requirement
141
+ required_ruby_version: !ruby/object:Gem::Requirement
65
142
  none: false
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- hash: 3
70
- segments:
71
- - 0
72
- version: "0"
73
- required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ! '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
148
  none: false
75
- requirements:
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- hash: 3
79
- segments:
80
- - 0
81
- version: "0"
82
- requirements: []
83
-
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements:
154
+ - iconv
155
+ - Ruby 1.9.x or FasterCSV
84
156
  rubyforge_project:
85
- rubygems_version: 1.5.2
157
+ rubygems_version: 1.8.6
86
158
  signing_key:
87
159
  specification_version: 3
88
160
  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
161
+ test_files: []