Module: PagesCore::ImagesHelper
- Includes:
- DynamicImage::Helper
- Included in:
- ApplicationHelper, ImageEmbedder
- Defined in:
- app/helpers/pages_core/images_helper.rb
Instance Method Summary collapse
- #dynamic_image_tag(record_or_array, options = {}) ⇒ Object
- #image_caption(image, caption: nil) ⇒ Object
-
#image_figure(image, opts = {}) ⇒ Object
Renders an image figure tag with caption.
- #original_dynamic_image_tag(record_or_array, options = {}) ⇒ Object
-
#picture(image, opts = {}) ⇒ Object
Renders an image figure tag with caption.
- #picture_tag(image, ratio: nil, sizes: "100vw") ⇒ Object
- #uncropped_dynamic_image_tag(record_or_array, options = {}) ⇒ Object
Instance Method Details
#dynamic_image_tag(record_or_array, options = {}) ⇒ Object
7 8 9 10 |
# File 'app/helpers/pages_core/images_helper.rb', line 7 def dynamic_image_tag(record_or_array, = {}) super(record_or_array, extract_alt_text(record_or_array).merge()) end |
#image_caption(image, caption: nil) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'app/helpers/pages_core/images_helper.rb', line 12 def (image, caption: nil) return if == false = image. unless .is_a?(String) return if .blank? tag.() end |
#image_figure(image, opts = {}) ⇒ Object
Renders an image figure tag with caption.
Options
-
:caption
: Override caption with a string, or set to false to disable captions. -
:class_name
: Class name to add to figure tag. -
:link
: Link target for image. -
:ratio
: Ratio to constrain image by. -
:size
: Max size for image.
30 31 32 33 34 35 36 37 38 39 |
# File 'app/helpers/pages_core/images_helper.rb', line 30 def image_figure(image, opts = {}) class_name = ["image", image_class_name(image, ratio: opts[:ratio]), opts[:class_name]].compact image_tag = image_figure_image_tag(image, size: opts[:size], ratio: opts[:ratio]) content = opts[:link] ? image_link_to(image_tag, opts[:link]) : image_tag tag.figure(content + (image, caption: opts[:caption]), class: class_name) end |
#original_dynamic_image_tag(record_or_array, options = {}) ⇒ Object
72 73 74 75 |
# File 'app/helpers/pages_core/images_helper.rb', line 72 def original_dynamic_image_tag(record_or_array, = {}) super(record_or_array, extract_alt_text(record_or_array).merge()) end |
#picture(image, opts = {}) ⇒ Object
Renders an image figure tag with caption.
Options
-
:caption
: Override caption with a string, or set to false to disable captions. -
:class_name
: Class name to add to figure tag. -
:link
: Link target for image. -
:ratio
: Ratio to constrain image by. -
:sizes
: Sizes attribute for image tag, default: “100vw”.
50 51 52 53 54 55 56 57 |
# File 'app/helpers/pages_core/images_helper.rb', line 50 def picture(image, opts = {}) class_name = ["image", image_class_name(image, ratio: opts[:ratio]), opts[:class_name]].compact pict = picture_tag(image, ratio: opts[:ratio], sizes: opts[:sizes]) content = opts[:link] ? image_link_to(pict, opts[:link]) : pict tag.figure(content + (image, caption: opts[:caption]), class: class_name) end |
#picture_tag(image, ratio: nil, sizes: "100vw") ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/helpers/pages_core/images_helper.rb', line 59 def picture_tag(image, ratio: nil, sizes: "100vw") tag.picture do safe_join( [webp_source(image, ratio:, sizes: sizes || "100vw"), dynamic_image_tag(image, size: image_size(1050, ratio), crop: (ratio ? true : false), sizes:, srcset: srcset(image, ratio:))] ) end end |
#uncropped_dynamic_image_tag(record_or_array, options = {}) ⇒ Object
77 78 79 80 |
# File 'app/helpers/pages_core/images_helper.rb', line 77 def uncropped_dynamic_image_tag(record_or_array, = {}) super(record_or_array, extract_alt_text(record_or_array).merge()) end |