pretty_file_input 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/.gitignore +5 -1
- data/.travis.yml +13 -0
- data/README.md +66 -1
- data/app/inputs/pretty_file_input_input.rb +1 -1
- data/lib/pretty_file_input/component.rb +6 -6
- data/lib/pretty_file_input/version.rb +1 -1
- data/pretty_file_input.gemspec +8 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +14 -0
- data/spec/dummy/app/assets/javascripts/jquery.form.js +1277 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/users_controller.rb +32 -0
- data/spec/dummy/app/models/user.rb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +15 -0
- data/spec/dummy/app/views/users/_form.html.erb +4 -0
- data/spec/dummy/app/views/users/edit.html.erb +1 -0
- data/spec/dummy/app/views/users/new.html.erb +1 -0
- data/spec/dummy/config/application.rb +26 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +3 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/migrate/20141123205413_create_users.rb +7 -0
- data/spec/dummy/db/schema.rb +20 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/spec/features/users_spec.rb +42 -0
- data/spec/dummy/spec/fixtures/avatar.jpg +0 -0
- data/spec/dummy/spec/fixtures/avatar2.jpg +0 -0
- data/spec/spec_helper.rb +15 -0
- metadata +150 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c168ebe781c32c83a16d009e59fd6ba47248986c
|
4
|
+
data.tar.gz: b23a8b2cce2676ba4a0ce1f20492cbdbc1b99993
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14fca40aa7f82597774a3a66114501a5a48354b0f5ad7af34e98088f0e963f955efc1745c256aabd2d23e5d105160d8289648200d777f5f9fe8cec3a02970b4d
|
7
|
+
data.tar.gz: 88cf5c3de4533a042946b5d7643b55b2f478aa401851d38b99d3e3a57cede42eb033660f5b5ba70771d6e06e48dbce8a3593d3b034bd1fd57a9808b835928bb7
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.9.3
|
4
|
+
- 2.0.0
|
5
|
+
- 2.1.1
|
6
|
+
before_script:
|
7
|
+
- export DISPLAY=:99.0
|
8
|
+
- sh -e /etc/init.d/xvfb start
|
9
|
+
- "cd spec/dummy && RAILS_ENV=test bundle exec rake db:create && RAILS_ENV=test bundle exec rake db:migrate && cd ../../"
|
10
|
+
script:
|
11
|
+
- bundle exec rspec
|
12
|
+
notifications:
|
13
|
+
email: false
|
data/README.md
CHANGED
@@ -1,6 +1,71 @@
|
|
1
|
-
pretty_file_input
|
1
|
+
pretty_file_input [![version]](http://rubygems.org/gems/pretty_file_input) [![build]](https://travis-ci.org/dobtco/pretty_file_input)
|
2
2
|
=======
|
3
3
|
|
4
|
+
pretty_file_input is an attempt to standardize the always-problematic file input in our Rails apps.
|
5
|
+
|
6
|
+
## Benefits
|
7
|
+
|
8
|
+
- Immediate uploads via AJAX for `persisted?` records
|
9
|
+
- Upload percentage displayed while uploading
|
10
|
+
- Identical user interface (without AJAX uploads) for non-`persisted?` records
|
11
|
+
- Use your existing models and controllers, no changes necessary
|
12
|
+
|
13
|
+
## Requirements
|
14
|
+
|
15
|
+
- [carrierwave](https://github.com/carrierwaveuploader/carrierwave)
|
16
|
+
- [simple_form](https://github.com/plataformatec/simple_form) (if using the "Automatic" implementation below)
|
17
|
+
- jQuery
|
18
|
+
- [jquery.form](https://github.com/malsup/form/)
|
19
|
+
|
20
|
+
## Installation
|
21
|
+
|
22
|
+
```sh
|
23
|
+
# Gemfile
|
24
|
+
gem 'dvl-core'
|
25
|
+
|
26
|
+
# application.css
|
27
|
+
*= require pretty_file_input
|
28
|
+
|
29
|
+
# application.js
|
30
|
+
//= require pretty_file_input
|
31
|
+
```
|
32
|
+
|
33
|
+
## Implementation
|
34
|
+
|
35
|
+
There are a couple of ways to use this gem:
|
36
|
+
|
37
|
+
### Automatic
|
38
|
+
|
39
|
+
By taking advantage of the included simple_form input class, you can start using pretty_file_input with as little as one line of code:
|
40
|
+
|
41
|
+
```rb
|
42
|
+
f.input :avatar, as: :pretty_file_input
|
43
|
+
```
|
44
|
+
|
45
|
+
The resulting behavior will depend on whether or not the parent object is already persisted in the database.
|
46
|
+
|
47
|
+
**For existing records**, pretty_file_input will upload and remove files immediately, displaying some nice UI feedback along the way:
|
48
|
+
|
49
|
+

|
50
|
+
|
51
|
+
**For new records**, pretty_file_input will not perform any AJAX requests. (Carrierwave stores files alongside your database records, so it's impossible to upload a file _before_ its associated record has been created.)
|
52
|
+
|
53
|
+
### Manual
|
54
|
+
|
55
|
+
If your use case doesn't fit the patterns above, you can use the "Manual" integration with pretty_file_input. `PrettyFileInput::Component` is an Erector widget that can be customized with the following options:
|
56
|
+
|
57
|
+
```rb
|
58
|
+
:name, # input name that will be sent to the server
|
59
|
+
persisted: false, # is parent object is not persisted, no AJAX calls will be made
|
60
|
+
filename: nil, # pre-populate the filename span
|
61
|
+
method: nil, # override the parent form's method
|
62
|
+
action: nil, # override the parent form's action
|
63
|
+
additional_params: {} # additional parameters to be sent to server with each request
|
64
|
+
```
|
65
|
+
|
4
66
|
## License
|
5
67
|
|
6
68
|
[MIT](http://dobtco.mit-license.org/)
|
69
|
+
|
70
|
+
[version]: https://img.shields.io/gem/v/pretty_file_input.svg
|
71
|
+
[build]: http://img.shields.io/travis/dobtco/pretty_file_input.svg
|
@@ -3,7 +3,7 @@ class PrettyFileInputInput < SimpleForm::Inputs::Base
|
|
3
3
|
@builder.multipart = true
|
4
4
|
PrettyFileInput::Component.new(
|
5
5
|
name: tag_name,
|
6
|
-
persisted: object.persisted
|
6
|
+
persisted: object.try(:persisted?),
|
7
7
|
filename: object.try(:send, attribute_name).try(:file).try(:filename)
|
8
8
|
).to_html
|
9
9
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'erector'
|
2
2
|
|
3
3
|
class PrettyFileInput::Component < Erector::Widget
|
4
|
-
needs :name,
|
5
|
-
persisted: false,
|
6
|
-
filename: nil,
|
7
|
-
method: nil,
|
8
|
-
action: nil,
|
9
|
-
additional_params: {}
|
4
|
+
needs :name,
|
5
|
+
persisted: false,
|
6
|
+
filename: nil,
|
7
|
+
method: nil,
|
8
|
+
action: nil,
|
9
|
+
additional_params: {}
|
10
10
|
|
11
11
|
def content
|
12
12
|
div(
|
data/pretty_file_input.gemspec
CHANGED
@@ -19,4 +19,12 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.add_dependency 'coffee-script'
|
20
20
|
s.add_dependency 'erector-rails4'
|
21
21
|
s.add_dependency 'sass'
|
22
|
+
|
23
|
+
s.add_development_dependency 'capybara', '2.4.4'
|
24
|
+
s.add_development_dependency 'carrierwave'
|
25
|
+
s.add_development_dependency 'rails', '4.1.7'
|
26
|
+
s.add_development_dependency 'rspec-rails', '3.1.0'
|
27
|
+
s.add_development_dependency 'selenium-webdriver', '2.43.0'
|
28
|
+
s.add_development_dependency 'simple_form'
|
29
|
+
s.add_development_dependency 'sqlite3', '1.3.9'
|
22
30
|
end
|
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
14
|
+
//= require pretty_file_input
|