Class: SrcsetImages::SrcsetConfig
- Inherits:
-
Object
- Object
- SrcsetImages::SrcsetConfig
- Defined in:
- lib/middleman-srcset_images/srcset_config.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #applies_to?(img) ⇒ Boolean
- #image_versions(img) ⇒ Object
-
#initialize(name, config, cache_dir:) ⇒ SrcsetConfig
constructor
A new instance of SrcsetConfig.
Constructor Details
#initialize(name, config, cache_dir:) ⇒ SrcsetConfig
Returns a new instance of SrcsetConfig.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/middleman-srcset_images/srcset_config.rb', line 8 def initialize(name, config, cache_dir:) @name = name @config = config @base_config = { name: name, crop: config.fetch(:crop, false), quality: config.fetch(:quality, 80), cache_dir: cache_dir } end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/middleman-srcset_images/srcset_config.rb', line 6 def config @config end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/middleman-srcset_images/srcset_config.rb', line 6 def name @name end |
Instance Method Details
#applies_to?(img) ⇒ Boolean
38 39 40 41 |
# File 'lib/middleman-srcset_images/srcset_config.rb', line 38 def applies_to?(img) not ((name == 'landscape' && img.portrait?) or (name == 'portrait' && img.landscape?)) end |
#image_versions(img) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/middleman-srcset_images/srcset_config.rb', line 20 def image_versions(img) result = [] if applies_to?(img) config.srcset.each_with_index do |config, idx| result << ImageVersion.new( img, img.path_for_version(name, idx), @base_config.merge(config.symbolize_keys) ) end end result end |