Module: PaperCropper::FormHelpers

Defined in:
lib/paper_cropper/helpers.rb

Instance Method Summary collapse

Instance Method Details

#tws_cropper_box(attachment_name) ⇒ Object

Create a new cropper box with all buttons and classe. This will be use the twitter bootstrap classes

Parameters:

  • attachment_name (Symbol)

    Name of the attachment to crop



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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