Module: FuckingFavicons
- Extended by:
- FuckingFavicons
- Included in:
- FuckingFavicons
- Defined in:
- lib/fucking_favicons.rb,
lib/fucking_favicons/rails.rb,
lib/fucking_favicons/version.rb,
lib/fucking_favicons/middleware.rb
Defined Under Namespace
Classes: Engine, Middleware
Constant Summary collapse
- CONFIG =
[ { path: 'favicon.ico', size: [16, 16], mime_type: 'image/x-icon', format: 'ICO' }, { path: 'favicon-16x16.png', size: [16, 16] }, { path: 'favicon-32x32.png', size: [32, 32] }, { path: 'favicon-96x96.png', size: [96, 96] }, { path: 'favicon-160x160.png', size: [160, 160] }, { path: 'favicon-196x196.png', size: [196, 196] }, { path: 'mstile-70x70.png', size: [70, 70] }, { path: 'mstile-144x144.png', size: [144, 144] }, { path: 'mstile-150x150.png', size: [150, 150] }, { path: 'mstile-310x310.png', size: [310, 310] }, { path: 'mstile-310x150.png', size: [310, 150] }, { path: 'apple-touch-icon-57x57.png', size: [57, 57] }, { path: 'apple-touch-icon-60x60.png', size: [60, 60] }, { path: 'apple-touch-icon-72x72.png', size: [72, 72] }, { path: 'apple-touch-icon-76x76.png', size: [76, 76] }, { path: 'apple-touch-icon-114x114.png', size: [114, 114] }, { path: 'apple-touch-icon-120x120.png', size: [120, 120] }, { path: 'apple-touch-icon-144x144.png', size: [144, 144] }, { path: 'apple-touch-icon-152x152.png', size: [152, 152] }, { path: 'apple-touch-icon.png', size: [57, 57] }, { path: 'android-chrome-192x192.png', size: [192, 192] }, ]
- SIZES =
CONFIG.map{|h| h[:size]}
- PATHS =
CONFIG.map{|h| h[:path]}
- CACHE =
{}
- GLOBS =
[ FuckingFavicons.libdir('app/assets/images/favicon.png') ]
- VERSION =
'1.6.1'
Class Method Summary collapse
Instance Method Summary collapse
- #dependencies ⇒ Object
- #description ⇒ Object
- #favicon_for(path, info) ⇒ Object
- #libdir(*args, &block) ⇒ Object
Class Method Details
.version ⇒ Object
4 5 6 |
# File 'lib/fucking_favicons/version.rb', line 4 def FuckingFavicons.version ::FuckingFavicons::VERSION end |
Instance Method Details
#dependencies ⇒ Object
9 10 11 12 13 |
# File 'lib/fucking_favicons.rb', line 9 def dependencies { 'mini_magick' => [ 'mini_magick' , ' ~> 4.0' ] } end |
#description ⇒ Object
15 16 17 |
# File 'lib/fucking_favicons.rb', line 15 def description 'fucking favicons fucking suck' end |
#favicon_for(path, info) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# 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) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/fucking_favicons.rb', line 20 def libdir(*args, &block) @libdir ||= File.(__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 |