rack-favicon_all 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8b8994b1d37bc0f93e2b80b7b302aeb55da20920
4
+ data.tar.gz: 9e4fbfa7c9b097849b6666d9c82163facee58bdf
5
+ SHA512:
6
+ metadata.gz: 746f9e0a8514db286a8a9f1ff57cab9bc1ffd24fca1f250d3eb62526b2e83a4737780214fadc9fede049a6cf1f73b7694a225dcb9d33ac7854cd37bf70249d85
7
+ data.tar.gz: 0c2a9bc96835bbcb1f836571d676ca522ec1571d2e2c791aaf053683b654a08f9c9b9a5ffb916656390e41347bf0a0fc7be95cc890b9fdeb6f7a5739d5fc85e9
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .consolerc
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rack-favicon_all.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'pry'
8
+ end
9
+ group :test do
10
+ gem 'bundler'
11
+ gem 'rake'
12
+ gem 'rack'
13
+ #gem 'coveralls', require: false
14
+ gem 'rspec'
15
+ gem 'simplecov', require: false
16
+ gem 'simplecov-rcov', require: false
17
+ end
18
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright 2015 haruyama-makoto
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.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Rack::FaviconAll
2
+ This is a Ruby version of [bayashi/Plack-Middleware-Favicon](https://github.com/bayashi/Plack-Middleware-Favicon)
3
+
4
+ Generate favicons for IE, FF, Chrome, Safari!
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'rack-favicon_all'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install rack-favicon_all
21
+
22
+ ## Usage
23
+
24
+ In Gemfile
25
+
26
+ ```
27
+ gem 'rack-favicon_all'
28
+ ```
29
+
30
+ And write in config.ru below
31
+
32
+ ```
33
+ require 'rack/favicon_all'
34
+ use Rack::FaviconAll, favicon_path: "path/to/favicon.png"
35
+ ```
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it ( https://github.com/[my-github-username]/rack-favicon_all/fork )
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :default => :test
4
+
5
+ task :test do
6
+ require 'rspec/core'
7
+ require 'rspec/core/rake_task'
8
+ RSpec::Core::RakeTask.new(:test) do |spec|
9
+ spec.pattern = FileList['spec/**/*_spec.rb']
10
+ end
11
+ end
12
+
@@ -0,0 +1,8 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $:.unshift(File.dirname(__FILE__))
3
+
4
+ require 'rack/favicon_all'
5
+ require 'hello_world'
6
+
7
+ use Rack::FaviconAll, favicon_path: "./icon.png"
8
+ run HelloWorld.new
@@ -0,0 +1,6 @@
1
+ class HelloWorld
2
+ def call(env)
3
+ [200, {"Content-Type" => "text/html"}, [%Q{<html><head><link href="/favicon.ico" rel="shortcut icon" /></head><body>hello</body></html>}]]
4
+ end
5
+ end
6
+
data/examples/icon.png ADDED
Binary file
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ class FaviconAll
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,58 @@
1
+ require 'rmagick'
2
+ require 'rack/favicon_all/version'
3
+ require 'pry'
4
+
5
+ module Rack
6
+ class FaviconAll
7
+ FAVICON = [
8
+ { path: /\A\/favicon\.ico/, size: [16, 16], mime_type: 'image/x-icon', format: 'ICO' },
9
+ { path: /\A\/favicon-16x16\.png/, size: [16, 16] },
10
+ { path: /\A\/favicon-32x32\.png/, size: [32, 32] },
11
+ { path: /\A\/favicon-96x96\.png/, size: [96, 96] },
12
+ { path: /\A\/favicon-160x160\.png/, size: [160, 160] },
13
+ { path: /\A\/favicon-196x196\.png/, size: [196, 196] },
14
+ { path: /\A\/mstile-70x70\.png/, size: [70, 70] },
15
+ { path: /\A\/mstile-144x144\.png/, size: [144, 144] },
16
+ { path: /\A\/mstile-150x150\.png/, size: [150, 150] },
17
+ { path: /\A\/mstile-310x310\.png/, size: [310, 310] },
18
+ { path: /\A\/mstile-310x150\.png/, size: [310, 150] },
19
+ { path: /\A\/apple-touch-icon-57x57\.png/, size: [57, 57] },
20
+ { path: /\A\/apple-touch-icon-60x60\.png/, size: [60, 60] },
21
+ { path: /\A\/apple-touch-icon-72x72\.png/, size: [72, 72] },
22
+ { path: /\A\/apple-touch-icon-76x76\.png/, size: [76, 76] },
23
+ { path: /\A\/apple-touch-icon-114x114\.png/, size: [114, 114] },
24
+ { path: /\A\/apple-touch-icon-120x120\.png/, size: [120, 120] },
25
+ { path: /\A\/apple-touch-icon-144x144\.png/, size: [144, 144] },
26
+ { path: /\A\/apple-touch-icon-152x152\.png/, size: [152, 152] },
27
+ { path: /\A\/apple-touch-icon\.png/, size: [57, 57] },
28
+ { path: /\A\/apple-touch-icon-precomposed\.png/, size: [57, 57] },
29
+ ]
30
+ def initialize(app, options = {})
31
+ @app = app
32
+ @favicon_path = options[:favicon_path]
33
+ @image = Magick::Image.read(@favicon_path).first unless @favicon_path.nil?
34
+ end
35
+
36
+ def call(env)
37
+ status, headers, body = @app.call(env)
38
+ return [status, headers, body] if @image.nil?
39
+
40
+ favicon_info = FAVICON.find { |f| env['PATH_INFO'] =~ f[:path] }
41
+
42
+ return [status, headers, body] if favicon_info.nil?
43
+
44
+ body = genarate_favicon(favicon_info)
45
+ headers["Content-Length"] = body.bytesize.to_s
46
+ headers["Content-Type"] = favicon_info[:mime_type] || "imgae/png"
47
+ [status, headers, [body]]
48
+ end
49
+
50
+ private
51
+
52
+ def genarate_favicon(info)
53
+ @image.scale!(*info[:size]).to_blob do
54
+ self.format = info[:format] unless info[:format].nil?
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rack/favicon_all/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rack-favicon_all"
8
+ spec.version = Rack::FaviconAll::VERSION
9
+ spec.authors = ["SpringMT"]
10
+ spec.email = ["today.is.sky.blue.sky@gmail.com"]
11
+
12
+ spec.required_rubygems_version = ">= 2.0"
13
+
14
+ spec.summary = %q{Generate favicons for IE, FF, Chrome, Safari!}
15
+ spec.description = %q{Generate favicons for IE, FF, Chrome, Safari!}
16
+ spec.homepage = "https://github.com/SpringMT/rack-favicon_all"
17
+ spec.license = "MIT"
18
+
19
+ spec.files = `git ls-files -z`.split("\x0")
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency 'rmagick'
25
+ spec.add_development_dependency "bundler", "~> 1.7"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ end
@@ -0,0 +1,21 @@
1
+ require 'fileutils'
2
+
3
+ require File.dirname(__FILE__) + '/spec_helper'
4
+
5
+ describe Rack::FaviconAll do
6
+ app = lambda { |env|
7
+ [200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]]
8
+ }
9
+
10
+ context 'confirm to Rack::Lint' do
11
+ subject do
12
+ Rack::Lint.new( Rack::FaviconAll.new(app) )
13
+ end
14
+ it do
15
+ response = Rack::MockRequest.new(subject).get('/')
16
+ expect(response.body).to eq 'Hello, World!'
17
+ end
18
+ end
19
+
20
+ end
21
+
@@ -0,0 +1,13 @@
1
+ require 'bundler'
2
+ Bundler.setup(:default, :test)
3
+ Bundler.require(:default, :test)
4
+
5
+ require 'simplecov'
6
+ require 'simplecov-rcov'
7
+ SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
8
+ SimpleCov.start
9
+
10
+ $TESTING=true
11
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib/rack/')
12
+ require 'rack/favicon_all'
13
+
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-favicon_all
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - SpringMT
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rmagick
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Generate favicons for IE, FF, Chrome, Safari!
56
+ email:
57
+ - today.is.sky.blue.sky@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - examples/config.ru
68
+ - examples/hello_world.rb
69
+ - examples/icon.png
70
+ - lib/rack/favicon_all.rb
71
+ - lib/rack/favicon_all/version.rb
72
+ - rack-favicon_all.gemspec
73
+ - spec/rack-favicon_all_spec.rb
74
+ - spec/spec_helper.rb
75
+ homepage: https://github.com/SpringMT/rack-favicon_all
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '2.0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Generate favicons for IE, FF, Chrome, Safari!
99
+ test_files:
100
+ - spec/rack-favicon_all_spec.rb
101
+ - spec/spec_helper.rb
102
+ has_rdoc: