Sha256: 0f53166fa6f211b45beace54bf05816aa24e9dbe412ed042b706b9180ca0468f
Contents?: true
Size: 980 Bytes
Versions: 1
Compression:
Stored size: 980 Bytes
Contents
module AmpImageTagHelper def amp_image_tag(source, opts = {}) has_dimensions = (opts[:width] && opts[:height]) || opts[:size] set_dimensions(source, opts) if !has_dimensions set_scrset(source, opts) image_tag_to_amp(image_tag(source, opts)) end private def image_tag_to_amp(img_tag) img_tag.gsub(/^<img/, '<amp-img').gsub(/>$/, '></amp-img>').html_safe end def set_dimensions(source, opts) if source.kind_of?(CarrierWave::Uploader::Base) && !source.class.processors.empty? opts[:width], opts[:height] = source.class.processors[0][1] else opts[:width], opts[:height] = FastImage.size(source.to_s) end end def set_scrset(source, opts) if source.kind_of?(CarrierWave::Uploader::Base) && !source.class.processors.empty? && format_2x = opts.delete(:format_2x) name_2x = format_2x % source.version_name opts[:srcset] = "#{source.parent_version.send(name_2x).url} 2x" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
amp_helper-0.1.2 | lib/amp_helper/amp_image_tag_helper.rb |