Sha256: edd95b5f548e05daa5535c503b8a0e6c72fa7abeb74d02a4d1f308a6066c3e3e

Contents?: true

Size: 946 Bytes

Versions: 17

Compression:

Stored size: 946 Bytes

Contents

module PictureTag
  module Srcsets
    # Creates a srcset in the "(filename) (width)w, (...)" format.
    # Example: "img.jpg 400w, img2.jpg 600w, img3.jpg 800w"
    class Width < Basic
      # Sizes html attribute. Since it's intimately related to srcset, we
      # generate it at the same time.
      def sizes
        preset_sizes = PictureTag.preset['sizes'] || {}
        preset_size = PictureTag.preset['size']
        size_set = []

        preset_sizes.each_pair do |media, size|
          size_set << build_size_entry(media, size)
        end

        size_set << preset_size if preset_size

        size_set.any? ? size_set.join(', ') : nil
      end

      private

      def widths
        PictureTag.widths(@media)
      end

      def build_srcset_entry(file)
        "#{file.uri} #{file.width}w"
      end

      def build_size_entry(media, size)
        "(#{PictureTag.media_presets[media]}) #{size}"
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

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