Class: PictureTag::Srcsets::Basic
- Inherits:
-
Object
- Object
- PictureTag::Srcsets::Basic
- Defined in:
- lib/jekyll_picture_tag/srcsets/basic.rb
Overview
Basic functionality for a srcset, which also handles file generation. Classes including this module must implement the to_a method, which accomplishes the following:
-
Return an array of srcset entries.
-
Call generate_file for each entry, giving it the desired width in pixels.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#media ⇒ Object
readonly
Returns the value of attribute media.
-
#source_image ⇒ Object
readonly
Returns the value of attribute source_image.
Instance Method Summary collapse
-
#files ⇒ Object
GeneratedImage class.
- #format ⇒ Object
- #height_attribute ⇒ Object
-
#initialize(source_image, input_format) ⇒ Basic
constructor
A new instance of Basic.
-
#media_attribute ⇒ Object
Generates an HTML attribute.
-
#mime_type ⇒ Object
Allows us to add a type attribute to whichever element contains this srcset.
-
#sizes ⇒ Object
Some srcsets have them, for those that don’t return nil.
- #to_a ⇒ Object
- #to_s ⇒ Object
- #width_attribute ⇒ Object
Constructor Details
#initialize(source_image, input_format) ⇒ Basic
14 15 16 17 18 |
# File 'lib/jekyll_picture_tag/srcsets/basic.rb', line 14 def initialize(source_image, input_format) @source_image = source_image @input_format = input_format @media = source_image.media_preset end |
Instance Attribute Details
#media ⇒ Object (readonly)
Returns the value of attribute media.
12 13 14 |
# File 'lib/jekyll_picture_tag/srcsets/basic.rb', line 12 def media @media end |
#source_image ⇒ Object (readonly)
Returns the value of attribute source_image.
12 13 14 |
# File 'lib/jekyll_picture_tag/srcsets/basic.rb', line 12 def source_image @source_image end |
Instance Method Details
#files ⇒ Object
GeneratedImage class
27 28 29 |
# File 'lib/jekyll_picture_tag/srcsets/basic.rb', line 27 def files @files ||= build_files end |
#format ⇒ Object
20 21 22 23 24 |
# File 'lib/jekyll_picture_tag/srcsets/basic.rb', line 20 def format # Input format might be 'original', which is handled by the generated # image. @format ||= files.first.format end |
#height_attribute ⇒ Object
59 60 61 |
# File 'lib/jekyll_picture_tag/srcsets/basic.rb', line 59 def height_attribute files.first.source_height.to_s end |
#media_attribute ⇒ Object
Generates an HTML attribute
51 52 53 |
# File 'lib/jekyll_picture_tag/srcsets/basic.rb', line 51 def media_attribute "(#{PictureTag.media_presets[@media]})" end |
#mime_type ⇒ Object
Allows us to add a type attribute to whichever element contains this srcset.
41 42 43 |
# File 'lib/jekyll_picture_tag/srcsets/basic.rb', line 41 def mime_type MIME::Types.type_for(format).first.to_s end |
#sizes ⇒ Object
Some srcsets have them, for those that don’t return nil.
46 47 48 |
# File 'lib/jekyll_picture_tag/srcsets/basic.rb', line 46 def sizes nil end |
#to_a ⇒ Object
31 32 33 |
# File 'lib/jekyll_picture_tag/srcsets/basic.rb', line 31 def to_a files.collect { |f| build_srcset_entry(f) } end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/jekyll_picture_tag/srcsets/basic.rb', line 35 def to_s to_a.join(', ') end |
#width_attribute ⇒ Object
55 56 57 |
# File 'lib/jekyll_picture_tag/srcsets/basic.rb', line 55 def width_attribute files.first.source_width.to_s end |