filepicker-rails 0.0.2 → 0.1

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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NWZhNzRjMzBjODI1OWM0ODUyYzFkZGI5OTRmOTU3MmY2YmYyZmJmNA==
5
+ data.tar.gz: !binary |-
6
+ NzY3MDZiNWE0NzA1Y2Y4NGI2OGM4YTkwMDIzN2QyZTJiNGQwNTE4YQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ Zjg2ZTFlZjc5MjJjYWM5YWFhNzZlNTMzZTBhYWM2NTFjMjY3OTJlNTc3ODYy
10
+ NDc0NjVkNjA4MjUwNWI0MDc5MWQzMzRjZGY4ODRlYzMzY2IyZmFiODY1ZjM3
11
+ NmI3YTIxZmFmMDlmN2YwYjk5YWZlNTNmMDdlNDlmOTA4ODE4OTY=
12
+ data.tar.gz: !binary |-
13
+ Y2NiZWQwN2IwNjEzOGMwYzk0MmVjNjk1MTk3YmY5ZjQ5NGM1ODUxNGE3Nzgw
14
+ NDM4YTlhMDc0NDEzMWU4ZjU1Y2Q4ZDdiNTA0Yzg1YzM3NjkxMjc0NGRlMTkz
15
+ NWNhZTU1NzkzOWNkNzhhNjczZDdmMmUwOTUyOGM2NjViMjQ0Mjg=
data/README.md CHANGED
@@ -6,7 +6,9 @@ Adds form, image_tag, and download/save helpers to help you get up and running w
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
- gem 'filepicker-rails'
9
+ ```ruby
10
+ gem 'filepicker-rails'
11
+ ```
10
12
 
11
13
  And then execute:
12
14
 
@@ -18,49 +20,100 @@ Or install it yourself as:
18
20
 
19
21
  Add the filepicker.io javascript library to your layout:
20
22
 
21
- <%= filepicker_js_include_tag %>
23
+ ```erb
24
+ <%= filepicker_js_include_tag %>
25
+ ```
22
26
 
23
27
  Set your API Key in config/application.rb:
24
28
 
25
- config.filepicker_rails.api_key = "Your filepicker.io API Key"
29
+ ```ruby
30
+ config.filepicker_rails.api_key = "Your filepicker.io API Key"
31
+ ```
26
32
 
27
33
  ## Usage
34
+ ### First create a migration to add the field that will hold your filepicker.io URL
35
+ Run the Rails migration generator from the command line:
28
36
 
29
- ### Adding an upload field to your form:
37
+ $ rails g migration AddNameOfAttrForFilepickerUrlToUser
38
+
39
+ Then add a column to the model's table of type :string:
30
40
 
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>
41
+ ```ruby
42
+ class AddNameOfAttrForFilepickerUrlToUser < ActiveRecord::Migration
43
+ def up
44
+ add_column :user, :filepicker_url, :string
45
+ end
36
46
 
37
- <%= f.submit %>
38
- <% end %>
47
+ def down
48
+ remove_column :user, :filepicker_url
49
+ end
50
+ end
51
+ ```
39
52
 
53
+
54
+ ### Adding an upload field to your form:
55
+
56
+ ```erb
57
+ <%= form_for @user do |f| %>
58
+ <div>
59
+ <%= f.label :filepicker_url, "Upload Your Avatar:" %>
60
+ <%= f.filepicker_field :filepicker_url %> <!-- User#filepicker_url is a regular string column -->
61
+ </div>
62
+
63
+ <%= f.submit %>
64
+ <% end %>
65
+ ```
40
66
  Full options list:
41
67
 
42
68
  * button_text - The text of the upload button.
43
69
  * button_class - The class of the upload button.
44
- * mimetypes - The file types you want to support for this upload. Ex: "image/png,text/*"
70
+ * mimetypes - The file types you want to support for this upload. Ex: "image/png,text/*".
45
71
  * container - Where to show the file picker dialog can be "modal", "window" or the
46
72
  of an iframe on the page.
73
+ * multiple - (true or false) Whether or not multiple uploads can be saved at once.
47
74
  * services - What services your users can upload to. Ex: "BOX, COMPUTER, FACEBOOK".
48
- * dragdrop - (true or false) Whether or not to all drag-and-drop uploads
75
+ * dragdrop - (true or false) Whether or not to allow drag-and-drop uploads.
49
76
  * drag_text - The text of the dragdrop pane.
50
77
  * drag_class - The class of the dragdrop pane.
51
- * onchange - The onchange event
52
-
78
+ * onchange - The onchange event.
79
+
80
+ ### Accessing FilePicker File with OnChange:
81
+
82
+ When the dialog finishes uploading the file, the javascript code in the onchange field will be run with a special 'event' variable. The variable has a fpfiles (or if not multiple, also fpfile) attribute with information about the files (jQuery users: look under event.originalEvent).
83
+
84
+ Example fpfiles object:
85
+ ```javascript
86
+ [{
87
+ url: 'https://...',
88
+ data: {
89
+ filename: 'filename.txt',
90
+ size: 100,
91
+ type: 'text/plain'
92
+ }
93
+ },{
94
+ url: 'https://...',
95
+ data: {
96
+ filename: 'filename2.jpg',
97
+ size: 9000,
98
+ type: 'image/jpeg'
99
+ }
100
+ }]
101
+ ```
53
102
 
54
103
  ### Displaying an image:
55
104
 
56
- <%= filepicker_image_tag @user.avatar_url, w: 160, h: 160, fit: 'clip' %>
105
+ ```erb
106
+ <%= filepicker_image_tag @user.filepicker_url, w: 160, h: 160, fit: 'clip' %>
107
+ ```
57
108
 
58
109
  See [the filepicker.io documentation](https://developers.filepicker.io/docs/web/#fpurl-images) for the full options list.
59
110
 
60
111
 
61
112
  ### Allowing the user to download a file (or upload it to any of the supported services)
62
113
 
63
- <%= filepicker_save_button "Save", @user.avatar_url, "image/jpg" %>
114
+ ```erb
115
+ <%= filepicker_save_button "Save", @user.filepicker_url, "image/jpg" %>
116
+ ```
64
117
 
65
118
  Full options list:
66
119
 
@@ -71,4 +124,4 @@ of an iframe on the page.
71
124
 
72
125
  ### Demo
73
126
 
74
- See a simple demo app [repo](https://github.com/maxtilford/filepicker-rails-demo) and [running on heroku](http://filepicker-rails-demo.herokuapp.com)
127
+ See a simple demo app [repo](https://github.com/maxtilford/filepicker-rails-demo)
@@ -3,9 +3,9 @@ require File.expand_path('../lib/filepicker/rails/version', __FILE__)
3
3
  Gem::Specification.new do |gem|
4
4
  gem.authors = ["Max Tilford"]
5
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"
6
+ gem.description = %q{Makes integrating filepicker.io with rails 4 easy}
7
+ gem.summary = %q{Makes integrating filepicker.io with rails 4 easy}
8
+ gem.homepage = "https://github.com/Filepicker/filepicker-rails"
9
9
 
10
10
  gem.files = `git ls-files`.split($\)
11
11
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -16,4 +16,5 @@ Gem::Specification.new do |gem|
16
16
 
17
17
  gem.required_rubygems_version = ">= 1.3.6"
18
18
  gem.add_dependency "railties", ">= 3.1.0", "< 5.0"
19
+ gem.add_dependency 'multi_json', '~> 1.6'
19
20
  end
@@ -1,5 +1,6 @@
1
1
  require "filepicker/rails/version"
2
2
  require "filepicker/rails/configuration"
3
+ require "filepicker/rails/policy"
3
4
  require "filepicker/rails/form_builder"
4
5
  require "filepicker/rails/view_helpers"
5
6
  require "filepicker/rails/railtie"
@@ -1,10 +1,19 @@
1
1
  module Filepicker
2
2
  module Rails
3
3
  class Configuration
4
- attr_writer :api_key
4
+ attr_writer :api_key, :secret_key, :default_expiry
5
+
5
6
  def api_key
6
7
  @api_key or raise "Set config.filepicker_rails.api_key"
7
8
  end
9
+
10
+ def secret_key
11
+ @secret_key
12
+ end
13
+
14
+ def default_expiry
15
+ @default_expiry ||= 600
16
+ end
8
17
  end
9
18
  end
10
19
  end
@@ -3,33 +3,52 @@ module Filepicker
3
3
  module FormBuilder
4
4
 
5
5
  def filepicker_field(method, options = {})
6
- input_options = {
7
- 'data-fp-apikey' =>
8
- ::Rails.application.config.filepicker_rails.api_key,
6
+ type = options.delete(:dragdrop) ? 'filepicker-dragdrop' : 'filepicker'
9
7
 
10
- 'data-fp-button-text' => options.fetch(:button_text, "Pick File"),
8
+ input_options = retrive_legacy_filepicker_options(options)
9
+ input_options['data-fp-apikey'] ||= ::Rails.application.config.filepicker_rails.api_key
10
+ input_options.merge!(secure_filepicker) unless input_options['data-fp-policy'].present?
11
11
 
12
- 'data-fp-button-class' => options[:button_class],
12
+ input_options['type'] = type
13
13
 
14
- 'data-fp-mimetypes' => options[:mimetypes],
15
-
16
- 'data-fp-option-container' => options[:container],
17
-
18
- 'data-fp-option-multiple' => false,
14
+ if ::Rails.version.to_i >= 4
15
+ ActionView::Helpers::Tags::TextField.new(@object_name, method, @template).tag('input', input_options)
16
+ else
17
+ ActionView::Helpers::InstanceTag.new(@object_name, method, @template).to_input_field_tag(type, input_options)
18
+ end
19
+ end
19
20
 
20
- 'data-fp-option-services' => Array(options[:services]).join(","),
21
+ private
22
+
23
+ def retrive_legacy_filepicker_options(options)
24
+ mappings = {
25
+ :button_text => 'data-fp-button-text',
26
+ :button_class => 'data-fp-button-class',
27
+ :mimetypes => 'data-fp-mimetypes',
28
+ :container => 'data-fp-container',
29
+ :services => 'data-fp-services',
30
+ :drag_text => 'data-fp-drag-text',
31
+ :drag_class => 'data-fp-drag-class',
32
+ :store_path => 'data-fp-store-path',
33
+ :store_location => 'data-fp-store-location',
34
+ :multiple => 'data-fp-multiple',
35
+ :onchange => 'onchange',
36
+ :class => 'class',
37
+ :value => 'value'
38
+ }
21
39
 
22
- 'data-fp-drag-text' => options.fetch(:drag_text, "Or drop files here"),
40
+ Hash[options.map {|k, v| [mappings[k] || k, v] }]
41
+ end
23
42
 
24
- 'data-fp-drag-class' => options[:drag_class],
43
+ def secure_filepicker
44
+ return {} unless ::Rails.application.config.filepicker_rails.secret_key.present?
45
+ grant = Policy.new
46
+ grant.call = [:pick, :store]
25
47
 
26
- 'onchange' => options[:onchange]
48
+ {
49
+ 'data-fp-policy' => grant.policy,
50
+ 'data-fp-signature' => grant.signature
27
51
  }
28
-
29
- type = options[:dragdrop] ? 'filepicker-dragdrop' : 'filepicker'
30
-
31
- ActionView::Helpers::InstanceTag.new(@object_name, method, @template)
32
- .to_input_field_tag(type, input_options)
33
52
  end
34
53
  end
35
54
  end
@@ -0,0 +1,37 @@
1
+ require 'base64'
2
+ require 'openssl'
3
+
4
+ module Filepicker
5
+ module Rails
6
+ class Policy
7
+ attr_accessor :expiry, :call, :handle, :maxsize, :minsize, :path
8
+
9
+ def initialize(options = {})
10
+ [:expiry, :call, :handle, :maxsize, :minsize, :path].each do |input|
11
+ send("#{input}=", options[input]) unless options[input].nil?
12
+ end
13
+ end
14
+
15
+ def policy
16
+ Base64.urlsafe_encode64(json_policy)
17
+ end
18
+
19
+ def signature
20
+ OpenSSL::HMAC.hexdigest('sha256', ::Rails.application.config.filepicker_rails.secret_key, policy)
21
+ end
22
+
23
+ private
24
+ def json_policy
25
+ hash = Hash.new
26
+
27
+ @expiry ||= Time.now.to_i + ::Rails.application.config.filepicker_rails.default_expiry
28
+
29
+ [:expiry, :call, :handle, :maxsize, :minsize, :path].each do |input|
30
+ hash[input] = send(input) unless send(input).nil?
31
+ end
32
+
33
+ MultiJson.dump(hash)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,5 +1,5 @@
1
1
  module Filepicker
2
2
  module Rails
3
- VERSION = "0.0.2"
3
+ VERSION = "0.1"
4
4
  end
5
5
  end
@@ -23,13 +23,13 @@ module Filepicker
23
23
 
24
24
  # Allows options to be passed to filepicker_image_url and then falls back to normal Rails options for image_tag
25
25
  # If specifying html width, height, pass it down to filepicker for optimization
26
- def filepicker_image_tag(url, options={})
27
- image_tag(filepicker_image_url(url, options), options)
26
+ def filepicker_image_tag(url, image_options={}, image_tag_options={})
27
+ image_tag(filepicker_image_url(url, image_options), image_tag_options)
28
28
  end
29
29
 
30
- # width - Resize the image to this width.
30
+ # w - Resize the image to this width.
31
31
  #
32
- # height - Resize the image to this height.
32
+ # h - Resize the image to this height.
33
33
  #
34
34
  # fit - Specifies how to resize the image. Possible values are:
35
35
  # clip: Resizes the image to fit within the specified parameters without
@@ -66,7 +66,7 @@ module Filepicker
66
66
  # and horizontal with a comma. The default behavior
67
67
  # is bottom,right
68
68
  def filepicker_image_url(url, options = {})
69
- query_params = options.slice(:width, :height, :fit, :align, :crop, :format, :quality, :watermark, :watersize, :waterposition).to_query
69
+ query_params = options.slice(:w, :h, :fit, :align, :crop, :format, :quality, :watermark, :watersize, :waterposition).to_query
70
70
  [url, "/convert?", query_params].join
71
71
  end
72
72
 
metadata CHANGED
@@ -1,55 +1,56 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: filepicker-rails
3
- version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 2
10
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Max Tilford
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2012-12-01 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2013-05-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.1.0
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
22
24
  prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 3
31
- - 1
32
- - 0
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
33
29
  version: 3.1.0
34
30
  - - <
35
- - !ruby/object:Gem::Version
36
- hash: 31
37
- segments:
38
- - 5
39
- - 0
40
- version: "5.0"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: multi_json
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: '1.6'
41
40
  type: :runtime
42
- version_requirements: *id001
43
- description: Makes integrating filepicker.io with rails easy
44
- email:
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: '1.6'
47
+ description: Makes integrating filepicker.io with rails 4 easy
48
+ email:
45
49
  - maxtilford@gmail.com
46
50
  executables: []
47
-
48
51
  extensions: []
49
-
50
52
  extra_rdoc_files: []
51
-
52
- files:
53
+ files:
53
54
  - .gitignore
54
55
  - Gemfile
55
56
  - LICENSE
@@ -59,43 +60,31 @@ files:
59
60
  - lib/filepicker-rails.rb
60
61
  - lib/filepicker/rails/configuration.rb
61
62
  - lib/filepicker/rails/form_builder.rb
63
+ - lib/filepicker/rails/policy.rb
62
64
  - lib/filepicker/rails/railtie.rb
63
65
  - lib/filepicker/rails/version.rb
64
66
  - lib/filepicker/rails/view_helpers.rb
65
- homepage: https://github.com/maxtilford/filepicker-rails
67
+ homepage: https://github.com/Filepicker/filepicker-rails
66
68
  licenses: []
67
-
69
+ metadata: {}
68
70
  post_install_message:
69
71
  rdoc_options: []
70
-
71
- require_paths:
72
+ require_paths:
72
73
  - lib
73
- required_ruby_version: !ruby/object:Gem::Requirement
74
- none: false
75
- requirements:
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- hash: 3
79
- segments:
80
- - 0
81
- version: "0"
82
- required_rubygems_version: !ruby/object:Gem::Requirement
83
- none: false
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- hash: 23
88
- segments:
89
- - 1
90
- - 3
91
- - 6
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
92
83
  version: 1.3.6
93
84
  requirements: []
94
-
95
85
  rubyforge_project:
96
- rubygems_version: 1.8.24
86
+ rubygems_version: 2.0.3
97
87
  signing_key:
98
- specification_version: 3
99
- summary: Makes integrating filepicker.io with rails easy
88
+ specification_version: 4
89
+ summary: Makes integrating filepicker.io with rails 4 easy
100
90
  test_files: []
101
-