Sha256: 9a63639ac58660cd2df63c30ab5235ae8f4751f5f87a22ff0ce3f6feebe2448e

Contents?: true

Size: 1.5 KB

Versions: 17

Compression:

Stored size: 1.5 KB

Contents

module ApplicationHelper
    module Amp::Components::AnimTagHelper

        def amp_anim(source, options = {}, &block)
            options = options.symbolize_keys

            source = options[:src] = path_to_image(source, skip_pipeline: options.delete(:skip_pipeline))

            options[:width], options[:height] = extract_dimensions(options.delete(:size)) if options[:size]
            warn "WARNING (AMP): specify width and height of amp-anim tags." unless options[:width] && options[:height]

            options[:layout] = "responsive" unless options[:layout] != "responsive"

            if block_given?
                content_tag("amp-anim", capture(&block), options)
            else
                if options[:placeholder]
                    placeholder = options[:placeholder]
                    options.delete(:placeholder)
                    content_tag("amp-anim", options) do
                        placeholder = options[:src] = path_to_image(source, skip_pipeline: options.delete(:skip_pipeline))
                        amp_placeholder("amp-img", options)
                    end
                else
                    content_tag("amp-anim", options)
                end
            end
        end

        private

        def extract_dimensions(size)
            size = size.to_s
            if /\A\d+x\d+\z/.match?(size)
                size.split("x")
            elsif /\A\d+\z/.match?(size)
                [size, size]
            end
        end

    end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
amp-html-1.2.1 lib/generators/templates/components/helpers/anim_tag_helper.rb
amp-html-1.2.0 lib/generators/templates/components/helpers/anim_tag_helper.rb
amp-html-1.1.0 lib/generators/templates/components/helpers/anim_tag_helper.rb
amp-html-1.0.1 lib/generators/templates/components/helpers/anim_tag_helper.rb
amp-html-1.0.0 lib/generators/templates/components/helpers/anim_tag_helper.rb
amp-html-0.7.18 lib/generators/templates/components/helpers/anim_tag_helper.rb
amp-html-0.7.17 lib/generators/templates/components/helpers/anim_tag_helper.rb
amp-html-0.7.16 lib/generators/templates/components/helpers/anim_tag_helper.rb
amp-html-0.7.15 lib/generators/templates/components/helpers/anim_tag_helper.rb
amp-html-0.7.14 lib/generators/templates/components/helpers/anim_tag_helper.rb
amp-html-0.7.13 lib/generators/templates/components/helpers/anim_tag_helper.rb
amp-html-0.7.12 lib/generators/templates/components/helpers/anim_tag_helper.rb
amp-html-0.7.11 lib/generators/templates/components/helpers/anim_tag_helper.rb
amp-html-0.7.10 lib/generators/templates/components/helpers/anim_tag_helper.rb
amp-html-0.7.9 lib/generators/templates/components/helpers/anim_tag_helper.rb
amp-html-0.7.8 lib/generators/templates/components/helpers/anim_tag_helper.rb
amp-html-0.7.7 lib/generators/templates/components/helpers/anim_tag_helper.rb