Sha256: 402b650161952562f9b123a10666405e700c06843ac36ef6d78d3dd37bd84b6b

Contents?: true

Size: 1.23 KB

Versions: 18

Compression:

Stored size: 1.23 KB

Contents

module PictureTag
  module OutputFormats
    # This is not an output format, it's a module for use in others. It allows
    # us to create JavaScript Library friendly markup, for things like LazyLoad
    module DataAttributes
      def base_markup
        build_noscript(super)
      end

      private

      def add_src(element, uri)
        element.attributes << { 'data-src' => uri }
      end

      def add_srcset(element, srcset)
        element.attributes << { 'data-srcset' => srcset.to_s }
      end

      def add_sizes(element, srcset)
        return unless srcset.sizes

        attribute = PictureTag.preset['data_sizes'] ? 'data-sizes' : 'sizes'
        element.attributes << { attribute => srcset.sizes }
      end

      def build_noscript(base_content)
        return base_content unless PictureTag.preset['noscript']

        noscript = DoubleTag.new(
          'noscript',
          content: Img.new.build_base_img,

          # Markdown fix requires removal of line breaks:
          oneline: PictureTag.nomarkdown?
        ).to_s

        ShelfTag.new(
          content: [base_content, noscript],

          # Markdown fix requires removal of line breaks:
          oneline: PictureTag.nomarkdown?
        )
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
jekyll_picture_tag-2.1.2 lib/jekyll_picture_tag/output_formats/data_attributes.rb
jekyll_picture_tag-2.1.1 lib/jekyll_picture_tag/output_formats/data_attributes.rb
jekyll_picture_tag-2.1.0 lib/jekyll_picture_tag/output_formats/data_attributes.rb
jekyll_picture_tag-2.0.4 lib/jekyll_picture_tag/output_formats/data_attributes.rb
jekyll_picture_tag-2.0.3 lib/jekyll_picture_tag/output_formats/data_attributes.rb
jekyll_picture_tag-2.0.2 lib/jekyll_picture_tag/output_formats/data_attributes.rb
jekyll_picture_tag-2.0.1 lib/jekyll_picture_tag/output_formats/data_attributes.rb
jekyll_picture_tag-2.0.0 lib/jekyll_picture_tag/output_formats/data_attributes.rb
jekyll_picture_tag-2.0.0pre1 lib/jekyll_picture_tag/output_formats/data_attributes.rb
jekyll_picture_tag-1.14.0 lib/jekyll_picture_tag/output_formats/data_attributes.rb
jekyll_picture_tag-1.13.0 lib/jekyll_picture_tag/output_formats/data_attributes.rb
jekyll_picture_tag-1.12.0 lib/jekyll_picture_tag/output_formats/data_attributes.rb
jekyll_picture_tag-1.11.0 lib/jekyll_picture_tag/output_formats/data_attributes.rb
jekyll_picture_tag-1.10.2 lib/jekyll_picture_tag/output_formats/data_attributes.rb
jekyll_picture_tag-1.10.1 lib/jekyll_picture_tag/output_formats/data_attributes.rb
jekyll_picture_tag-1.10.0 lib/jekyll_picture_tag/output_formats/data_attributes.rb
jekyll_picture_tag-1.9.0 lib/jekyll_picture_tag/output_formats/data_attributes.rb
jekyll_picture_tag-1.8.0 lib/jekyll_picture_tag/output_formats/data_attributes.rb