class HasFilepickerImage::View

Public Class Methods

new(object_name, attribute_name, template, options = {}) click to toggle source
# File lib/has_filepicker_image/view.rb, line 3
def initialize(object_name, attribute_name, template, options = {})
  @object_name = object_name
  @attribute_name = attribute_name
  @template = template
  @options = options
end

Public Instance Methods

render() click to toggle source
# File lib/has_filepicker_image/view.rb, line 10
def render
  buttons + preview + hidden_field
end

Private Instance Methods

buttons() click to toggle source
# File lib/has_filepicker_image/view.rb, line 16
def buttons
  @template.content_tag(
    :div,
    pick_button + remove_button,
    :class => 'filepicker-button'
  )
end
hidden_field() click to toggle source
# File lib/has_filepicker_image/view.rb, line 35
def hidden_field
  if Rails::VERSION::MAJOR >= 4
    ActionView::Helpers::Tags::HiddenField.new(
      @object_name,
      @attribute_name,
      @template,
      :object => object
    ).render
  else
    ActionView::Helpers::InstanceTag.new(
      @object_name,
      @attribute_name,
      @template,
      object
    ).to_input_field_tag('hidden')
  end
end
html_options() click to toggle source
# File lib/has_filepicker_image/view.rb, line 81
def html_options
  @options[:html_options] || {}
end
object() click to toggle source
# File lib/has_filepicker_image/view.rb, line 77
def object
  @options[:object]
end
pick_button() click to toggle source
# File lib/has_filepicker_image/view.rb, line 53
def pick_button
  @template.content_tag(:a,
    @options[:pick_button_html],
    html_options.merge(
      :href  => '#',
      :style => value.present? ? 'display:none;' : '',
      :'data-action' => 'pickImage'
    )
  )
end
preview() click to toggle source
# File lib/has_filepicker_image/view.rb, line 24
def preview
  @template.content_tag(:div, :class => 'filepicker-image', :style => (value.present? ? '' : 'display:none;')) do
    if value.present?
      # Render preview + Delete link
      thumb_url = value + "/convert?w=260&h=180"
      thumb_alt = "#{@attribute_name} thumbnail"
      @template.image_tag(thumb_url, alt: thumb_alt )
    end
  end
end
remove_button() click to toggle source
# File lib/has_filepicker_image/view.rb, line 64
def remove_button
  @template.link_to(
    @options[:delete_button_html],
    '#',
    :style => value.present? ? '' : 'display:none;',
    :'data-action' => 'removeImage'
  )
end
value() click to toggle source
# File lib/has_filepicker_image/view.rb, line 73
def value
  object.send(@attribute_name)
end