Class: Middleman::WebP::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman-webp/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  @ignore = options[:ignore] || []
  @ignore = [*@ignore].map do |pattern|
    Middleman::WebP::PathnameMatcher.new(pattern)
  end

  @conversion = options[:conversion_options] || {}
  @conversion = @conversion.reduce(Hash.new('')) do |h, (k, v)|
    h[Middleman::WebP::PathnameMatcher.new(k)] = to_args(v)
    h
  end

  @verbose = options[:verbose] || false

  @append_extension = options[:append_extension] || false
  @allow_skip = !(false == options[:allow_skip])
  @run_before_build = options[:run_before_build] || false
end

Instance Attribute Details

#allow_skipObject (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_extensionObject (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

#ignoreObject (readonly)

Returns the value of attribute ignore.



6
7
8
# File 'lib/middleman-webp/options.rb', line 6

def ignore
  @ignore
end

#run_before_buildObject (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

#verboseObject (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