filepicker-rails 1.3.0 → 1.4.0

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: 807acef7a7f487b4db552bebc8c084641e4f2730
4
- data.tar.gz: fc310857861c323da6c123b00ee22a216c976017
3
+ metadata.gz: 06d2e91d419884443bd5b5e7b78f3ad18515fde9
4
+ data.tar.gz: c0d4ab38baea1c65377d056e8e72f670f2f1bca9
5
5
  SHA512:
6
- metadata.gz: a76e4bb901b528dd717e92a85fe10e9237e209824bc4b020d682de42c3cda743a1b9c33b103874ccd33f05f4e2297ced454a7991f83fdcb9b82f9a24eb489fa1
7
- data.tar.gz: da50efe1cd0c2b9cd7a8354a78dcbe19bf6f482aaad5470138c98923a19ce1441cdc05f2c439b0d711539912013419cd893655fcf5581116982ebca388e6f8e0
6
+ metadata.gz: f09dde007e819de987b599b493fc077ed2133aca55bd723c66de7a43f613238b33d7f47fa0acaa0c1b8dd7856c2d61ee5423d62ee4824eccce74fc6394c476f3
7
+ data.tar.gz: af1c86fad975850a25696c57155ffb550d0642a59035eb977001bd067001be0125371ebb00c57d51f2eed3d96f6c593bd1b5df5552ce324d4e95c29e41b94898
@@ -1,6 +1,8 @@
1
1
  module FilepickerRails
2
2
  module ApplicationHelper
3
3
 
4
+ include FilepickerRails::Tag
5
+
4
6
  # Creates a javascript tag to the filepicker JavaScript.
5
7
  #
6
8
  # #### Examples
@@ -11,6 +13,41 @@ module FilepickerRails
11
13
  javascript_include_tag "//api.filepicker.io/v1/filepicker.js"
12
14
  end
13
15
 
16
+ # Creates a filepicker field tag, accepts optional `options` hash for configuration.
17
+ #
18
+ # #### Options
19
+ #
20
+ # - `:button_text` - The text of the upload button.
21
+ # - `:button_class` - The class of the upload button.
22
+ # - `:extensions` - The extensions of file types you want to support for this upload. Ex: `.png,.jpg`.
23
+ # - `:mimetypes` - The file types you want to support for this upload. Ex: `image/png,text/*`.
24
+ # - `:container` - Where to show the file picker dialog can be `modal`, `window` or the id of an iframe on the page.
25
+ # - `:multiple` - (true or false) Whether or not multiple uploads can be saved at once.
26
+ # - `:services` - What services your users can upload to. Ex: `BOX, COMPUTER, FACEBOOK`.
27
+ # - `:store_path` - The path to store the file at within the specified file store.
28
+ # - `:store_location` - The file is not copied by default. It remains in the original location. If you wish you have the file copied onto your own storage, you can specify where we should put the copy. The only value at the moment is `S3`.
29
+ # - `:store_container` - The bucket or container in your specified `store_location`. Defaults to the container specified in the developer portal. Does not apply to Dropbox storage.
30
+ # - `:store_access` - Should the underlying file be publicly available on its S3 link. Options are `public` and `private`, defaults to 'private'.
31
+ # - `:dragdrop` - (`true` or `false`) Whether or not to allow drag-and-drop uploads.
32
+ # - `:drag_text` - The text of the dragdrop pane.
33
+ # - `:drag_class` - The class of the dragdrop pane.
34
+ # - `:onchange` - The onchange event.
35
+ # - `:max_size` - The maximum file size allowed, in bytes.
36
+ # - `:max_files` - The maximum number of files.
37
+ # - `:open_to` - Open the picker to the given service. Ex: `COMPUTER`.
38
+ # - `:class` - Add a class to the input.
39
+ # - `:value` - Define the value of the input
40
+ #
41
+ # #### Examples
42
+ #
43
+ # filepicker_field_tag('user[filepicker_url]')
44
+ # # => <input data-fp-apikey="..." id="user_filepicker_url" name="user[filepicker_url]" type="filepicker" />
45
+ #
46
+ def filepicker_field_tag(name, options = {})
47
+ define_input_options(options)
48
+ tag :input, { 'type' => type, 'name' => name, 'id' => sanitize_to_id(name) }.update(input_options.stringify_keys)
49
+ end
50
+
14
51
  # Creates a button allowing the user to download a file
15
52
  # (or upload it to any of the supported services). Set the content of
16
53
  # the button on the `text` parameter. The `url` of the content you want the user to save.
@@ -1,12 +1,7 @@
1
1
  module FilepickerRails
2
2
  module FormHelper
3
3
 
4
- FILEPICKER_OPTIONS_TO_DASHERIZE = [:button_text, :button_class, :mimetypes,
5
- :extensions, :container, :services,
6
- :drag_text, :drag_class, :store_path,
7
- :store_location, :store_access, :multiple]
8
-
9
- FILEPICKER_OPTIONS_TO_CAMELIZE = [:max_size]
4
+ include FilepickerRails::Tag
10
5
 
11
6
  # Creates a filepicker field, accepts optional `options` hash for configuration.
12
7
  #
@@ -21,12 +16,15 @@ module FilepickerRails
21
16
  # - `:services` - What services your users can upload to. Ex: `BOX, COMPUTER, FACEBOOK`.
22
17
  # - `:store_path` - The path to store the file at within the specified file store.
23
18
  # - `:store_location` - The file is not copied by default. It remains in the original location. If you wish you have the file copied onto your own storage, you can specify where we should put the copy. The only value at the moment is `S3`.
19
+ # - `:store_container` - The bucket or container in your specified `store_location`. Defaults to the container specified in the developer portal. Does not apply to Dropbox storage.
24
20
  # - `:store_access` - Should the underlying file be publicly available on its S3 link. Options are `public` and `private`, defaults to 'private'.
25
21
  # - `:dragdrop` - (`true` or `false`) Whether or not to allow drag-and-drop uploads.
26
22
  # - `:drag_text` - The text of the dragdrop pane.
27
23
  # - `:drag_class` - The class of the dragdrop pane.
28
24
  # - `:onchange` - The onchange event.
29
25
  # - `:max_size` - The maximum file size allowed, in bytes.
26
+ # - `:max_files` - The maximum number of files.
27
+ # - `:open_to` - Open the picker to the given service. Ex: `COMPUTER`.
30
28
  # - `:class` - Add a class to the input.
31
29
  # - `:value` - Define the value of the input
32
30
  #
@@ -54,16 +52,7 @@ module FilepickerRails
54
52
 
55
53
  private
56
54
 
57
- attr_reader :input_options, :method, :type, :object_name, :template
58
-
59
- def define_input_options(options)
60
- @type = options.delete(:dragdrop) ? 'filepicker-dragdrop' : 'filepicker'
61
- @input_options = retrieve_legacy_filepicker_options(options)
62
- @input_options['data-fp-apikey'] ||= ::Rails.application.config.filepicker_rails.api_key
63
- @input_options.merge!(secure_filepicker) unless @input_options['data-fp-policy'].present?
64
- @input_options['type'] = @type
65
- @input_options
66
- end
55
+ attr_reader :method, :object_name, :template
67
56
 
68
57
  def rails_greater_than_4_input
69
58
  tag = ActionView::Helpers::Tags::TextField.new(object_name, method, template, objectify_options(input_options))
@@ -78,24 +67,5 @@ module FilepickerRails
78
67
  def rails_greater_than_4?
79
68
  ::Rails.version.to_i >= 4
80
69
  end
81
-
82
- def filepicker_prefix
83
- 'data-fp-'
84
- end
85
-
86
- def retrieve_legacy_filepicker_options(options)
87
- mappings = {}
88
- FILEPICKER_OPTIONS_TO_DASHERIZE.each do |option|
89
- mappings[option] = "#{filepicker_prefix}#{option.to_s.dasherize}"
90
- end
91
- FILEPICKER_OPTIONS_TO_CAMELIZE.each do |option|
92
- mappings[option] = "#{filepicker_prefix}#{option.to_s.camelize(:lower)}"
93
- end
94
- Hash[options.map {|k, v| [mappings[k] || k, v] }]
95
- end
96
-
97
- def secure_filepicker
98
- Policy.apply([:pick, :store], ['data-fp-policy', 'data-fp-signature'])
99
- end
100
70
  end
101
71
  end
@@ -1,6 +1,7 @@
1
1
  require "filepicker_rails/configuration"
2
2
  require "filepicker_rails/policy"
3
3
  require "filepicker_rails/engine"
4
+ require "filepicker_rails/tag"
4
5
 
5
6
  module FilepickerRails
6
7
  end
@@ -39,7 +39,7 @@ module FilepickerRails
39
39
  hash[input] = send(input) unless send(input).nil?
40
40
  end
41
41
 
42
- MultiJson.dump(hash)
42
+ hash.to_json
43
43
  end
44
44
  end
45
45
  private_constant :Policy
@@ -0,0 +1,44 @@
1
+ module FilepickerRails
2
+ module Tag
3
+
4
+ FILEPICKER_OPTIONS_TO_DASHERIZE = [:button_text, :button_class, :mimetypes,
5
+ :extensions, :container, :services,
6
+ :drag_text, :drag_class, :store_path,
7
+ :store_location, :store_access,
8
+ :store_container, :multiple]
9
+
10
+ FILEPICKER_OPTIONS_TO_CAMELIZE = [:max_size, :max_files, :open_to]
11
+
12
+ private
13
+
14
+ attr_reader :input_options, :type
15
+
16
+ def define_input_options(options)
17
+ @type = options.delete(:dragdrop) ? 'filepicker-dragdrop' : 'filepicker'
18
+ @input_options = retrieve_legacy_filepicker_options(options)
19
+ @input_options['data-fp-apikey'] ||= ::Rails.application.config.filepicker_rails.api_key
20
+ @input_options.merge!(secure_filepicker) unless @input_options['data-fp-policy'].present?
21
+ @input_options['type'] = @type
22
+ @input_options
23
+ end
24
+
25
+ def filepicker_prefix
26
+ 'data-fp-'
27
+ end
28
+
29
+ def retrieve_legacy_filepicker_options(options)
30
+ mappings = {}
31
+ FILEPICKER_OPTIONS_TO_DASHERIZE.each do |option|
32
+ mappings[option] = "#{filepicker_prefix}#{option.to_s.dasherize}"
33
+ end
34
+ FILEPICKER_OPTIONS_TO_CAMELIZE.each do |option|
35
+ mappings[option] = "#{filepicker_prefix}#{option.to_s.camelize(:lower)}"
36
+ end
37
+ Hash[options.map {|k, v| [mappings[k] || k, v] }]
38
+ end
39
+
40
+ def secure_filepicker
41
+ Policy.apply([:pick, :store], ['data-fp-policy', 'data-fp-signature'])
42
+ end
43
+ end
44
+ end
@@ -1,3 +1,3 @@
1
1
  module FilepickerRails
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filepicker-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Tilford
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-31 00:00:00.000000000 Z
11
+ date: 2015-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -152,6 +152,7 @@ files:
152
152
  - lib/filepicker_rails/configuration.rb
153
153
  - lib/filepicker_rails/engine.rb
154
154
  - lib/filepicker_rails/policy.rb
155
+ - lib/filepicker_rails/tag.rb
155
156
  - lib/filepicker_rails/version.rb
156
157
  homepage: https://github.com/Ink/filepicker-rails
157
158
  licenses: