Module: Picturesque::ApplicationHelper

Defined in:
app/helpers/picturesque/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#picturesque_image_tag(image, size:, slug:, alt:, scales: (1..3)) ⇒ Object



4
5
6
7
8
9
10
11
# File 'app/helpers/picturesque/application_helper.rb', line 4

def picturesque_image_tag(image, size:, slug:, alt:, scales: (1..3))
  matches = size.match(/(?<w>\d+)\D(?<h>\d+)/)
  w , h = Integer(matches[:w]) , Integer(matches[:h])

  image_tag picturesque.image_url(image, size: "#{w}x#{h}", slug: image.slug),
    srcset: scales.map { |s| "#{picturesque.image_url(image, size: "#{w * s}x#{h * s}", slug: slug)} #{s}x" }.join(','),
    size: "#{w}×#{h}", alt: alt
end