Module: FilepickerioRails::ActionView::FormTagHelper
- Defined in:
- lib/filepickerio_rails/action_view/form_tag_helper.rb
Overview
This module creates filepicker.io fields
Examples:
filepickerio_upload_tag :user, 'Pick file', 'http://example.com/existing-upload.jpg', data: { "fp-mimetypes": "image/jpg" }
'Save file to cloud', 'http://example.com/existing-upload.jpg', 'image/jpeg'
Instance Method Summary collapse
- #fp_file_field(object_name, method, text_or_options, options) ⇒ Object
- #fp_file_field_tag(object_name, text_or_options = nil, value_or_options = nil, options = {}) ⇒ Object
- #fp_save_button(object, method, content = nil, mime = nil, options = {}, &block) ⇒ Object
- #fp_save_button_tag(content = nil, url = nil, mime = nil, options = nil, &block) ⇒ Object
Instance Method Details
#fp_file_field(object_name, method, text_or_options, options) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/filepickerio_rails/action_view/form_tag_helper.rb', line 43 def fp_file_field(object_name, method, , ) if .is_a? Hash text = nil = else text = end dragdrop = [:dragdrop] && [:dragdrop] == true input_type = if dragdrop .delete(:dragdrop) 'filepicker-dragdrop' else 'filepicker' end = { type: input_type, size: nil, data: { "fp-apikey" => fp_api_key, "fp-button-text" => text || 'Pick File' } }.deep_merge() ::ActionView::Helpers::InstanceTag.new(object_name, method, self, .delete(:object)).to_input_field_tag(input_type, ) end |
#fp_file_field_tag(object_name, text_or_options = nil, value_or_options = nil, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/filepickerio_rails/action_view/form_tag_helper.rb', line 14 def fp_file_field_tag(object_name, =nil, =nil, ={}) # Allow users to pass in variable length arguments if .is_a? Hash # Nothing passed but options text = nil value = nil = elsif .is_a? Hash # only text and options text = value = nil = else # full params text = value = # options = options end .merge!( # This avoids the ActiveModel naming of `object_name[method]` id: object_name, name: object_name, value: value ) fp_file_field(object_name, nil, text, ) end |
#fp_save_button(object, method, content = nil, mime = nil, options = {}, &block) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/filepickerio_rails/action_view/form_tag_helper.rb', line 84 def (object, method, content=nil, mime=nil, ={}, &block) raise "Mime type of file to be saved must be set" if mime.nil? value = [:value] if object && method if !value value = .fetch(:value){ ::ActionView::Helpers::InstanceTag::value_before_type_cast(object, method.to_s) } value &&= ERB::Util.html_escape(value) end end = { name: nil, type: 'button', data: { "fp-apikey" => fp_api_key, "fp-mimetype" => mime, "fp-url" => value } }.deep_merge() # Convert services array into string if [:data]['fp-option-services'].is_a? Array [:data]['fp-option-services'] = [:data]['fp-option-services'].join(',') end (content || 'Save file', , &block) end |
#fp_save_button_tag(content = nil, url = nil, mime = nil, options = nil, &block) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/filepickerio_rails/action_view/form_tag_helper.rb', line 72 def (content=nil, url=nil, mime=nil, =nil, &block) raise "URL of file to be saved must be set" if url.nil? .deep_merge!({ data: { "fp-url" => url } }) (nil, nil, content, mime, , &block) end |