Module: Filepicker::Padrino::Helpers

Defined in:
lib/filepicker/padrino/helpers.rb

Instance Method Summary collapse

Instance Method Details

#filepicker_fields_for(record, instance_or_collection = nil, &block) ⇒ Object



11
12
13
# File 'lib/filepicker/padrino/helpers.rb', line 11

def filepicker_fields_for(record, instance_or_collection = nil, &block)
  fields_for(record, instance_or_collection, &block)
end

#filepicker_form_for(record, path, options = {}, &block) ⇒ Object



4
5
6
7
8
9
# File 'lib/filepicker/padrino/helpers.rb', line 4

def filepicker_form_for(record, path, options = {}, &block)
  options[:builder] = ::Filepicker::Padrino::FormBuilder
  form_for(record, path, options) do |f|
    capture(f, &block)
  end
end

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

Allows options to be passed to filepicker_image_url and then falls back to normal Padrino options for image_tag



35
36
37
# File 'lib/filepicker/padrino/helpers.rb', line 35

def filepicker_image_tag(url, options={})
  image_tag(filepicker_image_url(url, options), options)
end

#filepicker_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".

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


76
77
78
79
80
# File 'lib/filepicker/padrino/helpers.rb', line 76

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

#filepicker_js_include_tagObject



15
16
17
# File 'lib/filepicker/padrino/helpers.rb', line 15

def filepicker_js_include_tag
  javascript_include_tag "//api.filepicker.io/v0/filepicker.js"
end

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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/filepicker/padrino/helpers.rb', line 19

def filepicker_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']                   = settings.filepicker_padrino_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