upload_documents_tool 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.idea/.rakeTasks +7 -0
- data/.idea/markdown-navigator/profiles_settings.xml +3 -0
- data/.idea/markdown-navigator.xml +72 -0
- data/.idea/misc.xml +4 -0
- data/.idea/modules.xml +8 -0
- data/.idea/upload_documents_tool.iml +63 -0
- data/.idea/vcs.xml +6 -0
- data/.idea/workspace.xml +356 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +175 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/app/assets/javascripts/documents.coffee +33 -0
- data/app/assets/javascripts/progress_bar.js +39 -0
- data/app/assets/javascripts/upload_document_tool.js +2 -0
- data/app/assets/stylesheets/upload_document_tool.scss +0 -0
- data/app/helpers/upload_document_tool_helper.rb +16 -0
- data/app/views/upload_documents_tool/_documents.html.erb +40 -0
- data/app/views/upload_documents_tool/_form.html.erb +21 -0
- data/app/views/upload_documents_tool/_form_error.html.erb +7 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/upload_documents_tool/validators/attachment_content_type_validator.rb +86 -0
- data/lib/upload_documents_tool/validators.rb +69 -0
- data/lib/upload_documents_tool/version.rb +3 -0
- data/lib/upload_documents_tool.rb +48 -0
- data/upload_documents_tool.gemspec +37 -0
- metadata +233 -0
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
require 'active_support/concern'
|
3
|
+
require 'active_support/core_ext/array/wrap'
|
4
|
+
require 'upload_documents_tool/validators/attachment_content_type_validator'
|
5
|
+
|
6
|
+
module UploadDocumentsTool
|
7
|
+
module Validators
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
extend HelperMethods
|
12
|
+
include HelperMethods
|
13
|
+
end
|
14
|
+
|
15
|
+
::UploadDocumentsTool::REQUIRED_VALIDATORS = [AttachmentContentTypeValidator]
|
16
|
+
|
17
|
+
module ClassMethods
|
18
|
+
# This method is a shortcut to validator classes that is in
|
19
|
+
# "Attachment...Validator" format. It is almost the same thing as the
|
20
|
+
# +validates+ method that shipped with Rails, but this is customized to
|
21
|
+
# be using with attachment validators. This is helpful when you're using
|
22
|
+
# multiple attachment validators on a single attachment.
|
23
|
+
#
|
24
|
+
# Example of using the validator:
|
25
|
+
#
|
26
|
+
# validates_attachment :avatar, :presence => true,
|
27
|
+
# :content_type => { :content_type => "image/jpg" },
|
28
|
+
# :size => { :in => 0..10.kilobytes }
|
29
|
+
#
|
30
|
+
def validates_attachment(*attributes)
|
31
|
+
options = attributes.extract_options!.dup
|
32
|
+
|
33
|
+
UploadDocumentsTool::Validators.constants.each do |constant|
|
34
|
+
if constant.to_s =~ /\AAttachment(.+)Validator\z/
|
35
|
+
validator_kind = $1.underscore.to_sym
|
36
|
+
|
37
|
+
if options.has_key?(validator_kind)
|
38
|
+
validator_options = options.delete(validator_kind)
|
39
|
+
validator_options = {} if validator_options == true
|
40
|
+
conditional_options = options.slice(:if, :unless)
|
41
|
+
Array.wrap(validator_options).each do |local_options|
|
42
|
+
method_name = UploadDocumentsTool::Validators.const_get(constant.to_s).helper_method_name
|
43
|
+
send(method_name, attributes, local_options.merge(conditional_options))
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def validate_before_processing(validator_class, options)
|
51
|
+
options = options.dup
|
52
|
+
attributes = options.delete(:attributes)
|
53
|
+
attributes.each do |attribute|
|
54
|
+
options[:attributes] = [attribute]
|
55
|
+
create_validating_before_filter(attribute, validator_class, options)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def create_validating_before_filter(attribute, validator_class, options)
|
60
|
+
if_clause = options.delete(:if)
|
61
|
+
unless_clause = options.delete(:unless)
|
62
|
+
send(:"before_#{attribute}_post_process", :if => if_clause, :unless => unless_clause) do |*args|
|
63
|
+
validator_class.new(options.dup).validate(self)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "upload_documents_tool/version"
|
2
|
+
|
3
|
+
module UploadDocumentsTool
|
4
|
+
|
5
|
+
class Engine < ::Rails::Engine
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize(params = {})
|
9
|
+
@file = params.delete(:file)
|
10
|
+
super
|
11
|
+
if @file
|
12
|
+
self.filename = sanitize_filename(@file.original_filename)
|
13
|
+
self.content_type = @file.content_type
|
14
|
+
self.file_contents = @file.read
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def upload_local
|
19
|
+
path = "#{Rails.root}/public/uploads/document"
|
20
|
+
FileUtils.mkdir_p(path) unless File.exists?(path)
|
21
|
+
FileUtils.copy(@file.tempfile, path)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def sanitize_filename(filename)
|
27
|
+
File.basename(filename)
|
28
|
+
end
|
29
|
+
|
30
|
+
def document_file_format
|
31
|
+
unless ['application/pdf','application/vnd.ms-excel',
|
32
|
+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
33
|
+
'application/msword',
|
34
|
+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
35
|
+
'text/plain', 'text/csv', 'application/octet-stream'].include? self.content_type
|
36
|
+
errors.add(:file, 'Invalid file format.')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
NUM_BYTES_IN_MEGABYTE = 1048576
|
41
|
+
def file_size_under_one_mb
|
42
|
+
if (@file.size.to_f / NUM_BYTES_IN_MEGABYTE) > 1
|
43
|
+
errors.add(:file, 'File size cannot be over one megabyte.')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "upload_documents_tool/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "upload_documents_tool"
|
8
|
+
spec.version = UploadDocumentsTool::VERSION
|
9
|
+
spec.authors = ["Jakub41"]
|
10
|
+
spec.email = ["lemiszewski@gmx.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A tool for upload various kind of documents}
|
13
|
+
spec.description = %q{This tool is an easy way to upload documents of different kind.
|
14
|
+
The package has partials which thanks to a helper, make easier to implement and set inside other application.
|
15
|
+
Is posible then to set the partials views where desired.}
|
16
|
+
spec.homepage = "https://github.com/Jakub41/upload_documents_tool"
|
17
|
+
spec.license = "MIT"
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_dependency("railties", "~> 4.2.6")
|
27
|
+
spec.add_dependency("jquery-rails")
|
28
|
+
spec.add_dependency("kaminari", "~> 1.0.1")
|
29
|
+
spec.add_dependency("bootstrap-kaminari-views", "~> 0.0.5")
|
30
|
+
spec.add_dependency("bootstrap-sass")
|
31
|
+
spec.add_dependency("jasny-bootstrap-rails")
|
32
|
+
spec.add_dependency("font-awesome-sass")
|
33
|
+
spec.add_dependency("toastr-rails")
|
34
|
+
spec.add_development_dependency "bundler", "~> 1.16.a"
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,233 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: upload_documents_tool
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jakub41
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: railties
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.2.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.2.6
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jquery-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: kaminari
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.0.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bootstrap-kaminari-views
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.0.5
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.0.5
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bootstrap-sass
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: jasny-bootstrap-rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: font-awesome-sass
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: toastr-rails
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: bundler
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 1.16.a
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 1.16.a
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rake
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '10.0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '10.0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rspec
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '3.0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '3.0'
|
167
|
+
description: |-
|
168
|
+
This tool is an easy way to upload documents of different kind.
|
169
|
+
The package has partials which thanks to a helper, make easier to implement and set inside other application.
|
170
|
+
Is posible then to set the partials views where desired.
|
171
|
+
email:
|
172
|
+
- lemiszewski@gmx.com
|
173
|
+
executables: []
|
174
|
+
extensions: []
|
175
|
+
extra_rdoc_files: []
|
176
|
+
files:
|
177
|
+
- ".gitignore"
|
178
|
+
- ".idea/.rakeTasks"
|
179
|
+
- ".idea/markdown-navigator.xml"
|
180
|
+
- ".idea/markdown-navigator/profiles_settings.xml"
|
181
|
+
- ".idea/misc.xml"
|
182
|
+
- ".idea/modules.xml"
|
183
|
+
- ".idea/upload_documents_tool.iml"
|
184
|
+
- ".idea/vcs.xml"
|
185
|
+
- ".idea/workspace.xml"
|
186
|
+
- ".rspec"
|
187
|
+
- ".travis.yml"
|
188
|
+
- CODE_OF_CONDUCT.md
|
189
|
+
- Gemfile
|
190
|
+
- Gemfile.lock
|
191
|
+
- LICENSE.txt
|
192
|
+
- README.md
|
193
|
+
- Rakefile
|
194
|
+
- app/assets/javascripts/documents.coffee
|
195
|
+
- app/assets/javascripts/progress_bar.js
|
196
|
+
- app/assets/javascripts/upload_document_tool.js
|
197
|
+
- app/assets/stylesheets/upload_document_tool.scss
|
198
|
+
- app/helpers/upload_document_tool_helper.rb
|
199
|
+
- app/views/upload_documents_tool/_documents.html.erb
|
200
|
+
- app/views/upload_documents_tool/_form.html.erb
|
201
|
+
- app/views/upload_documents_tool/_form_error.html.erb
|
202
|
+
- bin/console
|
203
|
+
- bin/setup
|
204
|
+
- lib/upload_documents_tool.rb
|
205
|
+
- lib/upload_documents_tool/validators.rb
|
206
|
+
- lib/upload_documents_tool/validators/attachment_content_type_validator.rb
|
207
|
+
- lib/upload_documents_tool/version.rb
|
208
|
+
- upload_documents_tool.gemspec
|
209
|
+
homepage: https://github.com/Jakub41/upload_documents_tool
|
210
|
+
licenses:
|
211
|
+
- MIT
|
212
|
+
metadata: {}
|
213
|
+
post_install_message:
|
214
|
+
rdoc_options: []
|
215
|
+
require_paths:
|
216
|
+
- lib
|
217
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
218
|
+
requirements:
|
219
|
+
- - ">="
|
220
|
+
- !ruby/object:Gem::Version
|
221
|
+
version: '0'
|
222
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
223
|
+
requirements:
|
224
|
+
- - ">="
|
225
|
+
- !ruby/object:Gem::Version
|
226
|
+
version: '0'
|
227
|
+
requirements: []
|
228
|
+
rubyforge_project:
|
229
|
+
rubygems_version: 2.6.13
|
230
|
+
signing_key:
|
231
|
+
specification_version: 4
|
232
|
+
summary: A tool for upload various kind of documents
|
233
|
+
test_files: []
|