Module: Iron::ImageHelper
- Defined in:
- app/helpers/iron/image_helper.rb
Constant Summary collapse
- IMAGE_BREAKPOINTS =
[ 150, 320, 640, 1024, 1920 ].freeze
Instance Method Summary collapse
- #iron_image_tag(attachment, sizes: "100vw", loading: "lazy", blur: true, **options) ⇒ Object
- #iron_picture_tag(attachment, sizes: "100vw", loading: "lazy", blur: true, **options) ⇒ Object
Instance Method Details
#iron_image_tag(attachment, sizes: "100vw", loading: "lazy", blur: true, **options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/helpers/iron/image_helper.rb', line 5 def iron_image_tag(, sizes: "100vw", loading: "lazy", blur: true, **) return "" unless &.attached? return image_tag(, **) unless .blob.variable? = .merge( srcset: generate_srcset(), sizes:, loading:, width: .blob.["width"], height: .blob.["height"] ).compact if blur && .blob.["blur_data_uri"].present? blur_style = "background-image: url('#{.blob.["blur_data_uri"]}'); background-size: cover; background-position: center;" [:style] = "#{blur_style} #{[:style]}".strip end image_tag .variant(resize_to_limit: [ IMAGE_BREAKPOINTS.third, nil ]), ** end |
#iron_picture_tag(attachment, sizes: "100vw", loading: "lazy", blur: true, **options) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'app/helpers/iron/image_helper.rb', line 25 def iron_picture_tag(, sizes: "100vw", loading: "lazy", blur: true, **) return "" unless &.attached? return image_tag(, **) unless .blob.variable? content_tag :picture do concat source_tag(, :avif, sizes) concat source_tag(, :webp, sizes) concat iron_image_tag(, sizes: sizes, loading: loading, blur: blur, **) end end |