Module: Middleman::FaviconMaker

Defined in:
lib/middleman-favicon-maker/version.rb,
lib/middleman-favicon-maker/extension.rb

Constant Summary collapse

MAJOR =
3
MINOR =
4
PATCH =
1
BUILD =
nil
VERSION =
[MAJOR, MINOR, PATCH, BUILD].compact.join('.')

Class Method Summary collapse

Class Method Details

.registered(app, options = {}) ⇒ Object Also known as: included



4
5
6
7
8
9
10
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
36
37
38
39
# File 'lib/middleman-favicon-maker/extension.rb', line 4

def registered(app, options={})
  require "favicon_maker"

  options[:favicon_maker_root_dir]        ||= ''
  options[:favicon_maker_input_dir]       ||= ''
  options[:favicon_maker_output_dir]      ||= ''
  options[:favicon_maker_base_image]      ||= 'favicon_base.png'
  options[:favicon_maker_versions]        ||= [ :fav_png, :fav_ico ]
  options[:favicon_maker_custom_versions] ||= {}

  app.after_configuration do
    # configs are either default or set by user in config.rb
    # due to Middleman extension limitations, we need to ensure they are sane
    # before we continue
    options[:favicon_maker_root_dir]   = root      if options[:favicon_maker_root_dir].empty?
    options[:favicon_maker_input_dir]  = source    if options[:favicon_maker_input_dir].empty?
    options[:favicon_maker_output_dir] = build_dir if options[:favicon_maker_output_dir].empty?
  end

  app.after_build do |builder|
    ::FaviconMaker::Generator.create_versions({
      :root_dir =>        options[:favicon_maker_root_dir],
      :input_dir =>       options[:favicon_maker_input_dir],
      :output_dir =>      options[:favicon_maker_output_dir],
      :base_image =>      options[:favicon_maker_base_image],
      :versions =>        options[:favicon_maker_versions],
      :custom_versions => options[:favicon_maker_custom_versions],
      :copy =>            true
    }) do |f, status|
      builder.say_status status, f.gsub(root + "/", "")
    end

    # remove favicon_base_image from the build dir
    builder.remove_file File.join(options[:favicon_maker_root_dir], options[:favicon_maker_output_dir], options[:favicon_maker_base_image])
  end
end