voltron-upload 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f264918ab9c54f6a1a5092cde1a7ea0e152a208fcbd71cc138f801fef01944c7
4
+ data.tar.gz: 53133b595dd837e97017358af5642fd34d2636b0a475c92dfe9fa56ad465910f
5
+ SHA512:
6
+ metadata.gz: 155183ca91d5eb778f578dd4d98b733b7351e0c8f21cebbb399f41ceea1a2f6b4b71df201e16cc649b173eaecc08baf7313748ce5f6c8eb403b71c08dbf65411
7
+ data.tar.gz: 74c5ab8e58001ce39720c24eb1afd8a4db53b2fc98a92f6743ab7746e9672ce7108512a7fa80c19ab513b6239f77c6749fe2111b104624a8392b40cc651de181
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ tmp/
10
+ log/
11
+ voltron-*.gem
12
+ *.bak
13
+ public/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.3
5
+ - 2.3.1
6
+ - 2.3.3
7
+ - 2.4.1
8
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at eric.hainer@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+ source 'https://gem.minow.io'
3
+
4
+ gemspec
5
+
6
+ gem 'pry'
7
+ gem 'pry-byebug'
8
+
9
+ group :test do
10
+ gem 'coveralls', require: false
11
+ gem 'jquery-rails', '~> 4'
12
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Eric Hainer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,166 @@
1
+ [![Coverage Status](https://coveralls.io/repos/github/ehainer/voltron-upload/badge.svg?branch=master)](https://coveralls.io/github/ehainer/voltron-upload?branch=master)
2
+ [![Build Status](https://travis-ci.org/ehainer/voltron-upload.svg?branch=master)](https://travis-ci.org/ehainer/voltron-upload)
3
+ [![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0)
4
+
5
+ # Voltron::Upload
6
+
7
+ Voltron upload brings [Dropzone JS](http://www.dropzonejs.com/) and logical file upload & committing to rails resources. It is an attempt to solve the issue of dropzone js uploading files immediately, often times before the resource itself has been saved (i.e. - User registration, where one might be able to upload an avatar)
8
+
9
+ The nice feature of Voltron Upload is that it requires very little additional code outside of what would be required by [CarrierWave](https://github.com/carrierwaveuploader/carrierwave) and gracefully can fall back to default file field inputs in the event that Dropzone is not supported.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'voltron-upload', '~> 0.2.0'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle install
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install voltron-upload
26
+
27
+ Then run the following to create the voltron.rb initializer (if not exists already) and add the upload config:
28
+
29
+ $ rails g voltron:upload:install
30
+
31
+ Also, include the necessary js and css by adding the following to your application.js and application.css respectively
32
+
33
+ ```javascript
34
+ //= require voltron-upload
35
+ ```
36
+
37
+ ```css
38
+ /*
39
+ *= require voltron-upload
40
+ */
41
+ ```
42
+
43
+ If you want to customize the out-of-the-box functionality or styles, you can copy the assets (javascript/css) to your app assets directory by running:
44
+
45
+ $ rails g voltron:upload:install:assets
46
+
47
+ Optionlly, you may copy the few out-of-the-box preview template views to your app by running:
48
+
49
+ $ rails g voltron:upload:install:views
50
+
51
+ The views will be installed in the directory `<rails_root>/app/views/voltron/upload/preview/`
52
+
53
+ ## Usage
54
+
55
+ Voltron upload is designed to work as seamlessly as possible with how native carrierwave functionality does. Given a model `User`, you could have something like the following:
56
+
57
+ ```ruby
58
+ class User < ActiveRecord::Base
59
+
60
+ mount_uploader :avatar, AvatarUploader
61
+
62
+ mount_uploaders :images, ImageUploader # For multiple uploads
63
+
64
+ end
65
+ ```
66
+
67
+ Your controller only needs a call to `uploadable` to include the necessary route actions:
68
+
69
+ ```ruby
70
+ class UsersController < ApplicationController
71
+
72
+ uploadable :user
73
+
74
+ end
75
+ ```
76
+
77
+ The only argument to `uploadable` is the name of the model you'll be associating the uploads with, and is also optional. If omitted, Voltron Upload will try to determine it by the controller name. A controller named `UsersController` will look for a model named `User`, `PeopleController` will look for a model named `Person`, etc... If you have any doubts in it's ability to determine the model, just define it like shown above.
78
+
79
+ Lastly, you need to include the routes in your routes.rb config file:
80
+
81
+ ```ruby
82
+ Rails.application.routes.draw do
83
+
84
+ upload_for :people
85
+
86
+ # Or, explicitly define route parameters
87
+
88
+ # Will route the path to 'person#upload' as `upload_people_path`/`upload_people_url`
89
+ upload_for :people, { path: '/person/upload', controller: :person }
90
+
91
+ end
92
+ ```
93
+
94
+ As for your markup, Voltron Upload overrides the `file_field` helper method, but the options remain the same so nothing out of the ordinary needs to change. However, additional parameters are possible:
95
+
96
+ | Parameter | Default | Comment |
97
+ |-----------|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
98
+ | default | false | If true, forces the file_field to fallback to the default file field input. |
99
+ | preserve | true | If false, causes uploaded files to not persist in the Dropzone container. Useful for one-off uploads that trigger something else, like image cropping functionality. In that case you likely wouldn't want the uploaded files preview container to be visible, since you'd likely have just a progress bar instead. |
100
+ | preview | nil | Can be either the name of a preview partial found in `app/views/voltron/upload/preview` or raw html markup representing the Dropzone preview. If the defined preview partial name could not be found, or is not defined, it will fallback to the [default dropzone preview template](http://www.dropzonejs.com/#layout). Note that it will attempt to parse the preview template name even if html is provided, by stripping away all markup and using the leftover text as the preview name. i.e. - `preview: :progress` is seen the same as `preview: '<div style="height: 1px;"><span>progress</span></div>'` |
101
+ | options | nil | If defined, should be a hash of [Dropzone JS configuration options](http://www.dropzonejs.com/#configuration-options). Options defined here override the global configuration options of the matching preview, if any (see: Configuration) Hash keys can be defined as either camelCase or snake_case. (i.e. - dictDefaultMessage or dict_default_message) |
102
+
103
+ ## Configuration
104
+
105
+ There are two global config settings that will be found in `config/initializers/voltron.rb` once the installer is run.
106
+
107
+ | Option | Default | Comment |
108
+ |----------|------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
109
+ | enabled | true | Whether or not the file input fields should be converted to Dropzones. The master on/off switch for the whole thing. |
110
+ | previews | empty hash | Sets global Dropzone JS configuration settings for Dropzones utilizing a matching preview template. Running the installer will include some preview settings for out-of-the-box preview templates, which can be a good reference. The general format is that of a nested hash, where each key maps to a preview view name, and the value is a hash of options for Dropzones utilizing that preview template, i.e. - `{ preview_name: { dictDefaultMessage: 'Drop files here', parallelUploads: 10, etc... } }`|
111
+
112
+ ## Theming
113
+
114
+ Voltron Upload comes preloaded with 3 [preview template themes](http://www.dropzonejs.com/#layout), a horizontal tile layout, vertical tile layout, and progress bar layout. If/when you decide to add new preview templates, they should be added as partial views in the `app/views/voltron/upload/preview/` directory. The name of the view then defines the preview name when used in conjunction with the `file_field` method:
115
+
116
+ ```ruby
117
+ <%= f.file_field :avatar, preview: :horizontal_tile # maps to the _horizontal_tile.html.erb view %>
118
+ ```
119
+ as well as ties to the associated global config:
120
+ ```ruby
121
+ Voltron.setup do |config|
122
+ config.upload.previews = {
123
+ horizontal_tile: {
124
+ dictDefaultMessage: 'Drop files here',
125
+ dictCancelUpload: 'Cancel',
126
+ parallelUploads: 10,
127
+ # and so on...
128
+ }
129
+ }
130
+ end
131
+ ```
132
+
133
+ If the preview template name defined maps to an existing preview view (in the above case, `app/views/voltron/upload/preview/_horizontal_tile.html.erb`) an additional css class will be added to the Dropzone wrapper element matching the format `dz-layout-<preview name>`, i.e. - `dz-layout-horizontal_tile`
134
+
135
+ From there, you can theme using the generated class name from within voltron-upload.scss. If the file is not in your assets directory run the views installer to add it. (see Installation above)
136
+
137
+ ## Events
138
+
139
+ Several events are dispatched throughout the course of the upload process, listed with each event's arguments below. Note that in keeping with the Voltron standard of each dispatched object having a `data`, `event`, and `element` parameter, each will appear in the dispatched object. However, whether or not all 3 parameters have content varies. Not all events below have "data" associated, so while `data` will appear in the dispatched object, it is possible to be empty. See the specifics of each event to understand.
140
+
141
+ To observe any of the events, simply define the listed **callback function** in any other Voltron module of your choosing. The single argument will be an object containing the listed data (keys)
142
+
143
+ | Event Name | Callback Function | Data | Comment |
144
+ |--------------------|---------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
145
+ | upload:initialized | onUploadInitialized | <ul><li>**upload:** The Voltron Upload JS instance</li> <li>**dropzone:** The Dropzone instance</li> <li>**element:** The DOM element of the hidden file input field</li></ul> | Dispatched after a Dropzone is instantiated on a given field upload field. |
146
+ | upload:sending | onUploadSending | <ul><li>**upload:** The Voltron Upload JS instance</li> <li>**form:** The DOM element of the form that wraps the Dropzone</li> <li>**file:** An instance of a javascript [File](https://developer.mozilla.org/en-US/docs/Web/API/File)</li> <li>**xhr:** An instance of an [XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) object</li> <li>**data:** An instance of javascript's [FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData)</li> <li>**element:** The DOM element of the hidden file input field</li></ul> | Dispatched prior to a file being uploaded. Can be observed with the purposes of injecting additional fields into the FormData, or to manipulate the AJAX request before the request is sent |
147
+ | upload:complete | onUploadComplete | <ul><li>**upload:** The Voltron Upload JS instance</li> <li>**file:** An instance of a javascript [File](https://developer.mozilla.org/en-US/docs/Web/API/File)</li> <li>**data:** The resulting JSON from the upload process. Will contain information about the uploaded file (size, url, etc.)</li> <li>**element:** The DOM element of the hidden file input field</li></ul> | Dispatched after a file is uploaded successfully |
148
+ | upload:removed | onUploadRemoved | <ul><li>**upload:** The Voltron Upload JS instance</li><li>**file:** An instance of a javascript [File](https://developer.mozilla.org/en-US/docs/Web/API/File)</li><li>**element:** The DOM element of the hidden file input field</li></ul> | Dispatched after a file is removed from the Dropzone. This does not mean that the file has actually been deleted, just that it's been "flagged" for deleting when the form is submitted |
149
+ | upload:error | onUploadError | <ul><li>**upload:** The Voltron Upload JS instance</li><li>**file:** An instance of a javascript [File](https://developer.mozilla.org/en-US/docs/Web/API/File)</li><li>**data:** Will always be an array of one or more error messages</li><li>**element:** The DOM element of the hidden file input field</li></ul> | Dispatched whenever an error occurs. Look to the `response` argument for the resulting message(s) |
150
+
151
+ ## Note
152
+
153
+ Just due to the way CarrierWave caches files, the process of uploading can produce a fair number of caches files. Voltron does not clean up those files itself, so it is up to the developer to implement some sort of cache cleanup process. CarrierWave does provide a [clean_cached_files!](http://www.rubydoc.info/github/jnicklas/carrierwave/CarrierWave/Uploader/Cache/ClassMethods) method that should take care of everything, or one could write a custom rake task to deal with it by means of [whenever](https://github.com/javan/whenever) or some other automated process.
154
+
155
+ ## Development
156
+
157
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
158
+
159
+ ## Contributing
160
+
161
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ehainer/voltron-notify. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
162
+
163
+ ## License
164
+
165
+ The gem is available as open source under the terms of the [GNU General Public License](https://www.gnu.org/licenses/gpl-3.0.en.html).
166
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec