lib/jekyll/favicon/generator.rb in jekyll-favicon-0.2.1 vs lib/jekyll/favicon/generator.rb in jekyll-favicon-0.2.2

- old
+ new

@@ -2,27 +2,35 @@ module Favicon # Extended generator that creates all the stastic icons and metadata files class Generator < Jekyll::Generator priority :high + attr_accessor :template + def generate(site) @site = site if File.exist? favicon_source - generate_files Favicon.config['sizes'], Favicon.config['path'] + @template = favicon_tempfile + generate_files Favicon.config['path'] else Jekyll.logger.warn 'Jekyll::Favicon: Missing' \ " #{Favicon.config['source']}, not generating" \ ' favicons.' end end + def clean + return unless @tempfile + @template.close + @template.unlink + end + private - def generate_files(sizes, prefix) - favicon_template = favicon_tempfile - generate_ico_from favicon_template.path - generate_png_from favicon_template.path, prefix, sizes + def generate_files(prefix) + generate_ico_from @template.path + generate_png_from @template.path, prefix if File.extname(favicon_source) == '.svg' generate_svg_from favicon_source, prefix, 'safari-pinned-tab.svg' end generate_metadata_from 'browserconfig.xml' @@ -32,10 +40,10 @@ def generate_ico_from(source) ico_favicon = Icon.new(@site, '', 'favicon.ico', source) @site.static_files << ico_favicon end - def generate_png_from(source, prefix, sizes) + def generate_png_from(source, prefix) ['classic', 'ie', 'chrome', 'apple-touch-icon'].each do |template| Favicon.config[template]['sizes'].each do |size| png_favicon = Icon.new(@site, prefix, "favicon-#{size}.png", source) @site.static_files << png_favicon end