Module: DynamicImage::Helper
- Defined in:
- lib/dynamic_image/helper.rb,
lib/dynamic_image/helper/formats.rb,
lib/dynamic_image/helper/pictures.rb
Overview
DynamicImage Helper
Helper methods for rendering and linking to images.
Every URL is signed with an HMAC digest of the action, the record id and the size, and the controller rejects anything that doesn't match. URLs can only be built server-side.
_path returns a relative path and _url an absolute one. _tag renders an image tag, and is available for
dynamic_image and uncropped_dynamic_image only. original and download point at the stored file, which is
never rendered.
Defined Under Namespace
Instance Method Summary collapse
-
#download_dynamic_image_path(record_or_array, options = {}) ⇒ String
Returns a path to the original uploaded file, served as an attachment so the browser downloads it.
-
#download_dynamic_image_url(record_or_array, options = {}) ⇒ String
Same as #download_dynamic_image_path, but returns an absolute URL.
-
#dynamic_image_path(record_or_array, options = {}) ⇒ String
Returns the path for a Model record.
-
#dynamic_image_tag(record_or_array, options = {}) ⇒ String
Returns an HTML image tag for the record, with
widthandheightset to the rendered size. -
#dynamic_image_url(record_or_array, options = {}) ⇒ String
Returns the URL for a Model record.
-
#original_dynamic_image_path(record_or_array, options = {}) ⇒ String
Returns a path to the original uploaded file, exactly as it was uploaded.
-
#original_dynamic_image_url(record_or_array, options = {}) ⇒ String
Same as #original_dynamic_image_path, but returns an absolute URL.
-
#uncropped_dynamic_image_path(record_or_array, options = {}) ⇒ String
Same as #dynamic_image_path, but points to an image with any pre-cropping disabled.
-
#uncropped_dynamic_image_tag(record_or_array, options = {}) ⇒ String
Same as #dynamic_image_tag, but renders an image with any pre-cropping disabled.
-
#uncropped_dynamic_image_url(record_or_array, options = {}) ⇒ String
Same as #dynamic_image_url, but points to an image with any pre-cropping disabled.
Methods included from Pictures
#dynamic_picture, #dynamic_picture_source_tag, #dynamic_picture_tag
Instance Method Details
#download_dynamic_image_path(record_or_array, options = {}) ⇒ String
Returns a path to the original uploaded file, served as an attachment so the browser downloads it. The file
is not processed, and sizing options are ignored. The URL carries the stored format's extension, and
:format has no effect.
111 112 113 |
# File 'lib/dynamic_image/helper.rb', line 111 def download_dynamic_image_path(record_or_array, = {}) dynamic_image_path(record_or_array, { action: :download }.merge()) end |
#download_dynamic_image_url(record_or_array, options = {}) ⇒ String
Same as #download_dynamic_image_path, but returns an absolute URL.
120 121 122 |
# File 'lib/dynamic_image/helper.rb', line 120 def download_dynamic_image_url(record_or_array, = {}) dynamic_image_url(record_or_array, { action: :download }.merge()) end |
#dynamic_image_path(record_or_array, options = {}) ⇒ String
Returns the path for a Model record. Takes the same options as #dynamic_image_url.
30 31 32 |
# File 'lib/dynamic_image/helper.rb', line 30 def dynamic_image_path(record_or_array, = {}) dynamic_image_url(record_or_array, { routing_type: :path }.merge()) end |
#dynamic_image_tag(record_or_array, options = {}) ⇒ String
Returns an HTML image tag for the record, with width and height set to the rendered size. Without a
size, it renders at the original size.
See #dynamic_image_url for sizing and cropping. Options supported by polymorphic_url are passed to the
router, and any others are added as HTML attributes.
Unless an alt option is given, the alt text is resolved from Model#alt_text.
Pass alt: "" to mark an image as decorative.
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/dynamic_image/helper.rb', line 55 def dynamic_image_tag(record_or_array, = {}) record = extract_dynamic_image_record(record_or_array) requested = [:size] size = fit_size!(record_or_array, ) = .extract!(*) = { size: display_size(size, requested), alt: record.alt_text } .merge() image_tag(dynamic_image_path_with_size(record_or_array, size, ), ) end |
#dynamic_image_url(record_or_array, options = {}) ⇒ String
Returns the URL for a Model record.
Any options supported by polymorphic_url are also accepted.
99 100 101 102 |
# File 'lib/dynamic_image/helper.rb', line 99 def dynamic_image_url(record_or_array, = {}) size = fit_size!(record_or_array, ) dynamic_image_url_with_size(record_or_array, size, ) end |
#original_dynamic_image_path(record_or_array, options = {}) ⇒ String
Returns a path to the original uploaded file, exactly as it was uploaded. The file is not processed, and
sizing options are ignored. The URL carries the stored format's extension, and :format has no effect.
130 131 132 |
# File 'lib/dynamic_image/helper.rb', line 130 def original_dynamic_image_path(record_or_array, = {}) dynamic_image_path(record_or_array, { action: :original }.merge()) end |
#original_dynamic_image_url(record_or_array, options = {}) ⇒ String
Same as #original_dynamic_image_path, but returns an absolute URL.
139 140 141 |
# File 'lib/dynamic_image/helper.rb', line 139 def original_dynamic_image_url(record_or_array, = {}) dynamic_image_url(record_or_array, { action: :original }.merge()) end |
#uncropped_dynamic_image_path(record_or_array, options = {}) ⇒ String
Same as #dynamic_image_path, but points to an image with any pre-cropping disabled.
148 149 150 |
# File 'lib/dynamic_image/helper.rb', line 148 def uncropped_dynamic_image_path(record_or_array, = {}) dynamic_image_path(record_or_array, { action: :uncropped }.merge()) end |
#uncropped_dynamic_image_tag(record_or_array, options = {}) ⇒ String
Same as #dynamic_image_tag, but renders an image with any pre-cropping disabled.
157 158 159 |
# File 'lib/dynamic_image/helper.rb', line 157 def uncropped_dynamic_image_tag(record_or_array, = {}) dynamic_image_tag(record_or_array, { action: :uncropped }.merge()) end |
#uncropped_dynamic_image_url(record_or_array, options = {}) ⇒ String
Same as #dynamic_image_url, but points to an image with any pre-cropping disabled.
166 167 168 |
# File 'lib/dynamic_image/helper.rb', line 166 def uncropped_dynamic_image_url(record_or_array, = {}) dynamic_image_url(record_or_array, { action: :uncropped }.merge()) end |