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.
108 109 110 |
# File 'lib/dynamic_image/helper.rb', line 108 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.
117 118 119 |
# File 'lib/dynamic_image/helper.rb', line 117 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 |
# File 'lib/dynamic_image/helper.rb', line 55 def dynamic_image_tag(record_or_array, = {}) record = extract_dynamic_image_record(record_or_array) size = fit_size!(record_or_array, ) = .extract!(*) = { size:, 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.
96 97 98 99 |
# File 'lib/dynamic_image/helper.rb', line 96 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.
127 128 129 |
# File 'lib/dynamic_image/helper.rb', line 127 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.
136 137 138 |
# File 'lib/dynamic_image/helper.rb', line 136 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.
145 146 147 |
# File 'lib/dynamic_image/helper.rb', line 145 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.
154 155 156 |
# File 'lib/dynamic_image/helper.rb', line 154 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.
163 164 165 |
# File 'lib/dynamic_image/helper.rb', line 163 def uncropped_dynamic_image_url(record_or_array, = {}) dynamic_image_url(record_or_array, { action: :uncropped }.merge()) end |