rack-favicon_all 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/lib/rack/favicon_all/version.rb +1 -1
- data/lib/rack/favicon_all.rb +12 -8
- data/spec/images/icon.png +0 -0
- data/spec/rack-favicon_all_spec.rb +25 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 513049bb88c601dcee1c68ff16d3b1ab7969185d
|
4
|
+
data.tar.gz: 79488265fa69bced0a432ddd5fe6be0cc8d5681d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16918a625a26d1279736878ed692af66a81a555194c1da65ade2486432629789482ab0ac23b103204b463c75f029d9b1af515c5f219f1dfed95815ab86578cf1
|
7
|
+
data.tar.gz: 8def4ee4848ce5b4cb9fcaa71d9de35871f27c8f64f66d9545bbb9e500b753dd91d0b242612c6fcfbf1d5d450fa2f335070228984d892d36fef01e6e526d8bd3
|
data/Gemfile
CHANGED
data/lib/rack/favicon_all.rb
CHANGED
@@ -29,21 +29,25 @@ module Rack
|
|
29
29
|
def initialize(app, options = {})
|
30
30
|
@app = app
|
31
31
|
@favicon_path = options[:favicon_path]
|
32
|
-
|
32
|
+
if !@favicon_path.nil? && ::File.exist?(@favicon_path)
|
33
|
+
@image = Magick::Image.read(@favicon_path).first
|
34
|
+
end
|
33
35
|
end
|
34
36
|
|
35
37
|
def call(env)
|
36
|
-
|
37
|
-
return [status, headers, body] if @image.nil?
|
38
|
+
return @app.call(env) if @image.nil?
|
38
39
|
|
39
40
|
favicon_info = FAVICON.find { |f| env['PATH_INFO'] =~ f[:path] }
|
40
|
-
|
41
|
-
return [status, headers, body] if favicon_info.nil?
|
41
|
+
return @app.call(env) if favicon_info.nil?
|
42
42
|
|
43
43
|
body = genarate_favicon(favicon_info)
|
44
|
-
headers
|
45
|
-
|
46
|
-
|
44
|
+
headers = {
|
45
|
+
"Content-Length" => body.bytesize.to_s,
|
46
|
+
"Content-Type" => favicon_info[:mime_type] || "imgae/png",
|
47
|
+
"Last-Modified" => Time.now.httpdate
|
48
|
+
}
|
49
|
+
|
50
|
+
[200, headers, [body]]
|
47
51
|
end
|
48
52
|
|
49
53
|
private
|
Binary file
|
@@ -17,5 +17,30 @@ describe Rack::FaviconAll do
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
context 'return valid favicon' do
|
21
|
+
before { Timecop.freeze(Time.now) }
|
22
|
+
subject do
|
23
|
+
Rack::Lint.new(Rack::FaviconAll.new(app, favicon_path: File.expand_path('images/icon.png', __dir__)))
|
24
|
+
end
|
25
|
+
it do
|
26
|
+
response = Rack::MockRequest.new(subject).get('/favicon.ico')
|
27
|
+
expect(response.successful?).to be_truthy
|
28
|
+
expect(response.headers["Content-Type"]).to eq "image/x-icon"
|
29
|
+
expect(response.headers["Last-Modified"]).to eq Time.now.httpdate
|
30
|
+
end
|
31
|
+
after { Timecop.return }
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'invalid favicon_path' do
|
35
|
+
subject do
|
36
|
+
Rack::Lint.new(Rack::FaviconAll.new(app, favicon_path: File.expand_path('images/hoge', __dir__)))
|
37
|
+
end
|
38
|
+
it do
|
39
|
+
response = Rack::MockRequest.new(subject).get('/favicon.ico')
|
40
|
+
expect(response.successful?).to be_truthy
|
41
|
+
expect(response.body).to eq 'Hello, World!'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
20
45
|
end
|
21
46
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-favicon_all
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SpringMT
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rmagick
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- lib/rack/favicon_all.rb
|
71
71
|
- lib/rack/favicon_all/version.rb
|
72
72
|
- rack-favicon_all.gemspec
|
73
|
+
- spec/images/icon.png
|
73
74
|
- spec/rack-favicon_all_spec.rb
|
74
75
|
- spec/spec_helper.rb
|
75
76
|
homepage: https://github.com/SpringMT/rack-favicon_all
|
@@ -97,6 +98,7 @@ signing_key:
|
|
97
98
|
specification_version: 4
|
98
99
|
summary: Generate favicons for IE, FF, Chrome, Safari!
|
99
100
|
test_files:
|
101
|
+
- spec/images/icon.png
|
100
102
|
- spec/rack-favicon_all_spec.rb
|
101
103
|
- spec/spec_helper.rb
|
102
104
|
has_rdoc:
|