filepicker-rails 1.2.0 → 1.3.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: a7c6108a87b1e18899294344d21da54df7705e14
4
- data.tar.gz: fbab8e63de76ba8773a0aa1283591223386e8827
3
+ metadata.gz: 807acef7a7f487b4db552bebc8c084641e4f2730
4
+ data.tar.gz: fc310857861c323da6c123b00ee22a216c976017
5
5
  SHA512:
6
- metadata.gz: f445d0c3ebc0b0766d1bd034d27aa4fc5c53c5cd405c6bbf2b753263e33288834e1b6d61eeeb73c4410260bddb4f1c0a8fe45f329f91314fd1a1316480b0e3d0
7
- data.tar.gz: f1e3d5ff4a55be3249441f7cace323ff85f4658d64220a836ec5641c090842347be91ab0706a1be4724bcde5221788630d5b14b70c4a6045d2c212d8fcb68c77
6
+ metadata.gz: a76e4bb901b528dd717e92a85fe10e9237e209824bc4b020d682de42c3cda743a1b9c33b103874ccd33f05f4e2297ced454a7991f83fdcb9b82f9a24eb489fa1
7
+ data.tar.gz: da50efe1cd0c2b9cd7a8354a78dcbe19bf6f482aaad5470138c98923a19ce1441cdc05f2c439b0d711539912013419cd893655fcf5581116982ebca388e6f8e0
@@ -29,18 +29,33 @@ module FilepickerRails
29
29
  # # => <button data-fp-apikey="..." data-fp-mimetype="image/jpg" data-fp-url="https://www.filepicker.io/api/file/hFHUCB3iTxyMzseuWOgG" name="button" type="submit">save</button>
30
30
  #
31
31
  def filepicker_save_button(text, url, mimetype, options = {})
32
- options[:data] ||= {}
33
- container = options.delete(:container)
34
- services = options.delete(:services)
35
- save_as = options.delete(:save_as_name)
36
-
37
- options[:data]['fp-url'] = url
38
- options[:data]['fp-apikey'] = ::Rails.application.config.filepicker_rails.api_key
39
- options[:data]['fp-mimetype'] = mimetype
40
- options[:data]['fp-option-container'] = container if container
41
- options[:data]['fp-option-services'] = Array(services).join(",") if services
42
- options[:data]['fp-option-defaultSaveasName'] = save_as if save_as
43
- button_tag(text, options)
32
+ export_widget(text, url, mimetype, options) do
33
+ button_tag(text, options)
34
+ end
35
+ end
36
+
37
+ # Creates a link allowing the user to download a file
38
+ # (or upload it to any of the supported services). Set the content of
39
+ # the link on the `text` parameter. The `url` of the content you want the user to save.
40
+ # Define the `mimetype` of the content. Accepts a optional `options` parameter.
41
+ #
42
+ # #### Options
43
+ #
44
+ # - `:container` - Where to show the file picker dialog can be `modal`,
45
+ # `window` or the id of an iframe on the page.
46
+ # - `:services` - What services your users can upload to. Ex: `BOX, COMPUTER, FACEBOOK`.
47
+ # - `:save_as_name` - A recommended file name. The user can override this.
48
+ #
49
+ # #### Examples
50
+ #
51
+ # filepicker_save_link "Save", @user.filepicker_url, "image/jpg"
52
+ # # => <a data-fp-apikey="..." data-fp-mimetype="image/jpg" data-fp-url="https://www.filepicker.io/api/file/hFHUCB3iTxyMzseuWOgG" href="#" id="filepicker_export_widget_link">save</a>
53
+ #
54
+ def filepicker_save_link(text, url, mimetype, options = {})
55
+ export_widget(text, url, mimetype, options) do
56
+ options[:id] = options.fetch(:id, 'filepicker_export_widget_link')
57
+ link_to text, '#', options
58
+ end
44
59
  end
45
60
 
46
61
  # Creates a image tag of the `url`. Accepts the options to work on filepicker.io,
@@ -168,5 +183,22 @@ module FilepickerRails
168
183
  end
169
184
  end
170
185
  private_constant :FilepickerImageUrl
186
+
187
+ private
188
+
189
+ def export_widget(text, url, mimetype, options, &block)
190
+ options[:data] ||= {}
191
+ container = options.delete(:container)
192
+ services = options.delete(:services)
193
+ save_as = options.delete(:save_as_name)
194
+
195
+ options[:data]['fp-url'] = url
196
+ options[:data]['fp-apikey'] = ::Rails.application.config.filepicker_rails.api_key
197
+ options[:data]['fp-mimetype'] = mimetype
198
+ options[:data]['fp-option-container'] = container if container
199
+ options[:data]['fp-option-services'] = Array(services).join(",") if services
200
+ options[:data]['fp-option-defaultSaveasName'] = save_as if save_as
201
+ block.call
202
+ end
171
203
  end
172
204
  end
@@ -1,3 +1,3 @@
1
1
  module FilepickerRails
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.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.2.0
4
+ version: 1.3.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-08-23 00:00:00.000000000 Z
11
+ date: 2014-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -173,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
173
  version: '0'
174
174
  requirements: []
175
175
  rubyforge_project:
176
- rubygems_version: 2.2.2
176
+ rubygems_version: 2.4.5
177
177
  signing_key:
178
178
  specification_version: 4
179
179
  summary: Makes integrating filepicker.io with rails 4 easy