Class: JekyllImagemagickSutermserv::ImageGenerator

Inherits:
Jekyll::Generator
  • Object
show all
Defined in:
lib/generator.rb

Overview

Go through a set of directories and convert files

Instance Method Summary collapse

Instance Method Details

#generate(site) ⇒ Object

Main function, called by Jekyll-core. Do the transformations…



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/generator.rb', line 22

def generate(site)
  # Retrieve and merge the configuration from the site yml file
  @config = DEFAULTS.merge(site.config['imagemagick'] || {})

  # If disabled then simply quit
  unless @config['enabled']
    Jekyll.logger.info(LOG_PREFIX, 'Disabled in site.config')
    return
  end

  # If the site destination directory has not yet been created then create it now.
  # Otherwise, we cannot write our file there.
  unless File.directory? site.dest
    Dir.mkdir(site.dest)
  end

  files = get_files_to_transform(site, @config['input_directories'], @config['input_formats'])
  tuples = compute_transformations(site, files, @config['output_formats'], @config['widths'])
  generate_output_paths(site, tuples)
  generated_files = generate_files(site, tuples, @config['output_formats'])

  Jekyll.logger.info(LOG_PREFIX, "Generated #{generated_files} file(s)")
end