filepicker-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +69 -0
- data/Rakefile +2 -0
- data/filepicker-rails.gemspec +19 -0
- data/lib/filepicker/rails/configuration.rb +10 -0
- data/lib/filepicker/rails/form_builder.rb +30 -0
- data/lib/filepicker/rails/railtie.rb +18 -0
- data/lib/filepicker/rails/version.rb +5 -0
- data/lib/filepicker/rails/view_helpers.rb +78 -0
- data/lib/filepicker-rails.rb +10 -0
- metadata +79 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Max Tilford
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Filepicker::Rails
|
2
|
+
|
3
|
+
Adds form, image_tag, and download/save helpers to help you get up and running with [filepicker.io](http://filepicker.io) in Rails.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'filepicker-rails'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install filepicker-rails
|
18
|
+
|
19
|
+
Add the filepicker.io javascript library to your layout:
|
20
|
+
|
21
|
+
<%= filepicker_js_include_tag %>
|
22
|
+
|
23
|
+
Set your API Key in config/application.rb:
|
24
|
+
|
25
|
+
config.filepicker_rails.api_key = "Your filepicker.io API Key"
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
### Adding an upload field to your form:
|
30
|
+
|
31
|
+
<%= form_for @user do |f| %>
|
32
|
+
<div>
|
33
|
+
<%= f.label :avatar_url, "Upload Your Avatar:" %>
|
34
|
+
<%= f.filepicker_field :avatar_url %> <!-- User#avatar_url is a regular string column -->
|
35
|
+
</div>
|
36
|
+
|
37
|
+
<%= f.submit %>
|
38
|
+
<% end %>
|
39
|
+
|
40
|
+
Full options list:
|
41
|
+
* button_text - The text of the upload button.
|
42
|
+
* button_class - The class of the upload button.
|
43
|
+
* mimetypes - The file types you want to support for this upload. Ex: "image/png,text/*"
|
44
|
+
* container - Where to show the file picker dialog can be "modal", "window" or the
|
45
|
+
of an iframe on the page.
|
46
|
+
* services - What services your users can upload to. Ex: "BOX, COMPUTER, FACEBOOK".
|
47
|
+
|
48
|
+
|
49
|
+
### Displaying an image:
|
50
|
+
|
51
|
+
<%= filepicker_image_tag @user.avatar_url, w: 160, h: 160, fit: 'clip'
|
52
|
+
|
53
|
+
See [the filepicker.io documentation](https://developers.filepicker.io/docs/web/#fpurl-images) for the full options list.
|
54
|
+
|
55
|
+
|
56
|
+
### Allowing the user to download a file (or upload it to any of the supported services)
|
57
|
+
|
58
|
+
<%= filepicker_save_button "Save", @user.avatar_url, "image/jpg" %>
|
59
|
+
|
60
|
+
Full options list:
|
61
|
+
|
62
|
+
* container - Where to show the file picker dialog can be "modal", "window" or the
|
63
|
+
of an iframe on the page.
|
64
|
+
* services - What services your users can upload to. Ex: "BOX, COMPUTER, FACEBOOK".
|
65
|
+
* save_as_name - A recommended file name. The user can override this.
|
66
|
+
|
67
|
+
### Demo
|
68
|
+
|
69
|
+
See a simple demo app [repo](https://github.com/maxtilford/filepicker-rails-demo) and [running on heroku](http://filepicker-rails-demo.herokuapp.com)
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path('../lib/filepicker/rails/version', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.authors = ["Max Tilford"]
|
5
|
+
gem.email = ["maxtilford@gmail.com"]
|
6
|
+
gem.description = %q{Makes integrating filepicker.io with rails easy}
|
7
|
+
gem.summary = %q{Makes integrating filepicker.io with rails easy}
|
8
|
+
gem.homepage = "https://github.com/maxtilford/filepicker-rails"
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split($\)
|
11
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.name = "filepicker-rails"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = Filepicker::Rails::VERSION
|
16
|
+
|
17
|
+
gem.required_rubygems_version = ">= 1.3.6"
|
18
|
+
gem.add_dependency "railties", ">= 3.1.0", "< 5.0"
|
19
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Filepicker
|
2
|
+
module Rails
|
3
|
+
module FormBuilder
|
4
|
+
|
5
|
+
def filepicker_field(method, options = {})
|
6
|
+
input_options = {
|
7
|
+
'data-fp-apikey' =>
|
8
|
+
::Rails.application.config.filepicker_rails.api_key,
|
9
|
+
|
10
|
+
'data-fp-button-text' => options.fetch(:button_text, "Pick File"),
|
11
|
+
|
12
|
+
'data-fp-button-class' => options[:button_class],
|
13
|
+
|
14
|
+
'data-fp-mimetypes' => options[:mimetypes],
|
15
|
+
|
16
|
+
'data-fp-option-container' => options[:container],
|
17
|
+
|
18
|
+
'data-fp-option-multiple' => false,
|
19
|
+
|
20
|
+
'data-fp-option-services' => Array(options[:services]).join(","),
|
21
|
+
}
|
22
|
+
|
23
|
+
type = options[:dragdrop] ? 'filepicker-dragdrop' : 'filepicker'
|
24
|
+
|
25
|
+
ActionView::Helpers::InstanceTag.new(@object_name, method, @template)
|
26
|
+
.to_input_field_tag(type, input_options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Filepicker
|
2
|
+
module Rails
|
3
|
+
|
4
|
+
class Railtie < ::Rails::Railtie
|
5
|
+
|
6
|
+
config.filepicker_rails = Filepicker::Rails::Configuration.new
|
7
|
+
|
8
|
+
initializer "filepicker_rails.view_helpers" do
|
9
|
+
ActionView::Base.send(:include, Filepicker::Rails::ViewHelpers)
|
10
|
+
end
|
11
|
+
|
12
|
+
initializer "filepicker_rails.form_builder" do
|
13
|
+
ActionView::Helpers::FormBuilder.send(:include, Filepicker::Rails::FormBuilder)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Filepicker
|
2
|
+
module Rails
|
3
|
+
|
4
|
+
module ViewHelpers
|
5
|
+
def filepicker_js_include_tag
|
6
|
+
javascript_include_tag "//api.filepicker.io/v0/filepicker.js"
|
7
|
+
end
|
8
|
+
|
9
|
+
def filepicker_save_button(text, url, mimetype, options = {})
|
10
|
+
options[:data] ||= {}
|
11
|
+
container = options.delete(:container)
|
12
|
+
services = options.delete(:services)
|
13
|
+
save_as = options.delete(:save_as_name)
|
14
|
+
|
15
|
+
options[:data]['fp-url'] = url
|
16
|
+
options[:data]['fp-apikey'] = ::Rails.application.config.filepicker_rails.api_key
|
17
|
+
options[:data]['fp-mimetype'] = mimetype
|
18
|
+
options[:data]['fp-option-container'] = container if container
|
19
|
+
options[:data]['fp-option-services'] = Array(services).join(",") if services
|
20
|
+
options[:data]['fp-option-defaultSaveasName'] = save_as if save_as
|
21
|
+
button_tag(text, options)
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def filepicker_image_tag(url, options={})
|
26
|
+
image_tag(filepicker_image_url(url, options),
|
27
|
+
width: options[:w],
|
28
|
+
height: options[:h],
|
29
|
+
|
30
|
+
alt: options[:alt])
|
31
|
+
end
|
32
|
+
|
33
|
+
# w - Resize the image to this width.
|
34
|
+
#
|
35
|
+
# h - Resize the image to this height.
|
36
|
+
#
|
37
|
+
# fit - Specifies how to resize the image. Possible values are:
|
38
|
+
# clip: Resizes the image to fit within the specified parameters without
|
39
|
+
# distorting, cropping, or changing the aspect ratio
|
40
|
+
# crop: Resizes the image to fit the specified parameters exactly by
|
41
|
+
# removing any parts of the image that don't fit within the boundaries
|
42
|
+
# scales: Resizes the image to fit the specified parameters exactly by
|
43
|
+
# scaling the image to the desired size
|
44
|
+
# Defaults to "clip".
|
45
|
+
#
|
46
|
+
# crop - Crops the image to a specified rectangle. The input to this parameter
|
47
|
+
# should be 4 numbers for 'x,y,width,height' - for example,
|
48
|
+
# 'crop=10,20,200,250' would select the 200x250 pixel rectangle starting
|
49
|
+
# from 10 pixels from the left edge and 20 pixels from the top edge of the
|
50
|
+
# image.
|
51
|
+
#
|
52
|
+
# format - Specifies what format the image should be converted to, if any.
|
53
|
+
# Possible values are "jpg" and "png". For "jpg" conversions, you
|
54
|
+
# can additionally specify a quality parameter.
|
55
|
+
#
|
56
|
+
# quality - For jpeg conversion, specifies the quality of the resultant image.
|
57
|
+
# Quality should be an integer between 1 and 100
|
58
|
+
#
|
59
|
+
# watermark - Adds the specified absolute url as a watermark on the image.
|
60
|
+
#
|
61
|
+
# watersize - This size of the watermark, as a percentage of the base
|
62
|
+
# image (not the original watermark).
|
63
|
+
#
|
64
|
+
# waterposition - Where to put the watermark relative to the base image.
|
65
|
+
# Possible values for vertical position are "top","middle",
|
66
|
+
# "bottom" and "left","center","right", for horizontal
|
67
|
+
# position. The two can be combined by separating vertical
|
68
|
+
# and horizontal with a comma. The default behavior
|
69
|
+
# is bottom,right
|
70
|
+
def filepicker_image_url(url, options = {})
|
71
|
+
query_params = options.slice(:w,:h,:fit,:crop,:format,:quality,
|
72
|
+
:watermark,:watersize,:waterposition).to_query
|
73
|
+
[url, "/convert?", query_params].join
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: filepicker-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Max Tilford
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: railties
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.1.0
|
22
|
+
- - <
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '5.0'
|
25
|
+
type: :runtime
|
26
|
+
prerelease: false
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.1.0
|
33
|
+
- - <
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '5.0'
|
36
|
+
description: Makes integrating filepicker.io with rails easy
|
37
|
+
email:
|
38
|
+
- maxtilford@gmail.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- LICENSE
|
46
|
+
- README.md
|
47
|
+
- Rakefile
|
48
|
+
- filepicker-rails.gemspec
|
49
|
+
- lib/filepicker-rails.rb
|
50
|
+
- lib/filepicker/rails/configuration.rb
|
51
|
+
- lib/filepicker/rails/form_builder.rb
|
52
|
+
- lib/filepicker/rails/railtie.rb
|
53
|
+
- lib/filepicker/rails/version.rb
|
54
|
+
- lib/filepicker/rails/view_helpers.rb
|
55
|
+
homepage: https://github.com/maxtilford/filepicker-rails
|
56
|
+
licenses: []
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 1.3.6
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.8.24
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Makes integrating filepicker.io with rails easy
|
79
|
+
test_files: []
|