Module: ActionView::Helpers::InstanceTagMethods

Defined in:
lib/simple_crop/action_view_extensions/instance_tag.rb

Instance Method Summary collapse

Instance Method Details

#crop_ratio(paperclip, select_style) ⇒ Object



16
17
18
19
20
# File 'lib/simple_crop/action_view_extensions/instance_tag.rb', line 16

def crop_ratio paperclip, select_style
  original_geometry = paperclip_geometry(paperclip, :original)
  select_geometry = paperclip_geometry(paperclip, select_style)
  "#{original_geometry.width.to_i.to_s}/#{select_geometry.width.to_i.to_s}"
end

#paperclip_geometry(paperclip, style) ⇒ Object



22
23
24
# File 'lib/simple_crop/action_view_extensions/instance_tag.rb', line 22

def paperclip_geometry(paperclip, style)
  Paperclip::Geometry.from_file paperclip.to_file(style)
end

#to_simple_crop_preview_tag(options) ⇒ Object



4
5
6
7
8
9
# File 'lib/simple_crop/action_view_extensions/instance_tag.rb', line 4

def to_simple_crop_preview_tag(options)
  paperclip = options["object"].send(@method_name)
  target_crop_geometry = paperclip_geometry(paperclip, options["crop"])
  div_style = "padding:0;overflow:hidden;width:#{target_crop_geometry.width.to_i.to_s}px;height:#{target_crop_geometry.height.to_i.to_s}px;"
  ("div", tag("img",{:src => paperclip.url(options["select"])}), {:class => "simple-crop-preview", :id => "#{sanitized_object_name}_simple_crop_preview", :style => div_style})
end

#to_simple_crop_tag(options) ⇒ Object



11
12
13
14
# File 'lib/simple_crop/action_view_extensions/instance_tag.rb', line 11

def to_simple_crop_tag(options)
  paperclip = options["object"].send(@method_name)
  tag("img",{:src => paperclip.url(options["select"]), :"data-crop-ratio" => crop_ratio(paperclip, options["select"]), :"data-crop-for" => sanitized_object_name})
end