Module: RetinaImage

Defined in:
lib/retina_image.rb,
lib/retina_image/version.rb

Constant Summary collapse

VERSION =
'0.1.0'

Instance Method Summary collapse

Instance Method Details

#retina_tag(source, options = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/retina_image.rb', line 2

def retina_tag(source, options = {})
  options.reverse_merge!(include_srcsets: true)

  # if options[:include_srcsets] != true
  # need to cast to bool incase truthy/falsey strings are passed
  return image_tag unless options.delete(:include_srcsets).to_bool

  srcset = srcset_from_source(source)
  options[:srcset] = srcset.keys.map { |k| "#{srcset[k]} #{k}" }.join(', ')
  options.reverse_merge!(alt: alt(source))
  image_tag(srcset["1x"], options)
end