filestack-rails 3.1.0 → 3.1.1

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: 12acbf16028d407537c3f4f63b5764c6d0ffd122
4
- data.tar.gz: 783890ee5cd1508e3f3e4826e96735ea72423cb2
3
+ metadata.gz: 1f4dd0cbb37d89c5813e52869b2170833972e510
4
+ data.tar.gz: dafc43ed58576949d0791c703cbf57f94b650708
5
5
  SHA512:
6
- metadata.gz: 8e3eeac8a38167ca004b3d7753635d2ac2a7d14344be2261637d221dde07cf2b93dce36f1e3cc23d6716a3a86b3099f7e14d134be2f866bd38064932b9042708
7
- data.tar.gz: ac9e762eb23a017c247a9d20e4330b68eab4f17390884a6a468ce03b56cfc3affc0b26729997c2e2efffe36b195e1012317a80fa7e3ff06bce094e3c90a6f06f
6
+ metadata.gz: 7a44fc0084ada046a2509b74242c278b39d780f1c45c19d4006e6179e139a0fa6e128ef892ae65e6671dd083091c8953e44a45b61398fd7580feeec7aa97511b
7
+ data.tar.gz: 968cc05bbd359b8f28cac9a6c1464d35ffbdaee9f31dd142fe1f6ce00a5bd14bc8c04ae3621a89d8456bfeb73b093c11cf51d1a238329f69db267a510a22e8e2
data/README.md CHANGED
@@ -1,23 +1,30 @@
1
- [![Travis CI][travis_ci_badge]][travis_ci]
2
- [![Coveralls][coveralls_badge]][coveralls]
3
- [![Code Climate][code_climate_badge]][code_climate]
1
+ <p align="center"><img src="https://filestack.com/themes/filestack/assets/images/press-articles/color.svg" align="center" width="100"/></p>
2
+ <h1 align="center">Filestack::Rails SDK</h1>
3
+ <p align="center">
4
+ <a href="https://travis-ci.org/filestack/filestack-rails">
5
+ <img src="https://img.shields.io/travis/filestack/filestack-rails/master.svg?longCache=true&style=flat-square">
6
+ </a>
7
+ <a href="https://coveralls.io/github/filestack/filestack-rails?branch=master">
8
+ <img src="https://img.shields.io/coveralls/github/filestack/filestack-rails/master.svg?longCache=true&style=flat-square">
9
+ </a>
10
+ </p>
11
+ <p align="center">
12
+ Rails SDK for Filestack API and content management system.
13
+ </p>
4
14
 
5
- # Filestack::Rails
6
- <a href="https://www.filestack.com"><img src="https://filestack.com/themes/filestack/assets/images/press-articles/color.svg" align="left" hspace="10" vspace="6"></a>
7
- This is the official Rails plugin for Filestack - API and content management system that makes it easy to add powerful file uploading and transformation capabilities to any web or mobile application.
15
+ **Important: This is the readme for 3.1.0+.**
8
16
 
9
- ## Resources
17
+ Note that the [Filestack::Ruby](https://github.com/filestack/filestack-ruby/) dependency has been updated to no longer interfere with namespace. However, if you were using that dependency in your Rails application, you will need to change any `Client` and `Filelink` class declarations to `FilestackClient` and `FilestackFilelink`, as per documented [here](https://github.com/filestack/filestack-ruby/blob/master/README.md).
10
18
 
11
- * [Filestack](https://www.filestack.com)
12
- * [Documentation](https://www.filestack.com/docs)
13
- * [API Reference](https://filestack.github.io/)
19
+ ## Overview
14
20
 
15
- ## IMPORTANT
16
- Users of 3.0.0 wishing to upgrade to 3.1.0+ should note that the Filestack::Ruby dependency has been updated to no longer interfere with namespace. However, if you were using that dependency in your Rails app, you will need to change any Client and Filelink class declarations to FilestackClient and FilestackFilelink, as per documented [here](https://github.com/filestack/filestack-ruby/blob/master/README.md)
21
+ * A multi-part uploader powered on the backend by the [Filestack CIN](https://www.filestack.com/products/content-ingestion-network).
22
+ * An interface to the [Filestack Processing Engine](https://www.filestack.com/docs/image-transformations) for transforming assets via URLs.
23
+ * The Filestack Picker - an upload widget for the web that integrates over a dozen cloud providers and provides pre-upload image editing.
17
24
 
18
- ## Installing
25
+ ## Installation
19
26
 
20
- Add this line to your application's Gemfile:
27
+ Add this line to your application's `Gemfile`:
21
28
 
22
29
  ```ruby
23
30
  gem 'filestack-rails'
@@ -35,54 +42,63 @@ Add the Filestack File Picker and initialization script to your layout:
35
42
 
36
43
  ```erb
37
44
  <%= filestack_js_include_tag %>
38
- <%= filestack_js_init_tag %>
45
+ <%= filestack_js_init_tag %>
39
46
  ```
40
-
41
- Please note: the scripts need to be added before your application's custom scripts, e.g. before any scripts in your assets folder, if you need access the Filestack client in your own Javascript.
47
+ **Please note:** The scripts need to be added before your application's custom scripts, e.g. before any scripts in your assets folder, if you need access the Filestack client in your own Javascript.
42
48
 
43
49
  Set your API key and client name in `config/application.rb`:
44
50
 
45
51
  ```ruby
46
- config.filestack_rails.api_key = "Your Filestack API Key"
47
- config.filestack_rails.client_name = "custom_client_name"
52
+ config.filestack_rails.api_key = 'Your Filestack API Key'
53
+ config.filestack_rails.client_name = 'custom_client_name'
54
+ ```
55
+ The client name defaults to `"filestack_client"` and is injected into your client-side Javascript. This is because v3 of the File Picker lives in the Javascript of your web application.
56
+
57
+ ### CNAME
58
+
59
+ If you have set up a custom CNAME, you can add it to your configuration file. The Picker will modify all assets to formatted with your domain origin instead of Filestack's.
60
+
61
+ Set your CNAME in `config/application.rb`:
62
+
63
+ ```ruby
64
+ config.filestack_rails.cname = 'custom_cname'
48
65
  ```
49
- The client name defaults to "filestack_client" and is injected into your client-side Javascript. This is because v3 of the File Picker lives in the Javascript of your web application. For more information, please see our [File Picker documenation](https://www.filestack.com/docs/javascript-api/pick-v3).
50
66
 
51
67
  ### Security
52
68
 
53
- If your account has security enabled, then you must initialize the File Picker with a signature and policy. This is easily enabled through the configuration options by setting your application secret and security options:
69
+ If your account has security enabled, then you must initialize the File Picker with a signature and policy.
54
70
 
55
- ```erb
71
+ Set up your application secret and security options in `config/application.rb`:
72
+
73
+ ```ruby
56
74
  config.filestack_rails.app_secret = 'YOUR_APP_SECRET'
57
75
  config.filestack_rails.security = {'call' => %w[pick store read convert] }
58
76
  ```
59
- If you set security to an empty object like so
60
- ```erb
77
+ If you set security to an empty object like so:
78
+ ```ruby
61
79
  config.filestack_rails.security = {}
62
80
  ```
63
- it will provide a policy and signature with only an expiry setting (this defaults to one hour).
81
+ It will provide a policy and signature with only an expiry setting (this defaults to one hour).
64
82
 
65
83
  You can access the generated policy and signature anytime by calling their attributes on the created security object:
66
84
 
67
- ```erb
85
+ ```ruby
68
86
  puts config.filestack_rails.security.policy
69
87
  puts config.filestack_rails.security.signature
70
88
  ```
71
- You can also generate a new security object at any time, although this will only affect the filestack_image tag, and not the File Picker client.
89
+ You can also generate a new security object at any time, although this will only affect the filestack_image tag, and not the File Picker client.
72
90
 
73
91
  ## Usage
74
92
 
75
- Filestack::Rails provides three main functionalities:
76
-
77
93
  ### Filestack Upload Button
78
- This is a generic button that can be added anywhere in your application and opens an instance of the File Picker. Once a user has chosen a file(s) and submitted, a callback will be executed, passing in the results. You can also pass in any options for the File Picker using the pickerOptions symbol:
94
+ This is a generic button that can be added anywhere in your application and opens an instance of the File Picker. Once a user has chosen a file(s) and submitted, a callback will be executed, passing in the results. You can also pass in any options for the File Picker using the `pickerOptions` symbol:
79
95
 
80
96
  ```erb
81
- <%= filestack_picker_element 'button test', 'callbackForButton', id: 'someuniequeid', pickerOptions: { 'fromSources' => 'facebook' } %>
97
+ <%= filestack_picker_element 'button test', 'callbackForButton', id: 'someuniqueid', input_id: 'someuniqueinputid', pickerOptions: { 'fromSources' => 'facebook' } %>
82
98
  ```
83
- File Picker options are exactly the same as in the Javscript SDK and can be found in the aforementioned documentation.
99
+ File Picker options are exactly the same as in the Javscript SDK and can be found in the aforementioned documentation.
84
100
 
85
- The callback can be either the name of a function you've defined in your main Javascript or it can be any code that is immediately executable, e.g. "console.log" or "(function(data){console.log(data)})". The callback should take in a response array as its only argument, which has the following structure:
101
+ The callback can be either the name of a function you've defined in your main Javascript or it can be any code that is immediately executable, e.g. `console.log` or `(function(data){console.log(data)})`. The callback should take in a response array as its only argument, which has the following structure:
86
102
 
87
103
  ```javascript
88
104
  {
@@ -116,43 +132,48 @@ The form helper wraps the generic Pick element and adds the value of the returne
116
132
  ```erb
117
133
  <%= form_for @user do |f| %>
118
134
  <div>
119
- <%= f.filestack_field :filepicker_url, 'Upload Your Avatar!', pickerOptions: {'fromSources': 'facebook'}, id: 'unique-id' %>
135
+ <%= f.filestack_field :filepicker_url, 'Upload Your Avatar!', pickerOptions: {'fromSources': 'facebook'}, id: 'unique-id', input_id: 'unique-input-id' %>
120
136
  </div>
121
137
 
122
138
  <%= f.submit %>
123
139
  <% end %>
124
140
  ```
125
141
  ### Displaying an image with Filestack Transformations:
126
- Filestack::Rails now has access to the full list of image transforms through our custom Transformation Engine. This functionality is provided by the Filestack Ruby SDK and acts as a small wrapper around it. The filestack_image tag accepts the same options as the genric Rails image_tag, with the addition of a transform option, which accepts a filestack_transform chain:
142
+ Filestack::Rails now has access to the full list of image transforms through our custom Transformation Engine. This functionality is provided by the Filestack Ruby SDK and acts as a small wrapper around it. The `filestack_image` tag accepts the same options as the genric Rails `image_tag`, with the addition of a transform option, which accepts a `filestack_transform` chain:
127
143
 
128
144
  ```erb
129
145
  <%= filestack_image @user.filepicker_url, transform: filestack_transform.resize(width:100, height:100).flip.enhance %>
130
146
  ```
131
147
  ## Migrating from 2.x to 3.x
132
- Filestack::Rails 3.x is a significant and breaking change. Users wishing to upgrade will need to change their current implementation in order to use the plugin correctly.
148
+ Filestack::Rails 3.x is a significant and breaking change. Users wishing to upgrade will need to change their current implementation in order to use the plugin correctly.
149
+
133
150
  ### Javascript-based File Picker
134
151
  The v3 File Picker is a Javascript application that lives on the client-side of your application. This means you have greater control and access to when it is called, access to the rest of the web SDK, as well as being able to pass callbacks executed once uploads have completed. You must keep in mind the File Picker client lives in global scope and adjust your namespaces accordingly, although you can also change the name of the client, as detailed in the above sections.
152
+
135
153
  ### Form Helper
136
- The form helper's call remains essentially the same, except that it now takes as its argument the value of the button element displayed on the page.
154
+ The form helper's call remains essentially the same, except that it now takes as its argument the value of the button element displayed on the page.
137
155
  ```erb
138
156
  <%= f.filestack_field :filestack_url, 'Pick Your Avatar' >
139
157
  ```
140
158
  ### Save Button
141
- As user saving/downloading is not currently supported in the v3 File Picker, that functionality has been removed from Filestack::Rails for the time being.
159
+ As user saving/downloading is not currently supported in the v3 File Picker, that functionality has been removed from Filestack::Rails for the time being.
160
+
142
161
  ### Transformations
143
- The filestack_image tag wraps the generic Rails image_tag and generates a new URL with use of the Ruby SDK. This provides the entire scope of the possible transformations through Filestack's transformation engine, minus those which do not return an image (like debug, av_convert, and so forth). Defining transformations is as simple as chaining them together using the filestack_transform method:
162
+ The `filestack_image` tag wraps the generic Rails `image_tag` and generates a new URL with use of the Ruby SDK. This provides the entire scope of the possible transformations through Filestack's transformation engine, minus those which do not return an image (like debug, av_convert, and so forth). Defining transformations is as simple as chaining them together using the `filestack_transform` method:
144
163
  ```erb
145
164
  <%= @user.filestack_url, transform: filestack_transform.resize(width:100, height:100).enhance %>
146
165
  ```
166
+
147
167
  ### Ruby SDK
148
- Filestack::Rails injects the Filestack Ruby SDK into your application for use anywhere. You can use it to access the rest of the Filestack API and find its documentation [here](https://github.com/filestack/filestack-ruby)
168
+ Filestack::Rails injects the Filestack Ruby SDK into your application for use anywhere. You can use it to access the rest of the Filestack API and find its documentation [here](https://github.com/filestack/filestack-ruby).
169
+
149
170
  ## Demo
150
171
 
151
- To see the Filestack::Rails plugin in action, clone this repository and run the demo app by following these instructions (will only work in Rails 5.x):
172
+ To see the Filestack::Rails plugin in action, clone this repository and run the demo app by following these instructions (will only work in Rails 5.x):
152
173
 
153
174
  ### Set API key
154
175
 
155
- Go to ```spec/dummy/config/application.rb``` and change the API key to your own.
176
+ Go to ```spec/dummy/config/application.rb``` and change the API key to your own.
156
177
 
157
178
  ### Install Dependencies
158
179
 
@@ -183,20 +204,3 @@ Filestack::Rails follows the [Semantic Versioning](http://semver.org/).
183
204
  ## Issues
184
205
 
185
206
  If you have problems, please create a [Github Issue](https://github.com/filepicker/filestack-rails/issues).
186
-
187
- ## Contributing
188
-
189
- Please see [CONTRIBUTING.md](https://github.com/filepicker/filestack-rails/CONTRIBUTING.md) for details.
190
-
191
- ## Credits
192
-
193
- Thank you to all the [contributors](https://github.com/filepicker/filestack-rails/graphs/contributors).
194
-
195
- [gem_version_badge]: https://badge.fury.io/rb/filestack-rails.svg
196
- [ruby_gems]: http://rubygems.org/gems/filestack-rails
197
- [travis_ci]: http://travis-ci.org/filestack/filestack-rails
198
- [travis_ci_badge]: https://travis-ci.org/filestack/filestack-rails.svg?branch=master
199
- [code_climate]: https://codeclimate.com/github/filestack/filestack-rails
200
- [code_climate_badge]: https://codeclimate.com/github/filestack/filestack-rails.png
201
- [coveralls]: https://coveralls.io/github/filestack/filestack-rails?branch=master
202
- [coveralls_badge]: https://coveralls.io/repos/github/filestack/filestack-rails/badge.svg?branch=master
@@ -10,13 +10,8 @@ module FilestackRails
10
10
 
11
11
  def filestack_js_init_tag
12
12
  client_name, apikey = get_client_and_api_key
13
- signature, policy = get_policy_and_signature
14
- javascript_string = if policy && signature
15
- "var #{client_name} = filestack.init('#{apikey}'," \
16
- "{'signature': '#{signature}', 'policy': '#{policy}'});"
17
- else
18
- "var #{client_name} = filestack.init('#{apikey}');"
19
- end
13
+ signature_and_policy = get_policy_and_signature_string
14
+ javascript_string = "var #{client_name} = filestack.init('#{apikey}', #{signature_and_policy}, '#{cname}');"
20
15
  javascript_tag javascript_string
21
16
  end
22
17
 
@@ -26,7 +21,7 @@ module FilestackRails
26
21
  options[:onclick] = create_javascript_for_picker(callback, picker_options)
27
22
  options[:type] = 'button'
28
23
  button_tag content, options
29
- end
24
+ end
30
25
 
31
26
  def filestack_transform
32
27
  _, apikey = get_client_and_api_key
@@ -46,6 +41,10 @@ module FilestackRails
46
41
 
47
42
  private
48
43
 
44
+ def cname
45
+ ::Rails.application.config.filestack_rails.cname
46
+ end
47
+
49
48
  def create_javascript_for_picker(callback, options)
50
49
  client_name, = get_client_and_api_key
51
50
  json_string = if options.nil?
@@ -74,5 +73,11 @@ module FilestackRails
74
73
  end
75
74
  return [signature, policy]
76
75
  end
76
+
77
+ def get_policy_and_signature_string
78
+ signature, policy = get_policy_and_signature
79
+ return "{'signature': '#{signature}', 'policy': '#{policy}'}" if policy && signature
80
+ return "''"
81
+ end
77
82
  end
78
83
  end
@@ -10,7 +10,7 @@ module FilestackRails
10
10
 
11
11
  def get_filestack_field_button(method, content, options = {})
12
12
  input_options = {}
13
- input_options[:id] = "#{@object.class.name.downcase}_#{method.downcase}"
13
+ input_options[:id] = filestack_input_field_id(method, options[:input_id])
14
14
  input_options[:style] = 'display:none'
15
15
  user_callback = options[:callback] || nil
16
16
  options.delete(:callback)
@@ -22,11 +22,15 @@ module FilestackRails
22
22
  unless user_callback.nil?
23
23
  form_field_callback_guts = "#{form_field_callback_guts}#{user_callback}(data)"
24
24
  end
25
-
25
+
26
26
  form_field_callback = "(function(data){#{form_field_callback_guts}})"
27
27
 
28
28
  html_string = "#{filestack_picker_element(content, form_field_callback, options)}#{text_field(method, input_options)}"
29
29
  raw html_string.html_safe
30
30
  end
31
+
32
+ def filestack_input_field_id(method, input_id)
33
+ input_id.presence || "#{@object.class.name.downcase}_#{method.downcase}"
34
+ end
31
35
  end
32
36
  end
@@ -1,6 +1,6 @@
1
1
  module FilestackRails
2
2
  class Configuration
3
- attr_accessor :api_key, :client_name, :secret_key, :security, :expiry, :app_secret
3
+ attr_accessor :api_key, :client_name, :secret_key, :security, :expiry, :app_secret, :cname
4
4
 
5
5
  def api_key
6
6
  @api_key or raise "Set config.filepicker_rails.api_key"
@@ -22,4 +22,4 @@ module FilestackRails
22
22
  end
23
23
 
24
24
  end
25
- end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module FilestackRails
2
- VERSION = '3.1.0'
2
+ VERSION = '3.1.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filestack-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - filestack
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-04 00:00:00.000000000 Z
11
+ date: 2018-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 2.1.0
33
+ version: 2.2.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 2.1.0
40
+ version: 2.2.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: coveralls
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  version: '0'
133
133
  requirements: []
134
134
  rubyforge_project:
135
- rubygems_version: 2.6.8
135
+ rubygems_version: 2.6.14
136
136
  signing_key:
137
137
  specification_version: 4
138
138
  summary: Filestack plugin for Rails 4+