xls_to_csv-paperclip-processor 0.1.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/README.md +56 -0
- data/Rakefile +48 -0
- data/VERSION +1 -0
- data/lib/xls_to_csv-paperclip-processor.rb +35 -0
- data/xls_to_csv-paperclip-processor.gemspec +49 -0
- metadata +114 -0
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Ruby on Rails Paperclip xls to csv Processor #
|
2
|
+
|
3
|
+
This gem is Paperclip processor, that uses xls2csv to convert .xls to .csv.
|
4
|
+
|
5
|
+
## Requirements ##
|
6
|
+
|
7
|
+
* [Paperclip][0] ~> 2.3
|
8
|
+
* [xls2csv][2]
|
9
|
+
|
10
|
+
## Installation ##
|
11
|
+
|
12
|
+
gem 'xls_to_csv-paperclip-processor'
|
13
|
+
|
14
|
+
## xls2csv Instalation ##
|
15
|
+
|
16
|
+
Install [xls2csv][2] using your favorite package manager. On OS X, the easiest way to do it is by using [Homebrew][3].
|
17
|
+
|
18
|
+
sudo brew install catdoc
|
19
|
+
|
20
|
+
Various linux distributions should use similar methods with their respected package managers.
|
21
|
+
|
22
|
+
## Using Processor ##
|
23
|
+
|
24
|
+
Use it as you would any other Paperclip processor. In your model:
|
25
|
+
|
26
|
+
class SomeCsvAttachement < ActiveRecord::Base
|
27
|
+
before_post_process :is_xls?
|
28
|
+
has_attached_file :data,
|
29
|
+
:styles => {
|
30
|
+
:csv => {
|
31
|
+
:format => "csv",
|
32
|
+
:params => "-c, -q 3"
|
33
|
+
}
|
34
|
+
},
|
35
|
+
:path => ":rails_root/data/some_csv_attachements/:id_partition/:basename.:extension",
|
36
|
+
:processors => [:xls_to_csv]
|
37
|
+
|
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
|
+
|
48
|
+
end
|
49
|
+
|
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 won't do anything.
|
51
|
+
|
52
|
+
|
53
|
+
[0]: https://github.com/thoughtbot/paperclip
|
54
|
+
[1]: http://rubyonrails.org/
|
55
|
+
[2]: http://search.cpan.org/~ken/xls2csv-1.06/script/xls2csv
|
56
|
+
[3]: http://mxcl.github.com/homebrew/
|
data/Rakefile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
8
|
+
gem.name = "xls_to_csv-paperclip-processor"
|
9
|
+
gem.homepage = "http://github.com/igor-alexandrov/xls_to_csv-paperclip-processor"
|
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']
|
29
|
+
end
|
30
|
+
|
31
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
32
|
+
spec.libs << 'lib' << 'spec'
|
33
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
34
|
+
spec.rcov = true
|
35
|
+
end
|
36
|
+
|
37
|
+
task :spec => :check_dependencies
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
begin
|
42
|
+
require 'yard'
|
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
|
48
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'paperclip'
|
2
|
+
module Paperclip
|
3
|
+
class XlsToCsv < Processor
|
4
|
+
attr_accessor :file, :params, :format
|
5
|
+
|
6
|
+
def initialize file, options = {}, attachment = nil
|
7
|
+
super
|
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}" : ''])
|
18
|
+
begin
|
19
|
+
parameters = []
|
20
|
+
parameters << @params
|
21
|
+
parameters << ":source"
|
22
|
+
parameters << "> :dest"
|
23
|
+
|
24
|
+
parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")
|
25
|
+
|
26
|
+
|
27
|
+
system("touch #{dst.path}")
|
28
|
+
success = Paperclip.run("xls2csv", parameters, :source => File.expand_path(src.path),:dest => File.expand_path(dst.path))
|
29
|
+
rescue PaperclipCommandLineError => e
|
30
|
+
raise PaperclipError, "There was an error converting #{@basename} to csv: #{e.message}"
|
31
|
+
end
|
32
|
+
return dst
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,49 @@
|
|
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{xls_to_csv-paperclip-processor}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Igor Alexandrov"]
|
12
|
+
s.date = %q{2011-05-21}
|
13
|
+
s.description = %q{If you want to convert .xls to .csv simply and unwittingly, then this gem is for you!}
|
14
|
+
s.email = %q{igor.alexandrov@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.md"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"README.md",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION",
|
22
|
+
"lib/xls_to_csv-paperclip-processor.rb",
|
23
|
+
"xls_to_csv-paperclip-processor.gemspec"
|
24
|
+
]
|
25
|
+
s.homepage = %q{http://github.com/igor-alexandrov/xls_to_csv-paperclip-processor}
|
26
|
+
s.licenses = ["MIT"]
|
27
|
+
s.require_paths = ["lib"]
|
28
|
+
s.rubygems_version = %q{1.5.2}
|
29
|
+
s.summary = %q{Gem for easy convertation .xls to .csv with Paperclip}
|
30
|
+
|
31
|
+
if s.respond_to? :specification_version then
|
32
|
+
s.specification_version = 3
|
33
|
+
|
34
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
35
|
+
s.add_runtime_dependency(%q<paperclip>, [">= 2.3.0"])
|
36
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
37
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
38
|
+
else
|
39
|
+
s.add_dependency(%q<paperclip>, [">= 2.3.0"])
|
40
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
41
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
42
|
+
end
|
43
|
+
else
|
44
|
+
s.add_dependency(%q<paperclip>, [">= 2.3.0"])
|
45
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
46
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xls_to_csv-paperclip-processor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Igor Alexandrov
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-05-21 00:00:00 +04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: paperclip
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 3
|
33
|
+
- 0
|
34
|
+
version: 2.3.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
version: "0"
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: yard
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
type: :development
|
64
|
+
version_requirements: *id003
|
65
|
+
description: If you want to convert .xls to .csv simply and unwittingly, then this gem is for you!
|
66
|
+
email: igor.alexandrov@gmail.com
|
67
|
+
executables: []
|
68
|
+
|
69
|
+
extensions: []
|
70
|
+
|
71
|
+
extra_rdoc_files:
|
72
|
+
- README.md
|
73
|
+
files:
|
74
|
+
- README.md
|
75
|
+
- Rakefile
|
76
|
+
- VERSION
|
77
|
+
- lib/xls_to_csv-paperclip-processor.rb
|
78
|
+
- xls_to_csv-paperclip-processor.gemspec
|
79
|
+
has_rdoc: true
|
80
|
+
homepage: http://github.com/igor-alexandrov/xls_to_csv-paperclip-processor
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 3
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
version: "0"
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
hash: 3
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
version: "0"
|
106
|
+
requirements: []
|
107
|
+
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 1.5.2
|
110
|
+
signing_key:
|
111
|
+
specification_version: 3
|
112
|
+
summary: Gem for easy convertation .xls to .csv with Paperclip
|
113
|
+
test_files: []
|
114
|
+
|