module PaperCropper::FormHelpers

Public Instance Methods

tws_cropper_box(attachment_name) click to toggle source

Create a new cropper box with all buttons and classe. This will be use the twitter bootstrap classes @param attachment_name [Symbol] Name of the attachment to crop

# File lib/paper_cropper/helpers.rb, line 7
def tws_cropper_box attachment_name
  obj = self.object
  form_helper = self
  aspect_ratio = obj.send "#{attachment_name}_aspect"

  out = "<div class='crop-image-container' data-crop-image-range='#{aspect_ratio}'>"

  out << form_helper.hidden_field(:"#{attachment_name}_crop_x", class: 'crop-image-value-x')
  out << form_helper.hidden_field(:"#{attachment_name}_crop_y", class: 'crop-image-value-y')
  out << form_helper.hidden_field(:"#{attachment_name}_crop_width", class: 'crop-image-value-width')
  out << form_helper.hidden_field(:"#{attachment_name}_crop_height", class: 'crop-image-value-height')
  out << form_helper.hidden_field(:"#{attachment_name}_crop_ratio", class: 'crop-image-value-ratio')

  out << form_helper.file_field(attachment_name, class: 'crop-image-file-input', label_col: "col-sm-3", control_col: "col-sm-9")

  out << '<hr>'

  image_src = obj.send("#{attachment_name}?") ? obj.send(attachment_name).url : ''
  out << '<div class="crop-image-wrapper">'
  out << "<img class='crop-image' class='crop-image' src='#{image_src}'>"
  out << '</div>'

  out << '<hr>'

  out << '<div class="btn-group pull-left" role="group">'
  out << "<button type='button' class='crop-image-btn-zoom-in btn btn-default'>&#43;</button>"
  out << "<button type='button' class='crop-image-btn-zoom-out btn btn-default'>&#45;</button>"
  out << '</div>'

  out << '<div class="btn-group pull-right" role="group">'
  out << "<button type='button' class='crop-image-btn-move-left btn btn-default'>left</button>"
  out << "<button type='button' class='crop-image-btn-move-right btn btn-default'>right</button>"
  out << "<button type='button' class='crop-image-btn-move-up btn btn-default'>up</button>"
  out << "<button type='button' class='crop-image-btn-move-down btn btn-default'>down</button>"
  out << '</div>'

  out << '</div>'

  out.html_safe
end