Module: Jekyll::Filters::MaxZoomLevel

Defined in:
lib/jekyll/filters/max_zoom_level.rb

Overview

Maximum zoom level

Instance Method Summary collapse

Instance Method Details

#max_zoom_level(input) ⇒ Integer

Finds the maximum zoom level for an image

Parameters:

  • :input (String)

Returns:

  • (Integer)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/jekyll/filters/max_zoom_level.rb', line 11

def max_zoom_level(input)
  return input unless input

  path = ::File.dirname(@context.registers[:site].in_source_dir(input))

  unless ::File.exist? path
    Jekyll.logger.warn 'Max zoom level:', "File doesn't exist #{input}"
    return input
  end

  max_zoom_level = 0

  loop do
    unless ::File.directory?(::File.join(path, max_zoom_level.to_s))
      max_zoom_level -= 1
      break
    end

    break if max_zoom_level > 18

    max_zoom_level += 1
  end

  max_zoom_level
end