xls_to_csv-paperclip-processor 0.1.1 → 0.2.0
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/Gemfile +7 -0
- data/README.md +4 -14
- data/Rakefile +28 -40
- data/VERSION +1 -1
- data/lib/xls_to_csv-paperclip-processor.rb +40 -29
- data/xls_to_csv-paperclip-processor.gemspec +18 -17
- metadata +50 -75
data/Gemfile
ADDED
data/README.md
CHANGED
@@ -4,7 +4,7 @@ This gem is Paperclip processor, that uses xls2csv to convert .xls to .csv.
|
|
4
4
|
|
5
5
|
## Requirements ##
|
6
6
|
|
7
|
-
* [Paperclip][0] ~> 2.
|
7
|
+
* [Paperclip][0] ~> 2.5
|
8
8
|
* [xls2csv][2]
|
9
9
|
|
10
10
|
## Installation ##
|
@@ -24,10 +24,9 @@ Various linux distributions should use similar methods with their respected pack
|
|
24
24
|
Use it as you would any other Paperclip processor. In your model:
|
25
25
|
|
26
26
|
class SomeCsvAttachement < ActiveRecord::Base
|
27
|
-
before_post_process :is_xls?
|
28
27
|
has_attached_file :data,
|
29
28
|
:styles => {
|
30
|
-
:
|
29
|
+
:converted => {
|
31
30
|
:format => "csv",
|
32
31
|
:params => "-c, -q 3"
|
33
32
|
}
|
@@ -35,19 +34,10 @@ Use it as you would any other Paperclip processor. In your model:
|
|
35
34
|
:path => ":rails_root/data/some_csv_attachements/:id_partition/:basename.:extension",
|
36
35
|
:processors => [:xls_to_csv]
|
37
36
|
|
38
|
-
validates_attachment_content_type :data, :content_type => ['text/csv','text/comma-separated-values','text/csv','application/csv','application/excel','application/vnd.ms-excel','application/vnd.msexcel','text/anytext','text/plain']
|
39
|
-
|
40
|
-
def is_xls?
|
41
|
-
[
|
42
|
-
'application/excel',
|
43
|
-
'application/vnd.ms-excel',
|
44
|
-
'application/vnd.msexcel'
|
45
|
-
].include?(self.data_content_type)
|
46
|
-
end
|
47
|
-
|
37
|
+
validates_attachment_content_type :data, :content_type => ['text/csv','text/comma-separated-values','text/csv','application/csv','application/excel','application/vnd.ms-excel','application/vnd.msexcel','text/anytext','text/plain']
|
48
38
|
end
|
49
39
|
|
50
|
-
which will convert your .xls document into .csv, and keep both files (.xls and .csv) on the server. If your attachment is not a .xls it
|
40
|
+
which will convert your .xls document into .csv, and keep both files (.xls and .csv) on the server. If your attachment is not a .xls it will just copy it.
|
51
41
|
|
52
42
|
|
53
43
|
[0]: https://github.com/thoughtbot/paperclip
|
data/Rakefile
CHANGED
@@ -1,48 +1,36 @@
|
|
1
|
-
|
2
|
-
require 'rake'
|
1
|
+
# encoding: utf-8
|
3
2
|
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
4
5
|
begin
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
gem.license = "MIT"
|
11
|
-
gem.summary = %Q{Gem for easy convertation .xls to .csv with Paperclip}
|
12
|
-
gem.description = %Q{If you want to convert .xls to .csv simply and unwittingly, then this gem is for you!}
|
13
|
-
gem.email = "igor.alexandrov@gmail.com"
|
14
|
-
gem.authors = ["Igor Alexandrov"]
|
15
|
-
gem.add_dependency 'paperclip', '>=2.3.0'
|
16
|
-
gem.add_development_dependency "rspec", ">= 0"
|
17
|
-
gem.add_development_dependency "yard", ">= 0"
|
18
|
-
end
|
19
|
-
Jeweler::RubygemsDotOrgTasks.new
|
20
|
-
rescue LoadError
|
21
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
require 'spec/rake/spectask'
|
26
|
-
Spec::Rake::SpecTask.new(:spec) do |spec|
|
27
|
-
spec.libs << 'lib' << 'spec'
|
28
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
29
11
|
end
|
12
|
+
require 'rake'
|
30
13
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = 'xls_to_csv-paperclip-processor'
|
18
|
+
gem.homepage = 'http://github.com/igor-alexandrov/xls_to_csv-paperclip-processor'
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Gem for easy convertation .xls to .csv with Paperclip}
|
21
|
+
gem.description = %Q{If you want to convert .xls to .csv simply and unwittingly, then this gem is for you!}
|
22
|
+
gem.email = "igor.alexandrov@gmail.com"
|
23
|
+
gem.authors = ["Igor Alexandrov"]
|
24
|
+
# dependencies defined in Gemfile
|
35
25
|
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
36
27
|
|
37
|
-
|
28
|
+
require 'rake/rdoctask'
|
29
|
+
Rake::RDocTask.new do |rdoc|
|
30
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
38
31
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
YARD::Rake::YardocTask.new
|
44
|
-
rescue LoadError
|
45
|
-
task :yardoc do
|
46
|
-
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
47
|
-
end
|
32
|
+
rdoc.rdoc_dir = 'rdoc'
|
33
|
+
rdoc.title = "xls_to_csv-paperclip-processor #{version}"
|
34
|
+
rdoc.rdoc_files.include('README*')
|
35
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
48
36
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -1,35 +1,46 @@
|
|
1
1
|
require 'paperclip'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
2
|
+
class Paperclip::XlsToCsv < Paperclip::Processor
|
3
|
+
attr_accessor :file, :params, :format
|
4
|
+
|
5
|
+
def initialize(file, options = {}, attachment = nil)
|
6
|
+
super
|
7
|
+
|
8
|
+
@file = file
|
9
|
+
@params = options[:params]
|
10
|
+
@current_format = File.extname(@file.path)
|
11
|
+
@basename = File.basename(@file.path, @current_format)
|
12
|
+
@format = options[:format]
|
13
|
+
end
|
14
|
+
|
15
|
+
def make
|
16
|
+
src = @file
|
17
|
+
dst = Tempfile.new([@basename, @format ? "#{@format}" : 'csv'].compact.join("."))
|
18
|
+
|
19
|
+
begin
|
20
|
+
Paperclip.run(self.command, self.parameters, :source => File.expand_path(src.path),:dest => File.expand_path(dst.path))
|
21
|
+
rescue StandardError => e
|
22
|
+
raise Paperclip::StandardError, "There was an error converting #{@basename} to csv: #{e.message}"
|
13
23
|
end
|
14
24
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
return dst
|
25
|
+
return dst
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def command
|
31
|
+
@current_format == '.xls' ? 'xls2csv' : 'cp'
|
32
|
+
end
|
33
|
+
|
34
|
+
def parameters
|
35
|
+
p = []
|
36
|
+
|
37
|
+
if self.command == 'xls2csv'
|
38
|
+
p << [@params, ":source", "> :dest"]
|
39
|
+
else
|
40
|
+
p << [":source", ":dest"]
|
33
41
|
end
|
42
|
+
|
43
|
+
p.flatten.compact.join(" ").strip.squeeze(" ")
|
34
44
|
end
|
45
|
+
|
35
46
|
end
|
@@ -4,46 +4,47 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.
|
7
|
+
s.name = "xls_to_csv-paperclip-processor"
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Igor Alexandrov"]
|
12
|
-
s.date =
|
13
|
-
s.description =
|
14
|
-
s.email =
|
12
|
+
s.date = "2012-07-13"
|
13
|
+
s.description = "If you want to convert .xls to .csv simply and unwittingly, then this gem is for you!"
|
14
|
+
s.email = "igor.alexandrov@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"README.md"
|
17
17
|
]
|
18
18
|
s.files = [
|
19
|
+
"Gemfile",
|
19
20
|
"README.md",
|
20
21
|
"Rakefile",
|
21
22
|
"VERSION",
|
22
23
|
"lib/xls_to_csv-paperclip-processor.rb",
|
23
24
|
"xls_to_csv-paperclip-processor.gemspec"
|
24
25
|
]
|
25
|
-
s.homepage =
|
26
|
+
s.homepage = "http://github.com/igor-alexandrov/xls_to_csv-paperclip-processor"
|
26
27
|
s.licenses = ["MIT"]
|
27
28
|
s.require_paths = ["lib"]
|
28
|
-
s.rubygems_version =
|
29
|
-
s.summary =
|
29
|
+
s.rubygems_version = "1.8.15"
|
30
|
+
s.summary = "Gem for easy convertation .xls to .csv with Paperclip"
|
30
31
|
|
31
32
|
if s.respond_to? :specification_version then
|
32
33
|
s.specification_version = 3
|
33
34
|
|
34
35
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
35
|
-
s.add_runtime_dependency(%q<paperclip>, [">= 2.
|
36
|
-
s.add_development_dependency(%q<
|
37
|
-
s.add_development_dependency(%q<
|
36
|
+
s.add_runtime_dependency(%q<paperclip>, [">= 2.5.0"])
|
37
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
38
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
38
39
|
else
|
39
|
-
s.add_dependency(%q<paperclip>, [">= 2.
|
40
|
-
s.add_dependency(%q<
|
41
|
-
s.add_dependency(%q<
|
40
|
+
s.add_dependency(%q<paperclip>, [">= 2.5.0"])
|
41
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
42
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
42
43
|
end
|
43
44
|
else
|
44
|
-
s.add_dependency(%q<paperclip>, [">= 2.
|
45
|
-
s.add_dependency(%q<
|
46
|
-
s.add_dependency(%q<
|
45
|
+
s.add_dependency(%q<paperclip>, [">= 2.5.0"])
|
46
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
47
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
47
48
|
end
|
48
49
|
end
|
49
50
|
|
metadata
CHANGED
@@ -1,114 +1,89 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: xls_to_csv-paperclip-processor
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 1
|
10
|
-
version: 0.1.1
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Igor Alexandrov
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-07-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: paperclip
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70298183709460 !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 2
|
32
|
-
- 3
|
33
|
-
- 0
|
34
|
-
version: 2.3.0
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.5.0
|
35
22
|
type: :runtime
|
36
|
-
version_requirements: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: rspec
|
39
23
|
prerelease: false
|
40
|
-
|
24
|
+
version_requirements: *70298183709460
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: bundler
|
27
|
+
requirement: &70298183744220 !ruby/object:Gem::Requirement
|
41
28
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
|
46
|
-
segments:
|
47
|
-
- 0
|
48
|
-
version: "0"
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
49
33
|
type: :development
|
50
|
-
version_requirements: *id002
|
51
|
-
- !ruby/object:Gem::Dependency
|
52
|
-
name: yard
|
53
34
|
prerelease: false
|
54
|
-
|
35
|
+
version_requirements: *70298183744220
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: jeweler
|
38
|
+
requirement: &70298183742320 !ruby/object:Gem::Requirement
|
55
39
|
none: false
|
56
|
-
requirements:
|
57
|
-
- -
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
|
60
|
-
segments:
|
61
|
-
- 0
|
62
|
-
version: "0"
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.6.4
|
63
44
|
type: :development
|
64
|
-
|
65
|
-
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70298183742320
|
47
|
+
description: If you want to convert .xls to .csv simply and unwittingly, then this
|
48
|
+
gem is for you!
|
66
49
|
email: igor.alexandrov@gmail.com
|
67
50
|
executables: []
|
68
|
-
|
69
51
|
extensions: []
|
70
|
-
|
71
|
-
extra_rdoc_files:
|
52
|
+
extra_rdoc_files:
|
72
53
|
- README.md
|
73
|
-
files:
|
54
|
+
files:
|
55
|
+
- Gemfile
|
74
56
|
- README.md
|
75
57
|
- Rakefile
|
76
58
|
- VERSION
|
77
59
|
- lib/xls_to_csv-paperclip-processor.rb
|
78
60
|
- xls_to_csv-paperclip-processor.gemspec
|
79
|
-
has_rdoc: true
|
80
61
|
homepage: http://github.com/igor-alexandrov/xls_to_csv-paperclip-processor
|
81
|
-
licenses:
|
62
|
+
licenses:
|
82
63
|
- MIT
|
83
64
|
post_install_message:
|
84
65
|
rdoc_options: []
|
85
|
-
|
86
|
-
require_paths:
|
66
|
+
require_paths:
|
87
67
|
- lib
|
88
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
69
|
none: false
|
90
|
-
requirements:
|
91
|
-
- -
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
|
94
|
-
segments:
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
segments:
|
95
75
|
- 0
|
96
|
-
|
97
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
hash: -3794122404308807782
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
78
|
none: false
|
99
|
-
requirements:
|
100
|
-
- -
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
|
103
|
-
segments:
|
104
|
-
- 0
|
105
|
-
version: "0"
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
106
83
|
requirements: []
|
107
|
-
|
108
84
|
rubyforge_project:
|
109
|
-
rubygems_version: 1.
|
85
|
+
rubygems_version: 1.8.15
|
110
86
|
signing_key:
|
111
87
|
specification_version: 3
|
112
88
|
summary: Gem for easy convertation .xls to .csv with Paperclip
|
113
89
|
test_files: []
|
114
|
-
|