Module: Uploadcare::Rails::ActionView::UploadcareWidgetTags

Defined in:
lib/uploadcare/rails/action_view/uploadcare_include_tags.rb

Overview

A module containing a view include tags helper

Instance Method Summary collapse

Instance Method Details

#uploadcare_include_tag(version: '3.x', bundle: 'full', min: true) ⇒ Object

A view helper to add a js script tag from CDN with just one string of code. See uploadcare.com/docs/uploads/file-uploader/#cdn for more info.

Example:

<%= uploadcare_include_tag %>
=> <script src="https://ucarecdn.com/libs/widget/3.x/uploadcare.full.min.js"></script>
   <script>
     UPLOADCARE_PUBLIC_KEY = 'demopublickey';
     UPLOADCARE_LOCALE = 'en';
   </script>

Arguments:

version: (String, default: '3.x') - version of the widget
bundle: (String, default: 'full') - https://uploadcare.com/docs/uploads/file-uploader/#bundles
  valid options: 'full', 'default', 'ie8', 'api', 'lang.en'
min: (true/false, default: true) - sets which version to get, minified or not


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/uploadcare/rails/action_view/uploadcare_include_tags.rb', line 28

def uploadcare_include_tag(version: '3.x', bundle: 'full', min: true)
  min = min == true ? '.min' : ''
  bundle = bundle == 'default' ? '' : ".#{bundle}"
  path = "/libs/widget/#{version}/uploadcare#{bundle}#{min}.js"
  uri = URI::HTTPS.build(host: Uploadcare::Rails.configuration.cdn_hostname, path: path)

  config_tag = javascript_tag(uploader_settings) if uploader_settings.present?
  include_tag = javascript_include_tag(uri.to_s.squeeze('.'))

  include_tag.concat(config_tag)
end

#uploader_settingsObject



40
41
42
# File 'lib/uploadcare/rails/action_view/uploadcare_include_tags.rb', line 40

def uploader_settings
  @uploader_settings ||= Uploadcare::Rails.configuration.uploader_parameters
end