rack-devfavicon 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6550d005669c4c4053dd29aa2fd3378444e52394
4
+ data.tar.gz: 26be6a71b94e50a5edbd0db9cd49d4095d55d2d1
5
+ SHA512:
6
+ metadata.gz: 4a67aa67dece3607ea4d67d346ddf7a47f16c606c6d3a6e586773c2687e6c94666a04cb854884d832791f7d0a5f8fae803d294f4d7adc54fef66697e8393a62f
7
+ data.tar.gz: 05c78f2b71b79c1e5cc8d0c0bbda0e88a19d77403457024425d82ce804fabb6ca0af6d65d5335200a96025b1db13b75ff85272c670e4899df0db639ddd10d723
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Changes ADDED
@@ -0,0 +1,3 @@
1
+
2
+ 0.0.1 2013-09-08 16:18:15+0900
3
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rack-middkeware-devfavicon.gemspec
4
+ gemspec
5
+
6
+ gem 'rack'
7
+ gem 'rmagick'
8
+
9
+ group :test do
10
+ gem 'rack-test'
11
+ gem 'rspec'
12
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Fuji, Goro
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ # Rack::DevFavicon
2
+
3
+ The Rack::DevFavicon middleware shows the favicon in gray scale on a specified environment
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ group :development do
11
+ gem 'rack-devfavicon'
12
+ end
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rack-devfavicon
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ if ENV['RACK_ENV'] != 'production'
27
+ require 'rack-devfavicon'
28
+ use Rack::DevFavicon
29
+ end
30
+ ```
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,23 @@
1
+ require 'rack'
2
+
3
+ require 'rack-devfavicon'
4
+
5
+ class HelloWorld
6
+ def self.call(env)
7
+ [200, {"Content-Type" => "text/html"}, ["<p>Hello Rack!</p>"]]
8
+ end
9
+ end
10
+
11
+ use Rack::DevFavicon
12
+
13
+ assets = File.expand_path("../../spec/assets", __FILE__)
14
+
15
+ map "/favicon.png" do
16
+ run Rack::File.new("#{assets}/favicon.png")
17
+ end
18
+
19
+ map "/favicon.ico" do
20
+ run Rack::File.new("#{assets}/favicon.ico")
21
+ end
22
+
23
+ run HelloWorld
@@ -0,0 +1,34 @@
1
+
2
+ require 'rack-devfavicon/version'
3
+ require 'rack'
4
+ require 'rmagick'
5
+
6
+ module Rack
7
+ class DevFavicon
8
+ def initialize(app, options = {})
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ unless env['PATH_INFO'] =~ %r{\A /favicon\.(?:png|ico) \z}xm
14
+ return @app.call(env)
15
+ end
16
+
17
+ env.delete('HTTP_IF_MODIFIED_SINCE') # do not cache the icon file
18
+
19
+ status, headers, response = @app.call(env)
20
+
21
+ data = ''
22
+ response.each do |buf|
23
+ data << buf
24
+ end
25
+
26
+ img = Magick::Image.from_blob(data) do |info|
27
+ info.format = headers['Content-Type'] =~ /png/ ? 'PNG' : 'ICO'
28
+ end[0]
29
+ img = img.quantize(4, Magick::GRAYColorspace)
30
+
31
+ [status, headers, [img.to_blob]]
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ class DevFavicon
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rack-devfavicon/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rack-devfavicon"
8
+ spec.version = Rack::DevFavicon::VERSION
9
+ spec.authors = ["Fuji, Goro"]
10
+ spec.email = ["gfuji@cpan.org"]
11
+ spec.description = %q{A rack middleware to show gray-scaled favicon on development}
12
+ spec.summary = spec.description
13
+ spec.homepage = "https://github.com/gfx/rack-devfavicon/"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
Binary file
Binary file
@@ -0,0 +1,50 @@
1
+
2
+ require 'rack'
3
+ require 'rack/test'
4
+ require 'rack-devfavicon'
5
+
6
+ describe Rack::DevFavicon do
7
+ include Rack::Test::Methods
8
+
9
+ let(:app) do
10
+ Rack::Builder.new do
11
+ use Rack::DevFavicon
12
+
13
+ assets = File.expand_path("../assets", __FILE__)
14
+ map '/favicon.ico' do
15
+ run Rack::File.new("#{assets}/favicon.ico")
16
+ end
17
+ map '/favicon.png' do
18
+ run Rack::File.new("#{assets}/favicon.png")
19
+ end
20
+
21
+ map '/orig_favicon.ico' do
22
+ run Rack::File.new("#{assets}/favicon.ico")
23
+ end
24
+ map '/orig_favicon.png' do
25
+ run Rack::File.new("#{assets}/favicon.png")
26
+ end
27
+
28
+ run lambda { |env| [200, "text/plain", ["Hello, Rack!"]] }
29
+ end
30
+ end
31
+
32
+ it "modifies favicon.ico" do
33
+ get '/orig_favicon.ico'
34
+ orig = last_response.body
35
+
36
+ get "/favicon.ico"
37
+
38
+ expect(last_response.body).not_to eq(orig)
39
+ end
40
+
41
+ it "modifies favicon.png" do
42
+ get '/orig_favicon.png'
43
+ orig = last_response.body
44
+
45
+ get "/favicon.png"
46
+
47
+ expect(last_response.body).not_to eq(orig)
48
+ end
49
+
50
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-devfavicon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Fuji, Goro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A rack middleware to show gray-scaled favicon on development
42
+ email:
43
+ - gfuji@cpan.org
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Changes
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - example/config.ru
55
+ - lib/rack-devfavicon.rb
56
+ - lib/rack-devfavicon/version.rb
57
+ - rack-devfavicon.gemspec
58
+ - spec/assets/favicon.ico
59
+ - spec/assets/favicon.png
60
+ - spec/rack-devfavicon_spec.rb
61
+ homepage: https://github.com/gfx/rack-devfavicon/
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.0.3
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: A rack middleware to show gray-scaled favicon on development
85
+ test_files:
86
+ - spec/assets/favicon.ico
87
+ - spec/assets/favicon.png
88
+ - spec/rack-devfavicon_spec.rb
89
+ has_rdoc: