Module: Filepicker::Padrino::Helpers
- Defined in:
- lib/filepicker/padrino/helpers.rb
Instance Method Summary collapse
- #filepicker_fields_for(record, instance_or_collection = nil, &block) ⇒ Object
- #filepicker_form_for(record, path, options = {}, &block) ⇒ Object
-
#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.
-
#filepicker_image_url(url, options = {}) ⇒ Object
w - Resize the image to this width.
- #filepicker_js_include_tag ⇒ Object
- #filepicker_save_button(text, url, mimetype, options = {}) ⇒ Object
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, = {}, &block) [:builder] = ::Filepicker::Padrino::FormBuilder form_for(record, path, ) 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, ={}) image_tag(filepicker_image_url(url, ), ) 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 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, = {}) query_params = .slice(:w, :h, :fit, :crop, :format, :quality, :watermark, :watersize, :waterposition).to_query [url, "/convert?", query_params].join end |
#filepicker_js_include_tag ⇒ Object
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 (text, url, mimetype, = {}) [:data] ||= {} container = .delete(:container) services = .delete(:services) save_as = .delete(:save_as_name) [:data]['fp-url'] = url [:data]['fp-apikey'] = settings.filepicker_padrino_api_key [:data]['fp-mimetype'] = mimetype [:data]['fp-option-container'] = container if container [:data]['fp-option-services'] = Array(services).join(",") if services [:data]['fp-option-defaultSaveasName'] = save_as if save_as (text, ) end |