Module: FileClip::ActionView::Helpers
- Defined in:
- lib/fileclip/action_view/helpers.rb
Instance Method Summary collapse
-
#activation(js, id, callback) ⇒ Object
Return empty tag if it’s nil or true.
-
#fileclip_css_classes(given_classes) ⇒ Object
Add js-fileclip to existing classes.
-
#fileclip_id(form_object) ⇒ Object
Object id for link.
-
#fileclip_js_include_tag ⇒ Object
Include relevant JS.
-
#fileclip_link_builder(link, form_object, options, id) ⇒ Object
Options Activate (defaults to true) to set own javascript.
-
#link_to_fileclip(text, form_object, options = {}, &block) ⇒ Object
Options js to activate it on the spot, defaults to true class to add css classes.
Instance Method Details
#activation(js, id, callback) ⇒ Object
Return empty tag if it’s nil or true
45 46 47 48 49 50 51 |
# File 'lib/fileclip/action_view/helpers.rb', line 45 def activation(js, id, callback) return javascript_tag unless js.nil? || js javascript_tag("(function() { (new FileClip).button('##{id}', #{callback || 'null'}); })();") end |
#fileclip_css_classes(given_classes) ⇒ Object
Add js-fileclip to existing classes
30 31 32 33 34 35 |
# File 'lib/fileclip/action_view/helpers.rb', line 30 def fileclip_css_classes(given_classes) return "js-fileclip" if given_classes.nil? css_classes = [].push(given_classes.split) css_classes << "js-fileclip" css_classes end |
#fileclip_id(form_object) ⇒ Object
Object id for link
38 39 40 41 42 |
# File 'lib/fileclip/action_view/helpers.rb', line 38 def fileclip_id(form_object) new_object = form_object.object = new_object. "#{attachment_name}_#{new_object.object_id}" end |
#fileclip_js_include_tag ⇒ Object
Include relevant JS
6 7 8 |
# File 'lib/fileclip/action_view/helpers.rb', line 6 def fileclip_js_include_tag javascript_include_tag "fileclip" end |
#fileclip_link_builder(link, form_object, options, id) ⇒ Object
Options Activate (defaults to true) to set own javascript
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/fileclip/action_view/helpers.rb', line 55 def fileclip_link_builder(link, form_object, , id) # Get attachment name = form_object.object. js = activation([:js], id, [:callback]) js + link + form_object.hidden_field(:filepicker_url, class: "js-fileclip_url", data: { type: }) end |
#link_to_fileclip(text, form_object, options = {}, &block) ⇒ Object
Options js to activate it on the spot, defaults to true class to add css classes
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fileclip/action_view/helpers.rb', line 13 def link_to_fileclip(text, form_object, ={}, &block) form_object, = text, form_object if block_given? id = fileclip_id(form_object) classes = fileclip_css_classes([:class]) # Got to be a cleaner way to do this link = if block_given? link_to "javascript:void(0)", class: classes, id: id, &block else link_to text, "javascript:void(0)", class: classes, id: id end fileclip_link_builder(link, form_object, , id) end |