class Formtastic::Inputs::DragonflyInput

Public Instance Methods

fragment_download_html() click to toggle source
# 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) click to toggle source
# File lib/formtastic/inputs/dragonfly_input.rb, line 59
def fragment_html(fragment)
  send("fragment_#{fragment}_html")
end
fragment_id(fragment) click to toggle source
# File lib/formtastic/inputs/dragonfly_input.rb, line 46
def fragment_id(fragment)
  "#{input_html_options[:id]}_#{fragment}"
end
fragment_label(fragment) click to toggle source
# File lib/formtastic/inputs/dragonfly_input.rb, line 50
def fragment_label(fragment)
  labels_from_options = options[:labels] || {}
  if labels_from_options.key?(fragment)
    labels_from_options[fragment]
  else
    ::I18n.t(fragment.to_s, :default => fragment.to_s.humanize, :scope => [:dragonfly])
  end
end
fragment_label_html(fragment) click to toggle source
# 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() click to toggle source
# 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 = input_html_options[: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() click to toggle source
# 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() click to toggle source
# File lib/formtastic/inputs/dragonfly_input.rb, line 63
def fragment_upload_html
  fragment_label_html(:upload) <<
  builder.file_field(method, input_html_options) <<
  builder.hidden_field("retained_#{method}")
end
fragment_url_html() click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# File lib/formtastic/inputs/dragonfly_input.rb, line 22
def fragments_wrapping(&block)
  template.content_tag(:fieldset,
    template.capture(&block).html_safe,
    fragments_wrapping_html_options
  )
end
fragments_wrapping_html_options() click to toggle source
# File lib/formtastic/inputs/dragonfly_input.rb, line 29
def fragments_wrapping_html_options
  { :class => "fragments" }
end
is_image?(file) click to toggle source
# 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() click to toggle source
# File lib/formtastic/inputs/dragonfly_input.rb, line 6
def to_html
  components = input_html_options[: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