pretty_file_input 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e57d9efb1610be2863391f09c934f208c3a5f2e
4
- data.tar.gz: d46c59fca21ff1b76fa3c1bf37304b9de6eb721e
3
+ metadata.gz: c168ebe781c32c83a16d009e59fd6ba47248986c
4
+ data.tar.gz: b23a8b2cce2676ba4a0ce1f20492cbdbc1b99993
5
5
  SHA512:
6
- metadata.gz: 30f013d6bcc509c9a77bf227291e4e5a522add470edc1ccff78e059821fd24cd550fc0f577ba6347489de04caeefef8bcbb9c97c369e8ea426cddf323660ef3e
7
- data.tar.gz: 5707ec9e0e91111b18da1d53b024d4bcd9bb7cc33264749883f5bc4c45703b466dc4d9a2068ce8ee48570cf53fbabb795fb92b720e0d89f9349b4669dcba434a
6
+ metadata.gz: 14fca40aa7f82597774a3a66114501a5a48354b0f5ad7af34e98088f0e963f955efc1745c256aabd2d23e5d105160d8289648200d777f5f9fe8cec3a02970b4d
7
+ data.tar.gz: 88cf5c3de4533a042946b5d7643b55b2f478aa401851d38b99d3e3a57cede42eb033660f5b5ba70771d6e06e48dbce8a3593d3b034bd1fd57a9808b835928bb7
data/.gitignore CHANGED
@@ -4,4 +4,8 @@ tmp/*
4
4
  coverage/*
5
5
  *.gem
6
6
  Gemfile.lock
7
- .ruby-gemset
7
+ .ruby-gemset
8
+ spec/dummy/tmp/*
9
+ spec/dummy/log/*
10
+ spec/dummy/public/uploads/*
11
+ spec/dummy/db/test.sqlite
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
+ ![gif](https://s3.amazonaws.com/quickcast/3785/60141/quickcast.gif)
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, # input name that will be sent to the server
5
- persisted: false, # is parent object is not persisted, no AJAX calls will be made
6
- filename: nil, # pre-populate the filename span
7
- method: nil, # override the parent form's method
8
- action: nil, # override the parent form's action
9
- additional_params: {} # additional parameters to be sent to server with each request
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(
@@ -1,3 +1,3 @@
1
1
  module PrettyFileInput
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -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
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Dummy::Application.load_tasks
@@ -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