Class: PictureTag::OutputFormats::Picture
- Inherits:
-
Object
- Object
- PictureTag::OutputFormats::Picture
- Includes:
- Basics
- Defined in:
- lib/jekyll-4-picture-tag/output_formats/picture.rb
Overview
Represents a <picture> tag, enclosing at least 2 <source> tags and an <img> tag.
Direct Known Subclasses
Instance Method Summary collapse
Methods included from Basics
Instance Method Details
#base_markup ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/jekyll-4-picture-tag/output_formats/picture.rb', line 50 def base_markup picture = DoubleTag.new( 'picture', attributes: PictureTag.html_attributes['picture'], content: build_sources << build_base_img, # Markdown fix requires removal of line breaks: oneline: PictureTag.nomarkdown? ) picture.attributes << PictureTag.html_attributes['parent'] picture end |
#build_source(srcset) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/jekyll-4-picture-tag/output_formats/picture.rb', line 33 def build_source(srcset) source = SingleTag.new( 'source', attributes: PictureTag.html_attributes['source'] ) # Sizes will be the same for all sources. There's some redundant markup # here, but I don't think it's worth the effort to prevent. add_sizes(source, srcset) add_media(source, srcset) add_srcset(source, srcset) source.type = srcset.mime_type source end |
#build_sources ⇒ Object
29 30 31 |
# File 'lib/jekyll-4-picture-tag/output_formats/picture.rb', line 29 def build_sources srcsets.collect { |s| build_source(s) } end |
#srcsets ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/jekyll-4-picture-tag/output_formats/picture.rb', line 8 def srcsets sets = [] PictureTag.preset['formats'].each do |format| # We have 2 dimensions here: formats, and source images. Formats are # provided in the order they must be returned, source images are # provided in the reverse (least to most preferable) and must be # flipped. We'll use an intermediate value to accomplish this. format_set = [] # Source images are defined in the tag params, and associated with # media queries. The base (first provided) image has a key of nil. PictureTag.source_images.each_key do |media| format_set << build_srcset(media, format) end sets.concat format_set.reverse end sets end |