Module: PictureHelper

Defined in:
lib/carrierwave-picture/picture_helper.rb

Instance Method Summary collapse

Instance Method Details

#picture_tag(path, options = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/carrierwave-picture/picture_helper.rb', line 2

def picture_tag(path, options = {})

  (:picture, options) do
    concat   :source,
                        nil,
                        srcset: "#{path}.webp",
                        type: "image/webp",
                        style: "height: inherit; width: inherit" if File.exist?(Rails.root.join("public/#{path}.webp"))
    concat   :source,
                        nil,
                        srcset: "#{path}.jp2",
                        type: "image/jp2",
                        style: "height: inherit; width: inherit" if File.exist?(Rails.root.join("public/#{path}.jp2"))
    concat image_tag path, style: "height: inherit; width: inherit"
  end

end