module FuckingFavicons

Constants

CACHE
CONFIG
GLOBS
PATHS
SIZES
VERSION

Public Class Methods

version() click to toggle source
# File lib/fucking_favicons/version.rb, line 4
def FuckingFavicons.version
  ::FuckingFavicons::VERSION
end

Public Instance Methods

dependencies() click to toggle source
# File lib/fucking_favicons.rb, line 9
def dependencies
  {
    'mini_magick'             => [ 'mini_magick'             , ' ~> 4.0' ]
  }
end
description() click to toggle source
# File lib/fucking_favicons.rb, line 15
def description
  'fucking favicons fucking suck'
end
favicon_for(path, info) click to toggle source
# File lib/fucking_favicons.rb, line 84
def favicon_for(path, info)
  key = [path, info.map{|kv| kv.join('=')}.join('&')].join('?')

  CACHE[key] ||= (
    image = MiniMagick::Image.open(path)

    dimensions = info[:size].join('x')

    image.resize(dimensions)

    if info[:format]
      image.format(info[:format] || 'png')
    end

    body           = image.to_blob
    content_length = body.bytesize.to_s
    content_type   = image.mime_type =~ /ico/ ? 'image/x-icon' : image.mime_type
    last_modified  = File.stat(path).mtime.httpdate

    favicon = {
      :body             => body,
      :content_length   => content_length,
      :content_type     => content_type,
      :last_modified    => last_modified,

      :headers => {
        'Content-Length' => content_length,
        'Content-Type'   => content_type,
        'Last-Modified'  => last_modified
      }
    }
  )
end
libdir(*args, &block) click to toggle source
# File lib/fucking_favicons.rb, line 20
def libdir(*args, &block)
  @libdir ||= File.expand_path(__FILE__).sub(/\.rb$/,'')
  args.empty? ? @libdir : File.join(@libdir, *args)
ensure
  if block
    begin
      $LOAD_PATH.unshift(@libdir)
      block.call()
    ensure
      $LOAD_PATH.shift()
    end
  end
end