render_csv 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Peter Brown
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = render_csv
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to render_csv
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Peter Brown. See LICENSE.txt for
18
+ further details.
19
+
data/lib/render_csv.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'render_csv/extension'
2
+ require 'action_controller/metal/renderers'
3
+
4
+ ActionController.add_renderer :csv do |csv, options|
5
+ self.response_body = csv.respond_to?(:to_csv) ? csv.to_csv(options) : csv
6
+ end
@@ -0,0 +1,22 @@
1
+ class Array
2
+
3
+ # Converts an array to CSV formatted string
4
+ # Options include:
5
+ # :only => [:col1, :col2] # Specify which columns to include
6
+ # :except => [:col1, :col2] # Specify which columns to exclude
7
+ # :add_methods => [:method1, :method2] # Include addtional methods that aren't columns
8
+ def to_csv(options={})
9
+ return '' if empty?
10
+ return join(',') unless first.class.respond_to? :column_names
11
+
12
+ columns = first.class.column_names
13
+ columns &= options[:only].map(&:to_s) if options[:only]
14
+ columns -= options[:except].map(&:to_s) if options[:except]
15
+ columns += options[:add_methods].map(&:to_s) if options[:add_methods]
16
+
17
+ csv = [columns.join(',')]
18
+ csv.concat(map {|v| columns.map {|c| v.send(c) }.join(',') })
19
+
20
+ csv.join("\n")
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: render_csv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Peter Brown
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-07-30 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &70359766159360 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70359766159360
25
+ - !ruby/object:Gem::Dependency
26
+ name: sqlite3
27
+ requirement: &70359766158760 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70359766158760
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70359766158260 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 2.6.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70359766158260
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: &70359766157780 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70359766157780
58
+ - !ruby/object:Gem::Dependency
59
+ name: jeweler
60
+ requirement: &70359766157260 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 1.6.4
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70359766157260
69
+ - !ruby/object:Gem::Dependency
70
+ name: rcov
71
+ requirement: &70359766156760 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70359766156760
80
+ description: Adds a custom CSV renderer to Rails 3 applications
81
+ email: github@lette.us
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files:
85
+ - LICENSE.txt
86
+ - README.rdoc
87
+ files:
88
+ - lib/render_csv.rb
89
+ - lib/render_csv/extension.rb
90
+ - LICENSE.txt
91
+ - README.rdoc
92
+ homepage: http://github.com/beerlington/render_csv
93
+ licenses:
94
+ - MIT
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ segments:
106
+ - 0
107
+ hash: -2383263138295080423
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 1.8.6
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: Provides CSV rendering support to Rails 3 applications
120
+ test_files: []