Sha256: 3a7f8353b535daa6d28f7eb1ee7a8692e628d6f167f83f0773e39acf89f33a08

Contents?: true

Size: 658 Bytes

Versions: 17

Compression:

Stored size: 658 Bytes

Contents

module PictureTag
  module Srcsets
    # Creates a srcset in the "(filename) (pixel_ratio)x" format.
    # Example: "img.jpg 1x, img2.jpg 1.5x, img3.jpg 2x"
    class PixelRatio < Basic
      private

      def widths
        PictureTag.preset['pixel_ratios'].collect do |p|
          p * PictureTag.preset['base_width']
        end
      end

      def build_srcset_entry(file)
        # We have to recalculate the pixel ratio after verifying our source
        # image is large enough.
        pixel_ratio = (
          file.width.to_f / PictureTag.preset['base_width']
        ).round(2)

        "#{file.uri} #{pixel_ratio}x"
      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/pixel_ratio.rb
jekyll_picture_tag-2.1.1 lib/jekyll_picture_tag/srcsets/pixel_ratio.rb
jekyll_picture_tag-2.1.0 lib/jekyll_picture_tag/srcsets/pixel_ratio.rb
jekyll_picture_tag-2.0.4 lib/jekyll_picture_tag/srcsets/pixel_ratio.rb
jekyll_picture_tag-2.0.3 lib/jekyll_picture_tag/srcsets/pixel_ratio.rb
jekyll_picture_tag-2.0.2 lib/jekyll_picture_tag/srcsets/pixel_ratio.rb
jekyll_picture_tag-2.0.1 lib/jekyll_picture_tag/srcsets/pixel_ratio.rb
jekyll_picture_tag-2.0.0 lib/jekyll_picture_tag/srcsets/pixel_ratio.rb
jekyll_picture_tag-2.0.0pre1 lib/jekyll_picture_tag/srcsets/pixel_ratio.rb
jekyll_picture_tag-1.14.0 lib/jekyll_picture_tag/srcsets/pixel_ratio.rb
jekyll_picture_tag-1.13.0 lib/jekyll_picture_tag/srcsets/pixel_ratio.rb
jekyll_picture_tag-1.12.0 lib/jekyll_picture_tag/srcsets/pixel_ratio.rb
jekyll_picture_tag-1.11.0 lib/jekyll_picture_tag/srcsets/pixel_ratio.rb
jekyll_picture_tag-1.10.2 lib/jekyll_picture_tag/srcsets/pixel_ratio.rb
jekyll_picture_tag-1.10.1 lib/jekyll_picture_tag/srcsets/pixel_ratio.rb
jekyll_picture_tag-1.10.0 lib/jekyll_picture_tag/srcsets/pixel_ratio.rb
jekyll_picture_tag-1.9.0 lib/jekyll_picture_tag/srcsets/pixel_ratio.rb