Class: Formtastic::Inputs::DragonflyInput
- Inherits:
-
FileInput
- Object
- FileInput
- Formtastic::Inputs::DragonflyInput
- Defined in:
- lib/formtastic/inputs/dragonfly_input.rb
Instance Method Summary collapse
- #fragment_download_html ⇒ Object
- #fragment_html(fragment) ⇒ Object
- #fragment_id(fragment) ⇒ Object
- #fragment_label(fragment) ⇒ Object
- #fragment_label_html(fragment) ⇒ Object
- #fragment_preview_html ⇒ Object
- #fragment_remove_html ⇒ Object
- #fragment_upload_html ⇒ Object
- #fragment_url_html ⇒ Object
- #fragments_label ⇒ Object
- #fragments_wrapping(&block) ⇒ Object
- #fragments_wrapping_html_options ⇒ Object
- #is_image?(file) ⇒ Boolean
- #to_html ⇒ Object
Instance Method Details
#fragment_download_html ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/formtastic/inputs/dragonfly_input.rb', line 89 def fragment_download_html file = object.send(method) download = if file.present? original_url = file.url name = object.send("#{method}_name") rescue "Download" name = name.blank? ? "Download" : name template.link_to name, original_url else "<span class='no-file'>#{I18n.t("dragonfly.no_file")}</span>".html_safe end fragment_label_html(:download) << download end |
#fragment_html(fragment) ⇒ Object
59 60 61 |
# File 'lib/formtastic/inputs/dragonfly_input.rb', line 59 def fragment_html(fragment) send("fragment_#{fragment}_html") end |
#fragment_id(fragment) ⇒ Object
46 47 48 |
# File 'lib/formtastic/inputs/dragonfly_input.rb', line 46 def fragment_id(fragment) "#{input_html_options[:id]}_#{fragment}" end |
#fragment_label(fragment) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/formtastic/inputs/dragonfly_input.rb', line 50 def fragment_label(fragment) = [:labels] || {} if .key?(fragment) [fragment] else ::I18n.t(fragment.to_s, :default => fragment.to_s.humanize, :scope => [:dragonfly]) end end |
#fragment_label_html(fragment) ⇒ Object
41 42 43 44 |
# File 'lib/formtastic/inputs/dragonfly_input.rb', line 41 def fragment_label_html(fragment) text = fragment_label(fragment) text.blank? ? "".html_safe : template.content_tag(:label, text, :for => fragment_id(fragment)) end |
#fragment_preview_html ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/formtastic/inputs/dragonfly_input.rb', line 73 def fragment_preview_html file = object.send(method) if file.present? if is_image?(file) original_url = object.send(method).url preview_size = [:preview_size] || [ 75, 75 ] preview_url = object.send(method).thumb("#{preview_size.first}x#{preview_size.last}#").url fragment_label_html(:preview) << template.link_to(template.image_tag(preview_url), original_url) else fragment_download_html end else fragment_label_html(:preview) << "<div class='no-image'>#{I18n.t("dragonfly.no_image")}</div>".html_safe end end |
#fragment_remove_html ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'lib/formtastic/inputs/dragonfly_input.rb', line 107 def fragment_remove_html if object.send("#{method}_uid") template.content_tag(:label, for: fragment_id(:remove)) do builder.check_box("remove_#{method}") << " ".html_safe << I18n.t("dragonfly.remove") end end end |
#fragment_upload_html ⇒ Object
63 64 65 66 67 |
# File 'lib/formtastic/inputs/dragonfly_input.rb', line 63 def fragment_upload_html fragment_label_html(:upload) << builder.file_field(method, ) << builder.hidden_field("retained_#{method}") end |
#fragment_url_html ⇒ Object
102 103 104 105 |
# File 'lib/formtastic/inputs/dragonfly_input.rb', line 102 def fragment_url_html fragment_label_html(:url) << builder.text_field("#{method}_url") end |
#fragments_label ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/formtastic/inputs/dragonfly_input.rb', line 33 def fragments_label if render_label? template.content_tag(:legend, builder.label(method, label_text, :class => "label")) else "".html_safe end end |
#fragments_wrapping(&block) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/formtastic/inputs/dragonfly_input.rb', line 22 def fragments_wrapping(&block) template.content_tag(:fieldset, template.capture(&block).html_safe, ) end |
#fragments_wrapping_html_options ⇒ Object
29 30 31 |
# File 'lib/formtastic/inputs/dragonfly_input.rb', line 29 def { :class => "fragments" } end |
#is_image?(file) ⇒ Boolean
69 70 71 |
# File 'lib/formtastic/inputs/dragonfly_input.rb', line 69 def is_image?(file) file.mime_type =~ /png|bmp|gif|tif|jpe?g/ end |
#to_html ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/formtastic/inputs/dragonfly_input.rb', line 6 def to_html components = [:components] || [ :preview, :upload, :remove ] input_wrapping do fragments_wrapping do fragments_label << template.content_tag(:ol) do components.map do |component| template.content_tag(:li, class: "input component-#{component}") do fragment_html(component) end end.join.html_safe end end end end |