Class: Middleman::WebP::Options
- Inherits:
-
Object
- Object
- Middleman::WebP::Options
- Defined in:
- lib/middleman-webp/options.rb
Instance Attribute Summary collapse
-
#allow_skip ⇒ Object
readonly
Returns the value of attribute allow_skip.
-
#append_extension ⇒ Object
readonly
Returns the value of attribute append_extension.
-
#ignore ⇒ Object
readonly
Returns the value of attribute ignore.
-
#run_before_build ⇒ Object
readonly
Returns the value of attribute run_before_build.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#for(file) ⇒ Object
Internal: Generate command line args for cwebp or gif2webp command.
-
#initialize(options = {}) ⇒ Options
constructor
A new instance of Options.
Constructor Details
#initialize(options = {}) ⇒ Options
Returns a new instance of Options.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/middleman-webp/options.rb', line 9 def initialize( = {}) @ignore = [:ignore] || [] @ignore = [*@ignore].map do |pattern| Middleman::WebP::PathnameMatcher.new(pattern) end @conversion = [:conversion_options] || {} @conversion = @conversion.reduce(Hash.new('')) do |h, (k, v)| h[Middleman::WebP::PathnameMatcher.new(k)] = to_args(v) h end @verbose = [:verbose] || false @append_extension = [:append_extension] || false @allow_skip = !(false == [:allow_skip]) @run_before_build = [:run_before_build] || false end |
Instance Attribute Details
#allow_skip ⇒ Object (readonly)
Returns the value of attribute allow_skip.
6 7 8 |
# File 'lib/middleman-webp/options.rb', line 6 def allow_skip @allow_skip end |
#append_extension ⇒ Object (readonly)
Returns the value of attribute append_extension.
6 7 8 |
# File 'lib/middleman-webp/options.rb', line 6 def append_extension @append_extension end |
#ignore ⇒ Object (readonly)
Returns the value of attribute ignore.
6 7 8 |
# File 'lib/middleman-webp/options.rb', line 6 def ignore @ignore end |
#run_before_build ⇒ Object (readonly)
Returns the value of attribute run_before_build.
6 7 8 |
# File 'lib/middleman-webp/options.rb', line 6 def run_before_build @run_before_build end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
6 7 8 |
# File 'lib/middleman-webp/options.rb', line 6 def verbose @verbose end |
Instance Method Details
#for(file) ⇒ Object
Internal: Generate command line args for cwebp or gif2webp command
Find options defined for given file. Selects all options whose glob pattern matches file path and uses the one with longest glob, because it’s assumed to be the most precise one.
33 34 35 36 37 38 39 |
# File 'lib/middleman-webp/options.rb', line 33 def for(file) matching = @conversion.select { |m, _o| m.matches? file } return '' if matching.empty? matching.max_by { |(pathname_matcher, _oa)| pathname_matcher }[1] end |