filepicker-padrino 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/README.md +78 -0
- data/filepicker-padrino.gemspec +19 -0
- data/lib/filepicker-padrino.rb +12 -0
- data/lib/filepicker/padrino/form_builder.rb +20 -0
- data/lib/filepicker/padrino/helpers.rb +83 -0
- data/lib/filepicker/padrino/version.rb +5 -0
- metadata +68 -0
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# Filepicker::Padrino
|
2
|
+
|
3
|
+
Adds form, image_tag, and download/save helpers to help you get up and running with [filepicker.io](http://filepicker.io) in Padrino.
|
4
|
+
|
5
|
+
A port of [filepicker-rails](https://github.com/Filepicker/filepicker-rails) by Max Tilford to Padrino.
|
6
|
+
Very little code was changed so if you'd like to thank someone then thank him!
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'filepicker-padrino'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install filepicker-padrino
|
21
|
+
|
22
|
+
Register it with Padrino in app/app.rb:
|
23
|
+
|
24
|
+
register Filepicker::Padrino
|
25
|
+
|
26
|
+
Set your API Key in app/app.rb:
|
27
|
+
|
28
|
+
set :filepicker_padrino_api_key, 'XXXXXX'
|
29
|
+
|
30
|
+
Add the filepicker.io javascript library to your layout:
|
31
|
+
|
32
|
+
<%= filepicker_js_include_tag %>
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
### Adding an upload field to your form:
|
37
|
+
|
38
|
+
<%= filepicker_form_for @user do |f| %>
|
39
|
+
<div>
|
40
|
+
<%= f.label :avatar_url, "Upload Your Avatar:" %>
|
41
|
+
<%= f.filepicker_field :avatar_url %> <!-- User#avatar_url is a regular string column -->
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<%= f.submit %>
|
45
|
+
<% end %>
|
46
|
+
|
47
|
+
### Note the usage of:
|
48
|
+
|
49
|
+
<%= filepicker_form_for @user, path do |f| %>
|
50
|
+
|
51
|
+
### Instead of the typical:
|
52
|
+
|
53
|
+
<%= form_for @user, path do |f| %>
|
54
|
+
|
55
|
+
Full options list:
|
56
|
+
* button_text - The text of the upload button.
|
57
|
+
* button_class - The class of the upload button.
|
58
|
+
* mimetypes - The file types you want to support for this upload. Ex: "image/png,text/*"
|
59
|
+
* container - Where to show the file picker dialog can be "modal", "window" or the
|
60
|
+
of an iframe on the page.
|
61
|
+
* services - What services your users can upload to. Ex: "BOX, COMPUTER, FACEBOOK".
|
62
|
+
|
63
|
+
### Displaying an image:
|
64
|
+
|
65
|
+
<%= filepicker_image_tag @user.avatar_url, w: 160, h: 160, fit: 'clip' %>
|
66
|
+
|
67
|
+
See [the filepicker.io documentation](https://developers.filepicker.io/docs/web/#fpurl-images) for the full options list.
|
68
|
+
|
69
|
+
### Allowing the user to download a file (or upload it to any of the supported services)
|
70
|
+
|
71
|
+
<%= filepicker_save_button "Save", @user.avatar_url, "image/jpg" %>
|
72
|
+
|
73
|
+
Full options list:
|
74
|
+
|
75
|
+
* container - Where to show the file picker dialog can be "modal", "window" or the
|
76
|
+
of an iframe on the page.
|
77
|
+
* services - What services your users can upload to. Ex: "BOX, COMPUTER, FACEBOOK".
|
78
|
+
* save_as_name - A recommended file name. The user can override this.
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path('../lib/filepicker/padrino/version', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.authors = ["Ken Erickson"]
|
5
|
+
gem.email = ["bookworm.productions@gmail.com"]
|
6
|
+
gem.description = %q{Makes integrating filepicker.io with padrino easy}
|
7
|
+
gem.summary = %q{Makes integrating filepicker.io with padrino easy}
|
8
|
+
gem.homepage = "https://github.com/bookworm/filepicker-padrino"
|
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-padrino"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = Filepicker::Padrino::VERSION
|
16
|
+
|
17
|
+
gem.required_rubygems_version = ">= 1.3.6"
|
18
|
+
gem.add_dependency "padrino-helpers", "~> 0.10.6"
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Filepicker
|
2
|
+
module Padrino
|
3
|
+
class FormBuilder < ::Padrino::Helpers::FormBuilder::StandardFormBuilder
|
4
|
+
def filepicker_field(name, options = {})
|
5
|
+
input_options = {
|
6
|
+
'data-fp-apikey' => @template.settings.filepicker_padrino_api_key,
|
7
|
+
'data-fp-button-text' => options.fetch(:button_text, "Pick File"),
|
8
|
+
'data-fp-button-class' => options[:button_class],
|
9
|
+
'data-fp-mimetypes' => options[:mimetypes],
|
10
|
+
'data-fp-option-container' => options[:container],
|
11
|
+
'data-fp-option-multiple' => false,
|
12
|
+
'data-fp-option-services' => Array(options[:services]).join(","),
|
13
|
+
}
|
14
|
+
|
15
|
+
type = options[:dragdrop] ? 'filepicker-dragdrop' : 'filepicker'
|
16
|
+
@template.input_tag type, input_options.reverse_merge!(:name => field_name(name))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Filepicker
|
2
|
+
module Padrino
|
3
|
+
module Helpers
|
4
|
+
def filepicker_form_for(record, path, options = {}, &block)
|
5
|
+
options[:builder] = ::Filepicker::Padrino::FormBuilder
|
6
|
+
form_for(record, path, options) do |f|
|
7
|
+
capture(f, &block)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def filepicker_fields_for(record, instance_or_collection = nil, &block)
|
12
|
+
fields_for(record, instance_or_collection, &block)
|
13
|
+
end
|
14
|
+
|
15
|
+
def filepicker_js_include_tag
|
16
|
+
javascript_include_tag "//api.filepicker.io/v0/filepicker.js"
|
17
|
+
end
|
18
|
+
|
19
|
+
def filepicker_save_button(text, url, mimetype, options = {})
|
20
|
+
options[:data] ||= {}
|
21
|
+
container = options.delete(:container)
|
22
|
+
services = options.delete(:services)
|
23
|
+
save_as = options.delete(:save_as_name)
|
24
|
+
|
25
|
+
options[:data]['fp-url'] = url
|
26
|
+
options[:data]['fp-apikey'] = settings.filepicker_padrino_api_key
|
27
|
+
options[:data]['fp-mimetype'] = mimetype
|
28
|
+
options[:data]['fp-option-container'] = container if container
|
29
|
+
options[:data]['fp-option-services'] = Array(services).join(",") if services
|
30
|
+
options[:data]['fp-option-defaultSaveasName'] = save_as if save_as
|
31
|
+
button_tag(text, options)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Allows options to be passed to filepicker_image_url and then falls back to normal Padrino options for image_tag
|
35
|
+
def filepicker_image_tag(url, options={})
|
36
|
+
image_tag(filepicker_image_url(url, options), options)
|
37
|
+
end
|
38
|
+
|
39
|
+
# w - Resize the image to this width.
|
40
|
+
#
|
41
|
+
# h - Resize the image to this height.
|
42
|
+
#
|
43
|
+
# fit - Specifies how to resize the image. Possible values are:
|
44
|
+
# clip: Resizes the image to fit within the specified parameters without
|
45
|
+
# distorting, cropping, or changing the aspect ratio
|
46
|
+
# crop: Resizes the image to fit the specified parameters exactly by
|
47
|
+
# removing any parts of the image that don't fit within the boundaries
|
48
|
+
# scales: Resizes the image to fit the specified parameters exactly by
|
49
|
+
# scaling the image to the desired size
|
50
|
+
# Defaults to "clip".
|
51
|
+
#
|
52
|
+
# crop - Crops the image to a specified rectangle. The input to this parameter
|
53
|
+
# should be 4 numbers for 'x,y,width,height' - for example,
|
54
|
+
# 'crop=10,20,200,250' would select the 200x250 pixel rectangle starting
|
55
|
+
# from 10 pixels from the left edge and 20 pixels from the top edge of the
|
56
|
+
# image.
|
57
|
+
#
|
58
|
+
# format - Specifies what format the image should be converted to, if any.
|
59
|
+
# Possible values are "jpg" and "png". For "jpg" conversions, you
|
60
|
+
# can additionally specify a quality parameter.
|
61
|
+
#
|
62
|
+
# quality - For jpeg conversion, specifies the quality of the resultant image.
|
63
|
+
# Quality should be an integer between 1 and 100
|
64
|
+
#
|
65
|
+
# watermark - Adds the specified absolute url as a watermark on the image.
|
66
|
+
#
|
67
|
+
# watersize - This size of the watermark, as a percentage of the base
|
68
|
+
# image (not the original watermark).
|
69
|
+
#
|
70
|
+
# waterposition - Where to put the watermark relative to the base image.
|
71
|
+
# Possible values for vertical position are "top","middle",
|
72
|
+
# "bottom" and "left","center","right", for horizontal
|
73
|
+
# position. The two can be combined by separating vertical
|
74
|
+
# and horizontal with a comma. The default behavior
|
75
|
+
# is bottom,right
|
76
|
+
def filepicker_image_url(url, options = {})
|
77
|
+
query_params = options.slice(:w, :h, :fit, :crop, :format, :quality,
|
78
|
+
:watermark, :watersize, :waterposition).to_query
|
79
|
+
[url, "/convert?", query_params].join
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: filepicker-padrino
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ken Erickson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: padrino-helpers
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.10.6
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.10.6
|
30
|
+
description: Makes integrating filepicker.io with padrino easy
|
31
|
+
email:
|
32
|
+
- bookworm.productions@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- Gemfile
|
38
|
+
- README.md
|
39
|
+
- filepicker-padrino.gemspec
|
40
|
+
- lib/filepicker-padrino.rb
|
41
|
+
- lib/filepicker/padrino/form_builder.rb
|
42
|
+
- lib/filepicker/padrino/helpers.rb
|
43
|
+
- lib/filepicker/padrino/version.rb
|
44
|
+
homepage: https://github.com/bookworm/filepicker-padrino
|
45
|
+
licenses: []
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.3.6
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.8.23
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Makes integrating filepicker.io with padrino easy
|
68
|
+
test_files: []
|