Module: Inkfilepicker::ViewHelpers

Defined in:
lib/inkfilepicker/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#inkfilepicker_image_tag(url, image_options = {}, image_tag_options = {}) ⇒ Object

Allows options to be passed to inkfilepicker_image_url and then falls back to normal Rails options for image_tag If specifying html width, height, pass it down to inkfilepicker for optimization



25
26
27
# File 'lib/inkfilepicker/view_helpers.rb', line 25

def inkfilepicker_image_tag(url, image_options={}, image_tag_options={})
  image_tag(inkfilepicker_image_url(url, image_options), image_tag_options)
end

#inkfilepicker_image_url(url, options = {}) ⇒ Object

w - Resize the image to this width.

h - Resize the image to this height.

fit - Specifies how to resize the image. Possible values are:

clip: Resizes the image to fit within the specified parameters without
      distorting, cropping, or changing the aspect ratio
crop: Resizes the image to fit the specified parameters exactly by
      removing any parts of the image that don't fit within the boundaries
scales: Resizes the image to fit the specified parameters exactly by
        scaling the image to the desired size
Defaults to "clip".

align - Determines how the image is aligned when resizing and using the “fit” parameter. Check API for details.

cache - Specifies if the image should be cached or not.

crop - Crops the image to a specified rectangle. The input to this parameter

should be 4 numbers for 'x,y,width,height' - for example,
'crop=10,20,200,250' would select the 200x250 pixel rectangle starting
from 10 pixels from the left edge and 20 pixels from the top edge of the
image.

format - Specifies what format the image should be converted to, if any.

Possible values are "jpg" and "png". For "jpg" conversions, you
can additionally specify a quality parameter.

quality - For jpeg conversion, specifies the quality of the resultant image.

Quality should be an integer between 1 and 100

watermark - Adds the specified absolute url as a watermark on the image.

watersize - This size of the watermark, as a percentage of the base

image (not the original watermark).

waterposition - Where to put the watermark relative to the base image.

Possible values for vertical position are "top","middle",
"bottom" and "left","center","right", for horizontal
position. The two can be combined by separating vertical
and horizontal with a comma. The default behavior
is bottom,right


69
70
71
72
# File 'lib/inkfilepicker/view_helpers.rb', line 69

def inkfilepicker_image_url(url, options = {})
  query_params = options.slice(:w, :h, :fit, :align, :cache, :crop, :format, :quality, :watermark, :watersize, :waterposition).to_query
  [url, "/convert?", query_params].join
end

#inkfilepicker_js_include_tagObject



4
5
6
# File 'lib/inkfilepicker/view_helpers.rb', line 4

def inkfilepicker_js_include_tag
  javascript_include_tag "#{Inkfilepicker.api_url}"
end

#inkfilepicker_save_button(text, url, mimetype, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/inkfilepicker/view_helpers.rb', line 8

def inkfilepicker_save_button(text, url, mimetype, options = {})
  options[:data] ||= {}
  container = options.delete(:container)
  services = options.delete(:services)
  save_as = options.delete(:save_as_name)

  options[:data]['fp-url'] = url
  options[:data]['fp-apikey'] = Inkfilepicker.api_key
  options[:data]['fp-mimetype'] = mimetype
  options[:data]['fp-option-container'] = container if container
  options[:data]['fp-option-services'] = Array(services).join(",") if services
  options[:data]['fp-option-defaultSaveasName'] = save_as if save_as
  button_tag(text, options)
end