voltron-upload 0.2.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.
@@ -0,0 +1,446 @@
1
+ /*
2
+ *= require dropzone
3
+ */
4
+
5
+ $theme-color: #234051;
6
+
7
+ $hover-border-color: #234051;
8
+ $hover-background-color: lighten($hover-border-color, 75%);
9
+ $link-color: #234051;
10
+
11
+ $error-text-color: #FFFFFF;
12
+ $error-background-color: #BE2626;
13
+
14
+ $error-progress-color: #BE2626;
15
+ $success-progress-color: #008000;
16
+
17
+ .dropzone {
18
+
19
+ /**
20
+ * Vertical Tile Layout
21
+ * +---------------+
22
+ * | |
23
+ * | |
24
+ * | PIC |
25
+ * | |
26
+ * | |
27
+ * |---------------|
28
+ * | ABC 0.1MB |
29
+ * | remove |
30
+ * +---------------+
31
+ */
32
+ &.dz-layout-vertical_tile {
33
+ transition: border-color 300ms ease-out, background-color 300ms ease-out;
34
+ border-width: 1px;
35
+ padding: 16px;
36
+
37
+ &.dz-drag-hover {
38
+ border-color: $hover-border-color;
39
+ background-color: $hover-background-color;
40
+ }
41
+
42
+ .dz-preview {
43
+ border: 1px solid #ccc;
44
+ padding: 5px;
45
+ width: 212px;
46
+ box-shadow: 0 2px 5px -1px #aaa;
47
+ margin: 0 16px 0 0;
48
+ box-sizing: border-box;
49
+
50
+ &:hover {
51
+ .dz-image img {
52
+ -webkit-transform: none;
53
+ -moz-transform: none;
54
+ -ms-transform: none;
55
+ -o-transform: none;
56
+ transform: none;
57
+ -webkit-filter: none;
58
+ filter: none;
59
+ }
60
+ }
61
+
62
+ &.dz-success {
63
+ .dz-progress {
64
+ .dz-upload {
65
+ width: 100%;
66
+ background-color: $success-progress-color;
67
+ }
68
+ }
69
+ }
70
+
71
+ &.dz-error {
72
+ .dz-progress {
73
+ .dz-upload {
74
+ width: 100%;
75
+ background-color: $error-progress-color;
76
+ }
77
+ }
78
+ }
79
+
80
+ .dz-image {
81
+ border-radius: 0;
82
+ width: 200px;
83
+ height: 175px;
84
+ }
85
+
86
+ .dz-progress {
87
+ position: static;
88
+ opacity: 1;
89
+ margin-left: 0;
90
+ width: 100%;
91
+ border-radius: 0;
92
+ border: 0;
93
+ margin-top: 0;
94
+ height: 7px;
95
+ -webkit-animation: none;
96
+ -moz-animation: none;
97
+ -ms-animation: none;
98
+ -o-animation: none;
99
+ animation: none;
100
+ .dz-upload {
101
+ transition: background-color 300ms ease-out, width 100ms linear;
102
+ background-color: $theme-color;
103
+ }
104
+ }
105
+
106
+ .dz-details {
107
+ position: static;
108
+ opacity: 1;
109
+ text-align: left;
110
+ padding: 0;
111
+ margin-top: 4px;
112
+
113
+ .dz-info {
114
+ &:before, &:after {
115
+ content: ' ';
116
+ display: table;
117
+ }
118
+
119
+ &:after {
120
+ clear: both;
121
+ }
122
+ }
123
+
124
+ .dz-filename {
125
+ max-width: 60%;
126
+ overflow: hidden;
127
+ text-overflow: ellipsis;
128
+ white-space: nowrap;
129
+ float: left;
130
+ }
131
+
132
+ .dz-size {
133
+ margin-bottom: 0;
134
+ font-size: inherit;
135
+ float: right;
136
+ }
137
+
138
+ .dz-remove {
139
+ margin-top: 4px;
140
+ font-size: 0.9em;
141
+ text-transform: uppercase;
142
+ text-decoration: none;
143
+ color: $link-color;
144
+ float: left;
145
+ &:hover {
146
+ background: none;
147
+ text-decoration: underline;
148
+ }
149
+ }
150
+ }
151
+
152
+ .dz-error-message {
153
+ top: initial;
154
+ bottom: 100%;
155
+ color: $error-text-color;
156
+ border-radius: 0;
157
+ width: 300px;
158
+ padding: 8px;
159
+ left: 50%;
160
+ margin-bottom: 8px;
161
+ -webkit-transform: translateX(-50%);
162
+ -moz-transform: translateX(-50%);
163
+ -ms-transform: translateX(-50%);
164
+ -o-transform: translateX(-50%);
165
+ transform: translateX(-50%);
166
+ &:after {
167
+ top: 100%;
168
+ left: 50%;
169
+ margin-left: -6px;
170
+ border-bottom: 0;
171
+ border-top: 6px solid $error-background-color;
172
+ }
173
+ }
174
+ }
175
+ }
176
+
177
+ /**
178
+ * Horizontal Tile Layout
179
+ * +----------------------------------+
180
+ * | | ABC 0.1MB remove |
181
+ * | PIC |-----------------------|
182
+ * | | Error |
183
+ * | | |
184
+ * +----------------------------------+
185
+ */
186
+ &.dz-layout-horizontal_tile {
187
+ transition: border-color 300ms ease-out, background-color 300ms ease-out;
188
+ border-width: 1px;
189
+ padding: 16px;
190
+
191
+ &.dz-drag-hover {
192
+ border-color: $hover-border-color;
193
+ background-color: $hover-background-color;
194
+ }
195
+
196
+ .dz-preview {
197
+ border: 1px solid #ccc;
198
+ padding: 5px;
199
+ width: 24%;
200
+ box-shadow: 0 2px 5px -1px #aaa;
201
+ margin: 0 1.3333% 16px 0;
202
+ box-sizing: border-box;
203
+ min-height: 0;
204
+
205
+ &:nth-child(4n+1){
206
+ margin-right: 0;
207
+ }
208
+
209
+ &:hover {
210
+ .dz-image img {
211
+ -webkit-transform: none;
212
+ -moz-transform: none;
213
+ -ms-transform: none;
214
+ -o-transform: none;
215
+ transform: none;
216
+ -webkit-filter: none;
217
+ filter: none;
218
+ }
219
+ }
220
+
221
+ &.dz-success {
222
+ .dz-progress {
223
+ .dz-upload {
224
+ width: 100%;
225
+ background-color: $success-progress-color;
226
+ }
227
+ }
228
+ }
229
+
230
+ &.dz-error {
231
+ .dz-progress {
232
+ .dz-upload {
233
+ width: 100%;
234
+ background-color: $error-progress-color;
235
+ }
236
+ }
237
+ }
238
+
239
+ .dz-image {
240
+ border-radius: 0;
241
+ width: 80px;
242
+ height: 80px;
243
+ float: left;
244
+ img {
245
+ width: 80px;
246
+ height: 80px;
247
+ }
248
+ }
249
+
250
+ .dz-progress {
251
+ position: static;
252
+ opacity: 1;
253
+ margin-left: 0;
254
+ width: 100%;
255
+ border-radius: 0;
256
+ border: 0;
257
+ margin-top: 4px;
258
+ height: 3px;
259
+ float: left;
260
+ -webkit-animation: none;
261
+ -moz-animation: none;
262
+ -ms-animation: none;
263
+ -o-animation: none;
264
+ animation: none;
265
+
266
+ &:before, &:after {
267
+ content: ' ';
268
+ display: table;
269
+ }
270
+
271
+ &:after {
272
+ clear: both;
273
+ }
274
+
275
+ .dz-upload {
276
+ transition: background-color 300ms ease-out, width 100ms linear;
277
+ background-color: $theme-color;
278
+ }
279
+ }
280
+
281
+ .dz-details {
282
+ position: static;
283
+ opacity: 1;
284
+ text-align: left;
285
+ padding: 0;
286
+ margin-left: 85px;
287
+ min-width: 0;
288
+ max-width: none;
289
+
290
+ .dz-info {
291
+ float: left;
292
+ width: 100%;
293
+ &:before, &:after {
294
+ content: ' ';
295
+ display: table;
296
+ }
297
+
298
+ &:after {
299
+ clear: both;
300
+ }
301
+ }
302
+
303
+ .dz-filename {
304
+ max-width: 60%;
305
+ overflow: hidden;
306
+ text-overflow: ellipsis;
307
+ white-space: nowrap;
308
+ float: left;
309
+ }
310
+
311
+ .dz-size {
312
+ width: 15%;
313
+ margin-bottom: 0;
314
+ font-size: inherit;
315
+ white-space: nowrap;
316
+ float: left;
317
+ &:before {
318
+ content: '\00B7';
319
+ display: inline-block;
320
+ width: 14px;
321
+ text-align: center;
322
+ }
323
+ }
324
+
325
+ .dz-remove {
326
+ font-size: 0.9em;
327
+ text-transform: uppercase;
328
+ text-decoration: none;
329
+ color: $link-color;
330
+ float: right;
331
+ &:hover {
332
+ background: none;
333
+ text-decoration: underline;
334
+ }
335
+ }
336
+
337
+ .dz-error-message {
338
+ position: static;
339
+ padding: 0;
340
+ opacity: 1;
341
+ background: none;
342
+ font-size: 0.9em;
343
+ width: 100%;
344
+ line-height: 1.4;
345
+ margin-top: 3px;
346
+ color: $error-background-color;
347
+ float: left;
348
+ &:after {
349
+ content: normal;
350
+ }
351
+ }
352
+ }
353
+ }
354
+ }
355
+
356
+ /**
357
+ * Progress Bar Layout
358
+ * Intended as a one-and-done upload flow where you upload and
359
+ * then something happens outside the upload container
360
+ * (i.e. - image cropper loads an uploaded image)
361
+ *
362
+ * +----------------------------------+
363
+ * |%%%%%%%%%%%%%%%| |
364
+ * |%%%%%%%%%%%%%%%|ROP FILES HERE |
365
+ * |%%%%%%%%%%%%%%%| |
366
+ * +----------------------------------+
367
+ */
368
+ &.dz-layout-progress {
369
+ padding: 0;
370
+ position: relative;
371
+ height: 42px;
372
+ border-width: 1px;
373
+
374
+ .dz-message {
375
+ margin: 0;
376
+ height: 40px;
377
+ line-height: 40px;
378
+ position: absolute;
379
+ width: 100%;
380
+ text-align: center;
381
+ top: 0;
382
+ left: 0;
383
+ display: block;
384
+ }
385
+
386
+ .dz-preview {
387
+ // Keep preview from blocking the clickable area by making it 0px high
388
+ min-height: 0;
389
+ height: 0;
390
+ width: 100%;
391
+ margin: 0;
392
+ background: none;
393
+
394
+ .dz-progress {
395
+ margin-top: 0;
396
+ margin-left: 0;
397
+ position: relative;
398
+ width: 100%;
399
+ left: 0;
400
+ top: 0;
401
+ border-radius: 0;
402
+ height: 40px;
403
+ border: 0;
404
+ background: none;
405
+
406
+ .dz-upload {
407
+ background: $theme-color;
408
+ }
409
+ }
410
+
411
+ .dz-error-message {
412
+ top: initial;
413
+ bottom: 100%;
414
+ color: $error-text-color;
415
+ border-radius: 0;
416
+ width: 300px;
417
+ padding: 8px;
418
+ left: 50%;
419
+ margin-left: -150px;
420
+ margin-bottom: 8px;
421
+ text-align: center;
422
+ &:after {
423
+ top: 100%;
424
+ left: 50%;
425
+ margin-left: -6px;
426
+ border-bottom: 0;
427
+ border-top: 6px solid $error-background-color;
428
+ }
429
+ }
430
+
431
+ &.dz-complete {
432
+ &:hover {
433
+ .dz-error-message {
434
+ opacity: 1;
435
+ }
436
+ }
437
+ }
438
+
439
+ &.dz-error {
440
+ .dz-error-message {
441
+ opacity: 1;
442
+ }
443
+ }
444
+ }
445
+ }
446
+ }
@@ -0,0 +1,18 @@
1
+ <div class="dz-preview dz-file-preview">
2
+ <div class="dz-image">
3
+ <img data-dz-thumbnail />
4
+ </div>
5
+ <div class="dz-details">
6
+ <div class="dz-info">
7
+ <div class="dz-filename" data-dz-name></div>
8
+ <div class="dz-size" data-dz-size></div>
9
+ <a class="dz-remove" href="javascript:undefined;" data-dz-remove>Remove</a>
10
+ </div>
11
+ <div class="dz-progress">
12
+ <span class="dz-upload" data-dz-uploadprogress></span>
13
+ </div>
14
+ <div class="dz-error-message">
15
+ <span data-dz-errormessage></span>
16
+ </div>
17
+ </div>
18
+ </div>
@@ -0,0 +1,8 @@
1
+ <div class="dz-preview dz-file-preview">
2
+ <div class="dz-progress">
3
+ <span class="dz-upload" data-dz-uploadprogress></span>
4
+ </div>
5
+ <div class="dz-error-message">
6
+ <span data-dz-errormessage></span>
7
+ </div>
8
+ </div>
@@ -0,0 +1,18 @@
1
+ <div class="dz-preview dz-file-preview">
2
+ <div class="dz-image">
3
+ <img data-dz-thumbnail />
4
+ </div>
5
+ <div class="dz-progress">
6
+ <span class="dz-upload" data-dz-uploadprogress></span>
7
+ </div>
8
+ <div class="dz-details">
9
+ <div class="dz-info">
10
+ <div class="dz-filename" data-dz-name></div>
11
+ <div class="dz-size" data-dz-size></div>
12
+ </div>
13
+ <a class="dz-remove" href="javascript:undefined;" data-dz-remove>Remove</a>
14
+ </div>
15
+ <div class="dz-error-message">
16
+ <span data-dz-errormessage></span>
17
+ </div>
18
+ </div>
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "voltron/upload"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
1
+ module Voltron
2
+ module Upload
3
+ module Generators
4
+ module Install
5
+ class AssetsGenerator < Rails::Generators::Base
6
+
7
+ source_root File.expand_path('../../../../../../', __FILE__)
8
+
9
+ desc 'Install Voltron Upload assets'
10
+
11
+ def copy_javascripts_assets
12
+ copy_file 'app/assets/javascripts/voltron-upload.js', Rails.root.join('app', 'assets', 'javascripts', 'voltron-upload.js')
13
+ copy_file 'app/assets/javascripts/dropzone.js', Rails.root.join('app', 'assets', 'javascripts', 'dropzone.js')
14
+ end
15
+
16
+ def copy_stylesheets_assets
17
+ copy_file 'app/assets/stylesheets/voltron-upload.scss', Rails.root.join('app', 'assets', 'stylesheets', 'voltron-upload.scss')
18
+ copy_file 'app/assets/stylesheets/dropzone.scss', Rails.root.join('app', 'assets', 'stylesheets', 'dropzone.scss')
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ module Voltron
2
+ module Upload
3
+ module Generators
4
+ module Install
5
+ class ViewsGenerator < Rails::Generators::Base
6
+
7
+ source_root File.expand_path('../../../../../../', __FILE__)
8
+
9
+ desc 'Install Voltron Upload views'
10
+
11
+ def copy_views
12
+ copy_file 'app/views/voltron/upload/preview/_horizontal_tile.html.erb', Rails.root.join('app', 'views', 'voltron', 'upload', 'preview', '_horizontal_tile.html.erb')
13
+ copy_file 'app/views/voltron/upload/preview/_vertical_tile.html.erb', Rails.root.join('app', 'views', 'voltron', 'upload', 'preview', '_vertical_tile.html.erb')
14
+ copy_file 'app/views/voltron/upload/preview/_progress.html.erb', Rails.root.join('app', 'views', 'voltron', 'upload', 'preview', '_progress.html.erb')
15
+ end
16
+
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,57 @@
1
+ module Voltron
2
+ module Upload
3
+ module Generators
4
+ class InstallGenerator < Rails::Generators::Base
5
+
6
+ source_root File.expand_path("../../../templates", __FILE__)
7
+
8
+ desc "Add Voltron Upload initializer"
9
+
10
+ def inject_initializer
11
+
12
+ voltron_initialzer_path = Rails.root.join("config", "initializers", "voltron.rb")
13
+
14
+ unless File.exist? voltron_initialzer_path
15
+ unless system("cd #{Rails.root.to_s} && rails generate voltron:install")
16
+ puts "Voltron initializer does not exist. Please ensure you have the 'voltron' gem installed and run `rails g voltron:install` to create it"
17
+ return false
18
+ end
19
+ end
20
+
21
+ current_initiailzer = File.read voltron_initialzer_path
22
+
23
+ unless current_initiailzer.match(Regexp.new(/# === Voltron Upload Configuration ===/))
24
+ inject_into_file(voltron_initialzer_path, after: "Voltron.setup do |config|\n") do
25
+ <<-CONTENT
26
+
27
+ # === Voltron Upload Configuration ===
28
+
29
+ # Whether or not calls to file_field should generate markup for dropzone uploads
30
+ # If false, simply returns what file_field would return normally
31
+ # config.upload.enabled = true
32
+
33
+ # Global defaults for Dropzone's with a defined preview template
34
+ # Should be a hash of keys matching a preview partial name,
35
+ # with a value hash containing any of the Dropzone configuration options
36
+ # found at http://www.dropzonejs.com/#configuration-options
37
+ config.upload.previews = {
38
+ vertical_tile: {
39
+ thumbnailWidth: 200,
40
+ thumbnailHeight: 175,
41
+ dictRemoveFile: 'Remove',
42
+ dictCancelUpload: 'Cancel'
43
+ },
44
+
45
+ horizontal_tile: {
46
+ dictRemoveFile: 'Remove',
47
+ dictCancelUpload: 'Cancel'
48
+ }
49
+ }
50
+ CONTENT
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,18 @@
1
+ module Voltron
2
+ class Config
3
+
4
+ def upload
5
+ @upload ||= Upload.new
6
+ end
7
+
8
+ class Upload
9
+
10
+ attr_accessor :enabled, :previews
11
+
12
+ def initialize
13
+ @enabled ||= true
14
+ @previews ||= {}
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ module Voltron
2
+ module Upload
3
+ module Routes
4
+
5
+ def upload_for(resource, options={})
6
+ controller = resource.to_s.underscore
7
+ options = options.with_indifferent_access
8
+
9
+ options[:path] ||= "/#{controller}/upload"
10
+ options[:controller] ||= controller
11
+
12
+ post options[:path].gsub(/(^\/+|\/+$)/, ''), to: "#{options[:controller]}#upload", as: "upload_#{controller}"
13
+ end
14
+
15
+ end
16
+ end
17
+ end