Class: PictureTag::Srcsets::Width

Inherits:
Object
  • Object
show all
Includes:
Basics
Defined in:
lib/jekyll-4-picture-tag/srcsets/width.rb

Overview

Creates a srcset in the “(filename) (width)w, (…)” format. Example: “img.jpg 400w, img2.jpg 600w, img3.jpg 800w”

Instance Attribute Summary

Attributes included from Basics

#media, #source_image

Instance Method Summary collapse

Methods included from Basics

#check_widths, #initialize, #media_attribute, #mime_type, #to_s

Instance Method Details

#sizesObject

Sizes html attribute. Since it’s intimately related to srcset, we generate it at the same time.



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/jekyll-4-picture-tag/srcsets/width.rb', line 14

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

#to_aObject



8
9
10
# File 'lib/jekyll-4-picture-tag/srcsets/width.rb', line 8

def to_a
  widths.collect { |w| build_srcset_entry(w) }
end