module Jekyll::Favicon::StaticFile::Convertible

Create static file based on a source file

Public Instance Methods

convert() click to toggle source
# File lib/jekyll/favicon/static_file/convertible.rb, line 17
def convert
  convert_defaults = convertible_defaults.dig File.extname(path), @extname
  convert_normalized = convert_normalize convert_spec
  convert_consolidated = Utils.merge convert_defaults, convert_normalized
  patch convert_patch(convert_consolidated || {})
end
convert_odd_source?() click to toggle source
# File lib/jekyll/favicon/static_file/convertible.rb, line 33
def convert_odd_source?
  img = MiniMagick::Image.open path
  Utils.odd? img.dimensions
end
convert_size(size, separator = "x") click to toggle source
# File lib/jekyll/favicon/static_file/convertible.rb, line 38
def convert_size(size, separator = "x")
  return size unless convert_odd_source? || Utils.odd?(size)
  min_dimension = size.split(separator).min
  [min_dimension, min_dimension].join(separator)
end
convertible?() click to toggle source
# File lib/jekyll/favicon/static_file/convertible.rb, line 13
def convertible?
  convert.any? || convert_allow_empty?
end
convertible_patch(configuration) click to toggle source
# File lib/jekyll/favicon/static_file/convertible.rb, line 24
def convertible_patch(configuration)
  Utils.patch configuration do |value|
    case value
    when :sizes then sizes.join " "
    else value
    end
  end
end
modified?() click to toggle source

Jekyll::StaticFile method asks if dest mtime is older than source mtime after original modified?

Calls superclass method
# File lib/jekyll/favicon/static_file/convertible.rb, line 54
def modified?
  super || self.class.mtimes.fetch(href, -1) < mtime
end
sizes() click to toggle source
# File lib/jekyll/favicon/static_file/convertible.rb, line 44
def sizes
  if (match = Utils.name_to_size(name)) then [match[1]]
  elsif (define = Utils.define_to_size(convert_spec["define"])) then define
  elsif (resize = convert_spec["resize"]) then [resize]
  elsif (size = convert_spec["size"]) then [size]
  end
end
write(dest) click to toggle source

Jekyll::StaticFile method adds dest mtime to list after original write

Calls superclass method
# File lib/jekyll/favicon/static_file/convertible.rb, line 60
def write(dest)
  super(dest) && self.class.mtimes[href] = mtime
end

Private Instance Methods

convert_allow_empty?() click to toggle source
# File lib/jekyll/favicon/static_file/convertible.rb, line 78
def convert_allow_empty?
  @extname == ".svg" && @extname == File.extname(path)
end
convert_normalize(options) click to toggle source
# File lib/jekyll/favicon/static_file/convertible.rb, line 90
def convert_normalize(options)
  return {} unless options

  Utils.slice_and_compact options, convertible_keys
end
convert_patch(options) click to toggle source
# File lib/jekyll/favicon/static_file/convertible.rb, line 96
def convert_patch(options)
  patched_options = convert_patch_options options
  Utils.slice_and_compact patched_options, convertible_keys
end
convert_patch_option_extent(extent) click to toggle source
# File lib/jekyll/favicon/static_file/convertible.rb, line 116
def convert_patch_option_extent(extent)
  case extent
  when :auto
    if (size = sizes.first)
      width, height = size.split "x"
      size if width != height
    end
  else extent
  end
end
convert_patch_option_size(size) click to toggle source
# File lib/jekyll/favicon/static_file/convertible.rb, line 108
def convert_patch_option_size(size)
  case size
  when :auto
    convert_size size if (size = sizes.first)
  else size
  end
end
convert_patch_options(options) click to toggle source
# File lib/jekyll/favicon/static_file/convertible.rb, line 101
def convert_patch_options(options)
  %w[size extent].each_with_object(options) do |name, memo|
    method = "convert_patch_option_#{name}".to_sym
    memo[name] = send(method, options[name])
  end
end
convert_spec() click to toggle source
# File lib/jekyll/favicon/static_file/convertible.rb, line 82
def convert_spec
  spec.fetch "convert", {}
end
convertible_keys() click to toggle source
# File lib/jekyll/favicon/static_file/convertible.rb, line 86
def convertible_keys
  convertible_defaults["defaults"].keys
end
copy_file(dest_path) click to toggle source

Jekyll::StaticFile method add file creation instead of copying

Calls superclass method
# File lib/jekyll/favicon/static_file/convertible.rb, line 68
def copy_file(dest_path)
  case @extname
  when ".svg" then super(dest_path)
  when ".ico", ".png"
    Utils.convert path, dest_path, convert
  else Jekyll.logger.warn "Jekyll::Favicon: Can't generate " \
                          " #{dest_path}. Extension not supported."
  end
end