filestack / filestack-rails

Official Ruby on Rails plugin for Filestack File Picker that makes it easy to add powerful file uploading and transformation capabilities to any web or mobile application.
https://www.filestack.com
Apache License 2.0
223 stars 102 forks source link

Feature/fs 1339 add javascript include tag #163

Closed staturecrane closed 7 years ago

staturecrane commented 7 years ago

This pull request fulfills the following tasks:

Initialization

The v3 picker is initialized as a variable on the client side. To deal with this, there are now two tags that must be added:

<%= filestack_js_include_tag %>
<%= filestack_js_init_tag %>

The first of which loads the v3 Picker onto the page, while the second tag initializes it. You can define a custom client name in the config options as such:

config.filestack_rails.api_key = 'your_api_key'
config.filestack_rails.client_name = 'custom_client_name'

Which can then be referenced via:

// in app/assets/javascripts
console.log(custom_client_name)

Otherwise the name defaults to "filestack_client".

Another element has also been added, the filestack_picker_element (name open to discussion). It functions as a button that can be added to any page, which accepts a Javascript callback to handle return data from the API. Example usage would be such:

// in app/assets/javascripts
function handlePickerData(data){
    console.log(data.filesUploaded[0].url)
}
<%= filestack_picker_element "button_content", "handlePickerData" %>

Everything else that has been added has been to set up the next tasks, and as there is significant differences in the way that v2 and v3 Pickers behave, a lot of the code has been excised or rewritten. After looking through the issues, I have been careful to ensure we keep proper namespacing and that we are not modifying/affecting global rails options or names as much as possible.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-10.0%) to 90.0% when pulling cda70a745170ed04264fa3df77c0c813334d551d on feature/FS-1339-add-javascript-include-tag into cc149dde4df58bb17d5d690717d4552d5ca7f433 on develop.