fucking_favicons 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.md +64 -0
- data/Rakefile +394 -0
- data/lib/fucking_favicons.rb +118 -0
- data/lib/fucking_favicons/app/assets/images/favicon.png +0 -0
- data/lib/fucking_favicons/app/views/fucking_favicons.html.erb +25 -0
- data/lib/fucking_favicons/middleware.rb +45 -0
- data/lib/fucking_favicons/rails.rb +13 -0
- data/lib/fucking_favicons/version.rb +7 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YTMxYTAxZjcyOTIwZjc2ZjYyYjc1NTU0ZGIxNjE4NWMxYTQ3ZWY2NA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NDcwYzQyZDExOGY4MzM5ZmFiY2Q5MWEyYWViMGE1OGNmOGJlOWNlNQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NWNjZTc3ZjQwZGQzMTNkNzZjOTIzYzA5YWUwYTE4MDJiZWI4YWIxYTlkOWIw
|
10
|
+
ODNkY2UyZGMyZjdhMGQ2NGY3NDY3ZjljYmNmYzllYzM1ZGE0NzJiNzdiODgx
|
11
|
+
NjE2MTYxNWJlMzI0ZTc0YWMzMjQxOThiMmI2NjRhOWQwZmNjNmU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZGJjMmNlZWZiNDI2MTJhOWQyOGQyYjY1NzNjNTk0YWM5ZDYwNWZiZGRhNzc0
|
14
|
+
MGVlMGZkZmViNGQyMDNjYzhiZjUwMzY3MzFkYzE5OThjMjA2N2E3ZGFkMjU3
|
15
|
+
YTRiMTkzZjZhMGVhZmVjNzgzMTMxNzAyYTk4YmRjY2U2NDYyNTA=
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
NAME
|
2
|
+
====
|
3
|
+
fucking_favicons.rb
|
4
|
+
|
5
|
+
<img src='http://s3.amazonaws.com/drawohara.com.gifs/favicons.gif' style='max-height:100px;'>
|
6
|
+
|
7
|
+
TL;DR
|
8
|
+
=====
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
|
12
|
+
# install the fucking favicon gem
|
13
|
+
|
14
|
+
gem 'fucking_favicons'
|
15
|
+
|
16
|
+
```
|
17
|
+
|
18
|
+
|
19
|
+
```bash
|
20
|
+
|
21
|
+
# make a fucking favicon
|
22
|
+
|
23
|
+
~> cd app/views/images
|
24
|
+
|
25
|
+
~> curl -sO http://s3.amazonaws.com/drawohara.com.images/favicon.png
|
26
|
+
|
27
|
+
```
|
28
|
+
|
29
|
+
```erb
|
30
|
+
|
31
|
+
<!-- drop it in yer fucking viewz -->
|
32
|
+
|
33
|
+
<%= render :template => 'fucking_favicons' %>
|
34
|
+
|
35
|
+
```
|
36
|
+
|
37
|
+
ABOUT
|
38
|
+
=====
|
39
|
+
|
40
|
+
fucking_favicons.rb is the best gem in the world.
|
41
|
+
|
42
|
+
if you doubt this, read https://css-tricks.com/favicon-quiz/
|
43
|
+
|
44
|
+
fucking_favicons.rb is a rails engine, and rack middleware, which lets you
|
45
|
+
provide a *single* favicon.png file for your project and let all the rest be
|
46
|
+
dynamically generated on the fly. it also gives you a handy view that
|
47
|
+
vommits this out:
|
48
|
+
|
49
|
+
<img src='https://s3.amazonaws.com/ss.dojo4.com/qrlxRqq0XC7Uweu6DOYrYx8E11A73Qk0tn1YYPMjyzOQqs5bRSC4MBo.png' style='max-height:100px'>
|
50
|
+
|
51
|
+
the favicons are generated on the fly only once, and cached in memory. they
|
52
|
+
are served with the last-modified time of the file on disk. so, this will
|
53
|
+
peform just fine.
|
54
|
+
|
55
|
+
you can use this gem in rails, or a rack app
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
|
59
|
+
# for rack apps
|
60
|
+
|
61
|
+
use FuckingFavicons, :path => 'path/to/favicon.png'
|
62
|
+
|
63
|
+
```
|
64
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,394 @@
|
|
1
|
+
This.rubyforge_project = 'codeforpeople'
|
2
|
+
This.author = "Ara T. Howard"
|
3
|
+
This.email = "ara.t.howard@gmail.com"
|
4
|
+
This.homepage = "https://github.com/ahoward/#{ This.lib }"
|
5
|
+
|
6
|
+
task :license do
|
7
|
+
open('LICENSE', 'w'){|fd| fd.puts "same as ruby's"}
|
8
|
+
end
|
9
|
+
|
10
|
+
task :default do
|
11
|
+
puts((Rake::Task.tasks.map{|task| task.name.gsub(/::/,':')} - ['default']).sort)
|
12
|
+
end
|
13
|
+
|
14
|
+
task :test do
|
15
|
+
run_tests!
|
16
|
+
end
|
17
|
+
|
18
|
+
namespace :test do
|
19
|
+
task(:unit){ run_tests!(:unit) }
|
20
|
+
task(:functional){ run_tests!(:functional) }
|
21
|
+
task(:integration){ run_tests!(:integration) }
|
22
|
+
end
|
23
|
+
|
24
|
+
def run_tests!(which = nil)
|
25
|
+
which ||= '**'
|
26
|
+
test_dir = File.join(This.dir, "test")
|
27
|
+
test_glob ||= File.join(test_dir, "#{ which }/**_test.rb")
|
28
|
+
test_rbs = Dir.glob(test_glob).sort
|
29
|
+
|
30
|
+
div = ('=' * 119)
|
31
|
+
line = ('-' * 119)
|
32
|
+
|
33
|
+
test_rbs.each_with_index do |test_rb, index|
|
34
|
+
testno = index + 1
|
35
|
+
command = "#{ This.ruby } -w -I ./lib -I ./test/lib #{ test_rb }"
|
36
|
+
|
37
|
+
puts
|
38
|
+
say(div, :color => :cyan, :bold => true)
|
39
|
+
say("@#{ testno } => ", :bold => true, :method => :print)
|
40
|
+
say(command, :color => :cyan, :bold => true)
|
41
|
+
say(line, :color => :cyan, :bold => true)
|
42
|
+
|
43
|
+
system(command)
|
44
|
+
|
45
|
+
say(line, :color => :cyan, :bold => true)
|
46
|
+
|
47
|
+
status = $?.exitstatus
|
48
|
+
|
49
|
+
if status.zero?
|
50
|
+
say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
|
51
|
+
say("SUCCESS", :color => :green, :bold => true)
|
52
|
+
else
|
53
|
+
say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
|
54
|
+
say("FAILURE", :color => :red, :bold => true)
|
55
|
+
end
|
56
|
+
say(line, :color => :cyan, :bold => true)
|
57
|
+
|
58
|
+
exit(status) unless status.zero?
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
task :gemspec do
|
64
|
+
ignore_extensions = ['git', 'svn', 'tmp', /sw./, 'bak', 'gem']
|
65
|
+
ignore_directories = ['pkg']
|
66
|
+
ignore_files = ['test/log']
|
67
|
+
|
68
|
+
shiteless =
|
69
|
+
lambda do |list|
|
70
|
+
list.delete_if do |entry|
|
71
|
+
next unless test(?e, entry)
|
72
|
+
extension = File.basename(entry).split(%r/[.]/).last
|
73
|
+
ignore_extensions.any?{|ext| ext === extension}
|
74
|
+
end
|
75
|
+
list.delete_if do |entry|
|
76
|
+
next unless test(?d, entry)
|
77
|
+
dirname = File.expand_path(entry)
|
78
|
+
ignore_directories.any?{|dir| File.expand_path(dir) == dirname}
|
79
|
+
end
|
80
|
+
list.delete_if do |entry|
|
81
|
+
next unless test(?f, entry)
|
82
|
+
filename = File.expand_path(entry)
|
83
|
+
ignore_files.any?{|file| File.expand_path(file) == filename}
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
lib = This.lib
|
88
|
+
object = This.object
|
89
|
+
version = This.version
|
90
|
+
files = shiteless[Dir::glob("**/**")]
|
91
|
+
executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)}
|
92
|
+
#has_rdoc = true #File.exist?('doc')
|
93
|
+
test_files = "test/#{ lib }.rb" if File.file?("test/#{ lib }.rb")
|
94
|
+
summary = object.respond_to?(:summary) ? object.summary : "summary: #{ lib } kicks the ass"
|
95
|
+
description = object.respond_to?(:description) ? object.description : "description: #{ lib } kicks the ass"
|
96
|
+
license = object.respond_to?(:license) ? object.license : "same as ruby's"
|
97
|
+
|
98
|
+
if This.extensions.nil?
|
99
|
+
This.extensions = []
|
100
|
+
extensions = This.extensions
|
101
|
+
%w( Makefile configure extconf.rb ).each do |ext|
|
102
|
+
extensions << ext if File.exists?(ext)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
extensions = [extensions].flatten.compact
|
106
|
+
|
107
|
+
if This.dependencies.nil?
|
108
|
+
dependencies = []
|
109
|
+
else
|
110
|
+
case This.dependencies
|
111
|
+
when Hash
|
112
|
+
dependencies = This.dependencies.values
|
113
|
+
when Array
|
114
|
+
dependencies = This.dependencies
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
template =
|
119
|
+
if test(?e, 'gemspec.erb')
|
120
|
+
Template{ IO.read('gemspec.erb') }
|
121
|
+
else
|
122
|
+
Template {
|
123
|
+
<<-__
|
124
|
+
## <%= lib %>.gemspec
|
125
|
+
#
|
126
|
+
|
127
|
+
Gem::Specification::new do |spec|
|
128
|
+
spec.name = <%= lib.inspect %>
|
129
|
+
spec.version = <%= version.inspect %>
|
130
|
+
spec.platform = Gem::Platform::RUBY
|
131
|
+
spec.summary = <%= lib.inspect %>
|
132
|
+
spec.description = <%= description.inspect %>
|
133
|
+
spec.license = <%= license.inspect %>
|
134
|
+
|
135
|
+
spec.files =\n<%= files.sort.pretty_inspect %>
|
136
|
+
spec.executables = <%= executables.inspect %>
|
137
|
+
|
138
|
+
spec.require_path = "lib"
|
139
|
+
|
140
|
+
spec.test_files = <%= test_files.inspect %>
|
141
|
+
|
142
|
+
<% dependencies.each do |lib_version| %>
|
143
|
+
spec.add_dependency(*<%= Array(lib_version).flatten.inspect %>)
|
144
|
+
<% end %>
|
145
|
+
|
146
|
+
spec.extensions.push(*<%= extensions.inspect %>)
|
147
|
+
|
148
|
+
spec.rubyforge_project = <%= This.rubyforge_project.inspect %>
|
149
|
+
spec.author = <%= This.author.inspect %>
|
150
|
+
spec.email = <%= This.email.inspect %>
|
151
|
+
spec.homepage = <%= This.homepage.inspect %>
|
152
|
+
end
|
153
|
+
__
|
154
|
+
}
|
155
|
+
end
|
156
|
+
|
157
|
+
Fu.mkdir_p(This.pkgdir)
|
158
|
+
gemspec = "#{ lib }.gemspec"
|
159
|
+
open(gemspec, "w"){|fd| fd.puts(template)}
|
160
|
+
This.gemspec = gemspec
|
161
|
+
end
|
162
|
+
|
163
|
+
task :gem => [:clean, :gemspec] do
|
164
|
+
Fu.mkdir_p(This.pkgdir)
|
165
|
+
before = Dir['*.gem']
|
166
|
+
cmd = "gem build #{ This.gemspec }"
|
167
|
+
`#{ cmd }`
|
168
|
+
after = Dir['*.gem']
|
169
|
+
gem = ((after - before).first || after.first) or abort('no gem!')
|
170
|
+
Fu.mv(gem, This.pkgdir)
|
171
|
+
This.gem = File.join(This.pkgdir, File.basename(gem))
|
172
|
+
end
|
173
|
+
|
174
|
+
task :readme do
|
175
|
+
samples = ''
|
176
|
+
prompt = '~ > '
|
177
|
+
lib = This.lib
|
178
|
+
version = This.version
|
179
|
+
|
180
|
+
Dir['sample*/*'].sort.each do |sample|
|
181
|
+
samples << "\n" << " <========< #{ sample } >========>" << "\n\n"
|
182
|
+
|
183
|
+
cmd = "cat #{ sample }"
|
184
|
+
samples << Util.indent(prompt + cmd, 2) << "\n\n"
|
185
|
+
samples << Util.indent(`#{ cmd }`, 4) << "\n"
|
186
|
+
|
187
|
+
cmd = "ruby #{ sample }"
|
188
|
+
samples << Util.indent(prompt + cmd, 2) << "\n\n"
|
189
|
+
|
190
|
+
cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -I ./lib #{ sample })'"
|
191
|
+
samples << Util.indent(`#{ cmd } 2>&1`, 4) << "\n"
|
192
|
+
end
|
193
|
+
|
194
|
+
template =
|
195
|
+
if test(?e, 'README.erb')
|
196
|
+
Template{ IO.read('README.erb') }
|
197
|
+
else
|
198
|
+
Template {
|
199
|
+
<<-__
|
200
|
+
NAME
|
201
|
+
#{ lib }
|
202
|
+
|
203
|
+
DESCRIPTION
|
204
|
+
|
205
|
+
INSTALL
|
206
|
+
gem install #{ lib }
|
207
|
+
|
208
|
+
SAMPLES
|
209
|
+
#{ samples }
|
210
|
+
__
|
211
|
+
}
|
212
|
+
end
|
213
|
+
|
214
|
+
open("README", "w"){|fd| fd.puts template}
|
215
|
+
end
|
216
|
+
|
217
|
+
|
218
|
+
task :clean do
|
219
|
+
Dir[File.join(This.pkgdir, '**/**')].each{|entry| Fu.rm_rf(entry)}
|
220
|
+
end
|
221
|
+
|
222
|
+
|
223
|
+
task :release => [:clean, :gemspec, :gem] do
|
224
|
+
gems = Dir[File.join(This.pkgdir, '*.gem')].flatten
|
225
|
+
raise "which one? : #{ gems.inspect }" if gems.size > 1
|
226
|
+
raise "no gems?" if gems.size < 1
|
227
|
+
|
228
|
+
cmd = "gem push #{ This.gem }"
|
229
|
+
puts cmd
|
230
|
+
puts
|
231
|
+
system(cmd)
|
232
|
+
abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
|
233
|
+
|
234
|
+
cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.gem }"
|
235
|
+
puts cmd
|
236
|
+
puts
|
237
|
+
system(cmd)
|
238
|
+
abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
|
239
|
+
end
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
BEGIN {
|
246
|
+
# support for this rakefile
|
247
|
+
#
|
248
|
+
$VERBOSE = nil
|
249
|
+
|
250
|
+
require 'ostruct'
|
251
|
+
require 'erb'
|
252
|
+
require 'fileutils'
|
253
|
+
require 'rbconfig'
|
254
|
+
require 'pp'
|
255
|
+
|
256
|
+
# fu shortcut
|
257
|
+
#
|
258
|
+
Fu = FileUtils
|
259
|
+
|
260
|
+
# cache a bunch of stuff about this rakefile/environment
|
261
|
+
#
|
262
|
+
This = OpenStruct.new
|
263
|
+
|
264
|
+
This.file = File.expand_path(__FILE__)
|
265
|
+
This.dir = File.dirname(This.file)
|
266
|
+
This.pkgdir = File.join(This.dir, 'pkg')
|
267
|
+
|
268
|
+
# grok lib
|
269
|
+
#
|
270
|
+
lib = ENV['LIB']
|
271
|
+
unless lib
|
272
|
+
lib = File.basename(Dir.pwd).sub(/[-].*$/, '')
|
273
|
+
end
|
274
|
+
This.lib = lib
|
275
|
+
|
276
|
+
# grok version
|
277
|
+
#
|
278
|
+
version = ENV['VERSION']
|
279
|
+
unless version
|
280
|
+
require "./lib/#{ This.lib }"
|
281
|
+
This.name = lib.capitalize
|
282
|
+
This.object = eval(This.name)
|
283
|
+
version = This.object.send(:version)
|
284
|
+
end
|
285
|
+
This.version = version
|
286
|
+
|
287
|
+
# see if dependencies are export by the module
|
288
|
+
#
|
289
|
+
if This.object.respond_to?(:dependencies)
|
290
|
+
This.dependencies = This.object.dependencies
|
291
|
+
end
|
292
|
+
|
293
|
+
# we need to know the name of the lib an it's version
|
294
|
+
#
|
295
|
+
abort('no lib') unless This.lib
|
296
|
+
abort('no version') unless This.version
|
297
|
+
|
298
|
+
# discover full path to this ruby executable
|
299
|
+
#
|
300
|
+
c = Config::CONFIG
|
301
|
+
bindir = c["bindir"] || c['BINDIR']
|
302
|
+
ruby_install_name = c['ruby_install_name'] || c['RUBY_INSTALL_NAME'] || 'ruby'
|
303
|
+
ruby_ext = c['EXEEXT'] || ''
|
304
|
+
ruby = File.join(bindir, (ruby_install_name + ruby_ext))
|
305
|
+
This.ruby = ruby
|
306
|
+
|
307
|
+
# some utils
|
308
|
+
#
|
309
|
+
module Util
|
310
|
+
def indent(s, n = 2)
|
311
|
+
s = unindent(s)
|
312
|
+
ws = ' ' * n
|
313
|
+
s.gsub(%r/^/, ws)
|
314
|
+
end
|
315
|
+
|
316
|
+
def unindent(s)
|
317
|
+
indent = nil
|
318
|
+
s.each_line do |line|
|
319
|
+
next if line =~ %r/^\s*$/
|
320
|
+
indent = line[%r/^\s*/] and break
|
321
|
+
end
|
322
|
+
indent ? s.gsub(%r/^#{ indent }/, "") : s
|
323
|
+
end
|
324
|
+
extend self
|
325
|
+
end
|
326
|
+
|
327
|
+
# template support
|
328
|
+
#
|
329
|
+
class Template
|
330
|
+
def initialize(&block)
|
331
|
+
@block = block
|
332
|
+
@template = block.call.to_s
|
333
|
+
end
|
334
|
+
def expand(b=nil)
|
335
|
+
ERB.new(Util.unindent(@template)).result((b||@block).binding)
|
336
|
+
end
|
337
|
+
alias_method 'to_s', 'expand'
|
338
|
+
end
|
339
|
+
def Template(*args, &block) Template.new(*args, &block) end
|
340
|
+
|
341
|
+
# colored console output support
|
342
|
+
#
|
343
|
+
This.ansi = {
|
344
|
+
:clear => "\e[0m",
|
345
|
+
:reset => "\e[0m",
|
346
|
+
:erase_line => "\e[K",
|
347
|
+
:erase_char => "\e[P",
|
348
|
+
:bold => "\e[1m",
|
349
|
+
:dark => "\e[2m",
|
350
|
+
:underline => "\e[4m",
|
351
|
+
:underscore => "\e[4m",
|
352
|
+
:blink => "\e[5m",
|
353
|
+
:reverse => "\e[7m",
|
354
|
+
:concealed => "\e[8m",
|
355
|
+
:black => "\e[30m",
|
356
|
+
:red => "\e[31m",
|
357
|
+
:green => "\e[32m",
|
358
|
+
:yellow => "\e[33m",
|
359
|
+
:blue => "\e[34m",
|
360
|
+
:magenta => "\e[35m",
|
361
|
+
:cyan => "\e[36m",
|
362
|
+
:white => "\e[37m",
|
363
|
+
:on_black => "\e[40m",
|
364
|
+
:on_red => "\e[41m",
|
365
|
+
:on_green => "\e[42m",
|
366
|
+
:on_yellow => "\e[43m",
|
367
|
+
:on_blue => "\e[44m",
|
368
|
+
:on_magenta => "\e[45m",
|
369
|
+
:on_cyan => "\e[46m",
|
370
|
+
:on_white => "\e[47m"
|
371
|
+
}
|
372
|
+
def say(phrase, *args)
|
373
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
374
|
+
options[:color] = args.shift.to_s.to_sym unless args.empty?
|
375
|
+
keys = options.keys
|
376
|
+
keys.each{|key| options[key.to_s.to_sym] = options.delete(key)}
|
377
|
+
|
378
|
+
color = options[:color]
|
379
|
+
bold = options.has_key?(:bold)
|
380
|
+
|
381
|
+
parts = [phrase]
|
382
|
+
parts.unshift(This.ansi[color]) if color
|
383
|
+
parts.unshift(This.ansi[:bold]) if bold
|
384
|
+
parts.push(This.ansi[:clear]) if parts.size > 1
|
385
|
+
|
386
|
+
method = options[:method] || :puts
|
387
|
+
|
388
|
+
Kernel.send(method, parts.join)
|
389
|
+
end
|
390
|
+
|
391
|
+
# always run out of the project dir
|
392
|
+
#
|
393
|
+
Dir.chdir(This.dir)
|
394
|
+
}
|
@@ -0,0 +1,118 @@
|
|
1
|
+
module FuckingFavicons
|
2
|
+
#
|
3
|
+
extend(self)
|
4
|
+
|
5
|
+
#
|
6
|
+
require_relative 'fucking_favicons/version'
|
7
|
+
|
8
|
+
#
|
9
|
+
def dependencies
|
10
|
+
{
|
11
|
+
'mini_magick' => [ 'mini_magick' , ' >= 3.1' ]
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def description
|
16
|
+
'fucking favicons fucking suck'
|
17
|
+
end
|
18
|
+
|
19
|
+
#
|
20
|
+
def libdir(*args, &block)
|
21
|
+
@libdir ||= File.expand_path(__FILE__).sub(/\.rb$/,'')
|
22
|
+
args.empty? ? @libdir : File.join(@libdir, *args)
|
23
|
+
ensure
|
24
|
+
if block
|
25
|
+
begin
|
26
|
+
$LOAD_PATH.unshift(@libdir)
|
27
|
+
block.call()
|
28
|
+
ensure
|
29
|
+
$LOAD_PATH.shift()
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
CONFIG = [
|
36
|
+
{ path: 'favicon.ico', size: [16, 16], mime_type: 'image/x-icon', format: 'ICO' },
|
37
|
+
{ path: 'favicon-16x16.png', size: [16, 16] },
|
38
|
+
{ path: 'favicon-32x32.png', size: [32, 32] },
|
39
|
+
{ path: 'favicon-96x96.png', size: [96, 96] },
|
40
|
+
{ path: 'favicon-160x160.png', size: [160, 160] },
|
41
|
+
{ path: 'favicon-196x196.png', size: [196, 196] },
|
42
|
+
{ path: 'mstile-70x70.png', size: [70, 70] },
|
43
|
+
{ path: 'mstile-144x144.png', size: [144, 144] },
|
44
|
+
{ path: 'mstile-150x150.png', size: [150, 150] },
|
45
|
+
{ path: 'mstile-310x310.png', size: [310, 310] },
|
46
|
+
{ path: 'mstile-310x150.png', size: [310, 150] },
|
47
|
+
{ path: 'apple-touch-icon-57x57.png', size: [57, 57] },
|
48
|
+
{ path: 'apple-touch-icon-60x60.png', size: [60, 60] },
|
49
|
+
{ path: 'apple-touch-icon-72x72.png', size: [72, 72] },
|
50
|
+
{ path: 'apple-touch-icon-76x76.png', size: [76, 76] },
|
51
|
+
{ path: 'apple-touch-icon-114x114.png', size: [114, 114] },
|
52
|
+
{ path: 'apple-touch-icon-120x120.png', size: [120, 120] },
|
53
|
+
{ path: 'apple-touch-icon-144x144.png', size: [144, 144] },
|
54
|
+
{ path: 'apple-touch-icon-152x152.png', size: [152, 152] },
|
55
|
+
{ path: 'apple-touch-icon.png', size: [57, 57] },
|
56
|
+
{ path: 'apple-touch-icon-precomposed.png', size: [57, 57] },
|
57
|
+
]
|
58
|
+
|
59
|
+
#
|
60
|
+
SIZES = CONFIG.map{|h| h[:size]}
|
61
|
+
|
62
|
+
#
|
63
|
+
PATHS = CONFIG.map{|h| h[:path]}
|
64
|
+
|
65
|
+
#
|
66
|
+
CACHE = {}
|
67
|
+
|
68
|
+
#
|
69
|
+
GLOBS = [
|
70
|
+
FuckingFavicons.libdir('app/assets/images/favicon.png')
|
71
|
+
]
|
72
|
+
|
73
|
+
#
|
74
|
+
if defined?(Rack)
|
75
|
+
require_relative 'fucking_favicons/middleware'
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
if defined?(Rails)
|
80
|
+
require_relative 'fucking_favicons/rails'
|
81
|
+
end
|
82
|
+
|
83
|
+
#
|
84
|
+
def favicon_for(path, info)
|
85
|
+
key = [path, info.map{|kv| kv.join('=')}.join('&')].join('?')
|
86
|
+
|
87
|
+
CACHE[key] ||= (
|
88
|
+
image = MiniMagick::Image.open(path)
|
89
|
+
|
90
|
+
dimensions = info[:size].join('x')
|
91
|
+
|
92
|
+
image.resize(dimensions)
|
93
|
+
|
94
|
+
if info[:format]
|
95
|
+
image.format(info[:format] || 'png')
|
96
|
+
end
|
97
|
+
|
98
|
+
body = image.to_blob
|
99
|
+
content_length = body.bytesize.to_s
|
100
|
+
content_type = image.mime_type =~ /ico/ ? 'image/x-icon' : image.mime_type
|
101
|
+
last_modified = File.stat(path).mtime.httpdate
|
102
|
+
|
103
|
+
favicon = {
|
104
|
+
:body => body,
|
105
|
+
:content_length => content_length,
|
106
|
+
:content_type => content_type,
|
107
|
+
:last_modified => last_modified,
|
108
|
+
|
109
|
+
:headers => {
|
110
|
+
'Content-Length' => content_length,
|
111
|
+
'Content-Type' => content_type,
|
112
|
+
'Last-Modified' => last_modified
|
113
|
+
}
|
114
|
+
}
|
115
|
+
)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
Fucking_favicons = FuckingFavicons
|
Binary file
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<%
|
2
|
+
FuckingFavicons::CONFIG.each do |config|
|
3
|
+
|
4
|
+
case config[:path].to_s
|
5
|
+
when /apple/
|
6
|
+
size = Array(config[:size]).first
|
7
|
+
path = config[:path]
|
8
|
+
rel = 'apple-touch-icon'
|
9
|
+
type = 'image/png'
|
10
|
+
|
11
|
+
when /favicon-.*png/
|
12
|
+
size = Array(config[:size]).first
|
13
|
+
path = config[:path]
|
14
|
+
rel = 'image/png'
|
15
|
+
type = 'image/png'
|
16
|
+
|
17
|
+
else
|
18
|
+
next
|
19
|
+
end
|
20
|
+
|
21
|
+
%>
|
22
|
+
<%= favicon_link_tag path, :rel => rel, :type => type, :sizes => "#{ size }x#{ size }" %>
|
23
|
+
<% end %>
|
24
|
+
<meta name="msapplication-TileColor" content="#ffffff" />
|
25
|
+
<meta name="msapplication-TileImage" content="/mstile-144x144.png" />
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module FuckingFavicons
|
2
|
+
class Middleware
|
3
|
+
def initialize(app, options = {})
|
4
|
+
@app = app
|
5
|
+
@favicon_path = options[:favicon_path] || options[:path]
|
6
|
+
|
7
|
+
unless @favicon_path
|
8
|
+
GLOBS.each do |glob|
|
9
|
+
first = Dir.glob(glob).first
|
10
|
+
|
11
|
+
if first
|
12
|
+
@favicon_path = first
|
13
|
+
|
14
|
+
if STDERR.tty?
|
15
|
+
warn "FuckingFavicon: #{ @favicon_path }"
|
16
|
+
end
|
17
|
+
|
18
|
+
break
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
begin
|
24
|
+
MiniMagick::Image.open(@favicon_path)
|
25
|
+
rescue
|
26
|
+
warn "FuckingFavicon: #{ @favicon_path }"
|
27
|
+
raise
|
28
|
+
end
|
29
|
+
|
30
|
+
CONFIG.each do |c|
|
31
|
+
c[:regex] = %r'\A(?:/assets/|/)?#{ Regexp.escape( c[:path] )}'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def call(env)
|
36
|
+
config = CONFIG.detect{|c| env['PATH_INFO'] =~ c[:regex]}
|
37
|
+
|
38
|
+
return @app.call(env) unless config
|
39
|
+
|
40
|
+
favicon = FuckingFavicons.favicon_for(@favicon_path, config)
|
41
|
+
|
42
|
+
[200, favicon[:headers], [favicon[:body]]]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module FuckingFavicons
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
engine_name :fucking_favicons
|
4
|
+
|
5
|
+
config.before_initialize do |config|
|
6
|
+
config.middleware.use FuckingFavicons::Middleware
|
7
|
+
end
|
8
|
+
|
9
|
+
paths['app/views'] << FuckingFavicons.libdir('app/views')
|
10
|
+
|
11
|
+
FuckingFavicons::GLOBS.unshift(Rails.root.join('app/assets/images/favicon.png'))
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fucking_favicons
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ara T. Howard
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mini_magick
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.1'
|
27
|
+
description: fucking favicons fucking suck
|
28
|
+
email: ara.t.howard@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- README.md
|
34
|
+
- Rakefile
|
35
|
+
- lib/fucking_favicons.rb
|
36
|
+
- lib/fucking_favicons/app/assets/images/favicon.png
|
37
|
+
- lib/fucking_favicons/app/views/fucking_favicons.html.erb
|
38
|
+
- lib/fucking_favicons/middleware.rb
|
39
|
+
- lib/fucking_favicons/rails.rb
|
40
|
+
- lib/fucking_favicons/version.rb
|
41
|
+
homepage: https://github.com/ahoward/fucking_favicons
|
42
|
+
licenses:
|
43
|
+
- same as ruby's
|
44
|
+
metadata: {}
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project: codeforpeople
|
61
|
+
rubygems_version: 2.0.3
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: fucking_favicons
|
65
|
+
test_files: []
|