send_csv 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +23 -0
- data/.gemtest +0 -0
- data/History.txt +6 -0
- data/Manifest.txt +8 -0
- data/README.txt +62 -0
- data/Rakefile +16 -0
- data/bin/send_csv +3 -0
- data/lib/send_csv.rb +21 -0
- data/test/test_send_csv.rb +8 -0
- metadata +93 -0
data/.autotest
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'autotest/restart'
|
4
|
+
|
5
|
+
# Autotest.add_hook :initialize do |at|
|
6
|
+
# at.extra_files << "../some/external/dependency.rb"
|
7
|
+
#
|
8
|
+
# at.libs << ":../some/external"
|
9
|
+
#
|
10
|
+
# at.add_exception 'vendor'
|
11
|
+
#
|
12
|
+
# at.add_mapping(/dependency.rb/) do |f, _|
|
13
|
+
# at.files_matching(/test_.*rb$/)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# %w(TestA TestB).each do |klass|
|
17
|
+
# at.extra_class_map[klass] = "test/test_misc.rb"
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
|
21
|
+
# Autotest.add_hook :run_command do |at|
|
22
|
+
# system "rake build"
|
23
|
+
# end
|
data/.gemtest
ADDED
File without changes
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
= send_csv
|
2
|
+
|
3
|
+
* https://github.com/ouvrages/send_csv
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Adds to ApplicationController a send_csv method working like send_file.
|
8
|
+
|
9
|
+
== SYNOPSIS:
|
10
|
+
|
11
|
+
class MyController < ApplicationController
|
12
|
+
def export
|
13
|
+
lines = []
|
14
|
+
lines << ["Name", "e-mail"]
|
15
|
+
lines += Users.all.map { |user| [user.name, user.email]
|
16
|
+
send_csv(lines, :filename => "exported_users.csv")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
== REQUIREMENTS:
|
21
|
+
|
22
|
+
* csv (bundled with Ruby)
|
23
|
+
* ApplicationController with a #send_file method (bundled with Rails)
|
24
|
+
|
25
|
+
== INSTALL:
|
26
|
+
|
27
|
+
* add this to your Gemfile and run "bundle install":
|
28
|
+
gem "send_csv"
|
29
|
+
|
30
|
+
== DEVELOPERS:
|
31
|
+
|
32
|
+
After checking out the source, run:
|
33
|
+
|
34
|
+
$ rake newb
|
35
|
+
|
36
|
+
This task will install any missing dependencies, run the tests/specs,
|
37
|
+
and generate the RDoc.
|
38
|
+
|
39
|
+
== LICENSE:
|
40
|
+
|
41
|
+
(The MIT License)
|
42
|
+
|
43
|
+
Copyright (c) 2011 Ouvrages
|
44
|
+
|
45
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
46
|
+
a copy of this software and associated documentation files (the
|
47
|
+
'Software'), to deal in the Software without restriction, including
|
48
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
49
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
50
|
+
permit persons to whom the Software is furnished to do so, subject to
|
51
|
+
the following conditions:
|
52
|
+
|
53
|
+
The above copyright notice and this permission notice shall be
|
54
|
+
included in all copies or substantial portions of the Software.
|
55
|
+
|
56
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
57
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
58
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
59
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
60
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
61
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
62
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
|
6
|
+
# Hoe.plugin :compiler
|
7
|
+
# Hoe.plugin :gem_prelude_sucks
|
8
|
+
# Hoe.plugin :inline
|
9
|
+
# Hoe.plugin :racc
|
10
|
+
# Hoe.plugin :rubyforge
|
11
|
+
|
12
|
+
Hoe.spec 'send_csv' do
|
13
|
+
developer('Ouvrages', 'contact@ouvrages-web.fr')
|
14
|
+
end
|
15
|
+
|
16
|
+
# vim: syntax=ruby
|
data/bin/send_csv
ADDED
data/lib/send_csv.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module SendCsv
|
2
|
+
VERSION = '0.1'
|
3
|
+
end
|
4
|
+
|
5
|
+
class ApplicationController
|
6
|
+
def send_csv(lines, options = {})
|
7
|
+
options = options.dup
|
8
|
+
encoding = options.delete(:encoding) || 'ISO-8859-1'
|
9
|
+
|
10
|
+
options = {
|
11
|
+
:disposition => "attachment",
|
12
|
+
:type => 'text/plain',
|
13
|
+
}.merge(options)
|
14
|
+
|
15
|
+
csv = lines.map { |values| CSV.generate_line(values, ';') + "\r\n" }.join
|
16
|
+
csv = Iconv.conv(encoding, 'utf-8', csv)
|
17
|
+
|
18
|
+
send_data csv, options
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: send_csv
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: "0.1"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Ouvrages
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-05-05 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: hoe
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 35
|
29
|
+
segments:
|
30
|
+
- 2
|
31
|
+
- 9
|
32
|
+
- 4
|
33
|
+
version: 2.9.4
|
34
|
+
type: :development
|
35
|
+
version_requirements: *id001
|
36
|
+
description: Adds to ApplicationController a send_csv method working like send_file.
|
37
|
+
email:
|
38
|
+
- contact@ouvrages-web.fr
|
39
|
+
executables:
|
40
|
+
- send_csv
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- History.txt
|
45
|
+
- Manifest.txt
|
46
|
+
- README.txt
|
47
|
+
files:
|
48
|
+
- .autotest
|
49
|
+
- History.txt
|
50
|
+
- Manifest.txt
|
51
|
+
- README.txt
|
52
|
+
- Rakefile
|
53
|
+
- bin/send_csv
|
54
|
+
- lib/send_csv.rb
|
55
|
+
- test/test_send_csv.rb
|
56
|
+
- .gemtest
|
57
|
+
has_rdoc: true
|
58
|
+
homepage: https://github.com/ouvrages/send_csv
|
59
|
+
licenses: []
|
60
|
+
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options:
|
63
|
+
- --main
|
64
|
+
- README.txt
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
hash: 3
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project: send_csv
|
88
|
+
rubygems_version: 1.5.0
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Adds to ApplicationController a send_csv method working like send_file.
|
92
|
+
test_files:
|
93
|
+
- test/test_send_csv.rb
|