Class: Locomotive::ImageInput
- Inherits:
-
SimpleForm::Inputs::StringInput
- Object
- SimpleForm::Inputs::StringInput
- Locomotive::ImageInput
- Extended by:
- Forwardable
- Defined in:
- app/inputs/locomotive/image_input.rb
Direct Known Subclasses
Instance Method Summary collapse
- #actions ⇒ Object
- #browse_button_html ⇒ Object
- #default_url ⇒ Object
- #file? ⇒ Boolean
- #file_input ⇒ Object
- #file_url ⇒ Object
- #file_wrapper_options ⇒ Object
- #filename_html ⇒ Object
- #image_html ⇒ Object
- #input(wrapper_options = nil) ⇒ Object
- #resize_format ⇒ Object
- #resized_file_url ⇒ Object
- #text(name) ⇒ Object
Instance Method Details
#actions ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'app/inputs/locomotive/image_input.rb', line 42 def actions "<i class=\"fa fa-trash\" data-action=\"delete\" style=\"\#{'display: none;' unless file?}\"></i>\n<i class=\"fa fa-undo\" data-action=\"undo\" style=\"display: none;\"></i>\n<span class=\"spinner\" style=\"display: none;\">\n<i class=\"fa fa-circle-o-notch fa-spin\" ></i>\n</span>\n" end |
#browse_button_html ⇒ Object
35 36 37 38 39 40 |
# File 'app/inputs/locomotive/image_input.rb', line 35 def label, url = text(:browse), template.content_assets_path(template.current_site) "<a class=\"file-browse\" href=\"\#{url}\">\#{label}</a>\n" end |
#default_url ⇒ Object
78 79 80 |
# File 'app/inputs/locomotive/image_input.rb', line 78 def default_url [:default_url] || template.asset_path('locomotive/blank.png') end |
#file? ⇒ Boolean
64 65 66 |
# File 'app/inputs/locomotive/image_input.rb', line 64 def file? self.object.send(:"#{attribute_name}").present? end |
#file_input ⇒ Object
26 27 28 |
# File 'app/inputs/locomotive/image_input.rb', line 26 def file_input @builder.text_field(attribute_name) end |
#file_url ⇒ Object
68 69 70 |
# File 'app/inputs/locomotive/image_input.rb', line 68 def file_url self.object.send(attribute_name.to_sym) end |
#file_wrapper_options ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'app/inputs/locomotive/image_input.rb', line 82 def { resize: resize_format, persisted: file?, url: resized_file_url, default_url: default_url, no_file_label: text(:none) }.map { |k, value| "data-#{k.to_s.dasherize}=\"#{value}\"" }.join(' ') end |
#filename_html ⇒ Object
56 57 58 59 60 61 62 |
# File 'app/inputs/locomotive/image_input.rb', line 56 def filename_html if file? template.link_to(File.basename(file_url), file_url, target: 'blank') else text(:none) end end |
#image_html ⇒ Object
30 31 32 33 |
# File 'app/inputs/locomotive/image_input.rb', line 30 def image_html url = resized_file_url || default_url template.image_tag(url) end |
#input(wrapper_options = nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/inputs/locomotive/image_input.rb', line 8 def input( = nil) "<div class=\"file-wrapper\" \#{file_wrapper_options}>\n<div class=\"file-image\">\n\#{image_html}\n\#{actions}\n</div>\n<label class=\"file\">\n\#{file_input}\n<span class=\"file-custom\">\n<span class=\"file-name\">\#{filename_html}</span>\n\#{browse_button_html}\n</span>\n</label>\n</div>\n" end |
#resize_format ⇒ Object
52 53 54 |
# File 'app/inputs/locomotive/image_input.rb', line 52 def resize_format [:resize] || '96x96#' end |
#resized_file_url ⇒ Object
72 73 74 75 76 |
# File 'app/inputs/locomotive/image_input.rb', line 72 def resized_file_url if file? Locomotive::Dragonfly.resize_url file_url, resize_format end end |
#text(name) ⇒ Object
92 93 94 |
# File 'app/inputs/locomotive/image_input.rb', line 92 def text(name) I18n.t(name, scope: 'locomotive.inputs.file') end |