all-the-favicons 0.5.0

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: 6d0bf47052f42ede4c587bf5758bab357db7511d
4
+ data.tar.gz: b99d92a36162a80b6db50726a868c62edb59ad5c
5
+ SHA512:
6
+ metadata.gz: e2fb26d4bdcd3b4b6f8527950ba6cb8278291dde862bea9f5336c72290af008cb76ead93222bfa7dee05525671c51ace4366538da254a7fb7f70e6313d93e9ff
7
+ data.tar.gz: 8b9538d3cf478c9d02df570f082130c2cf82689bf9ed0ad90600c597ab673bf466f90c3da8a66ed2d79c28158dfe227c009682d090645a5eb8d810053dd1658d
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Kord AS
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # All The Favicons
2
+
3
+ The favicon sitation is getting out of hand. 25+ variants?
4
+ browserconfig.xml? manifest.json?
5
+
6
+ This gem handles the Rails stuff, all you need to do is generate the images.
7
+
8
+ ## Usage
9
+
10
+ Add `all-the-favicons` to your Gemfile:
11
+
12
+ ``` ruby
13
+ gem "all-the-favicons"
14
+ ```
15
+
16
+ Generate all your icons using something like the
17
+ [Real Favicon Generator](http://realfavicongenerator.net), and put
18
+ the files in `app/assets/favicons`.
19
+
20
+ Add the helper to your layout somewhere in the `<head>` tag:
21
+
22
+ ``` html
23
+ <%= all_the_favicons %>
24
+ ```
25
+
26
+ ## Configuration
27
+
28
+ You can configure colors by adding an initializer (ie
29
+ `app/config/initializers/favicons.rb`).
30
+
31
+ ``` ruby
32
+ AllTheFavicons.name = "MyApp" # For the Android Chrome manifest
33
+ AllTheFavicons.ms_tile_color = "#2d89ef"
34
+ AllTheFavicons.pinned_tab_color = "#000000"
35
+ AllTheFavicons.theme_color = "#ffffff"
36
+ ```
37
+
38
+ ## License
39
+
40
+ all-the-favicons is licensed under the
41
+ [MIT License](http://www.opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task default: :spec
4
+ task test: :spec
@@ -0,0 +1,23 @@
1
+ class FaviconsController < ActionController::Base
2
+ def browserconfig
3
+ @tile_color = AllTheFavicons.ms_tile_color
4
+ @tiles = AllTheFavicons::Tiles.all
5
+ end
6
+
7
+ def manifest
8
+ render json: {
9
+ name: AllTheFavicons.name,
10
+ icons: AllTheFavicons::Android.all.map { |i| android_icon(i) }
11
+ }.to_json
12
+ end
13
+
14
+ private
15
+
16
+ def android_icon(icon)
17
+ icon.merge(src: asset_path(icon[:src]))
18
+ end
19
+
20
+ def asset_path(path)
21
+ ActionController::Base.helpers.asset_path(path)
22
+ end
23
+ end
@@ -0,0 +1,50 @@
1
+ module FaviconsHelper
2
+ def all_the_favicons
3
+ icons = apple_favicons + standard_favicons + [
4
+ tag(:link, rel: "manifest", href: favicons_manifest_path),
5
+ pinned_tab_favicon,
6
+ tag(:meta,
7
+ name: "msapplication-TileColor",
8
+ content: AllTheFavicons.ms_tile_color),
9
+ tile_image_favicon,
10
+ tag(:meta, name: "theme-color", content: AllTheFavicons.theme_color)
11
+ ]
12
+ safe_join(icons.compact, "\n")
13
+ end
14
+
15
+ private
16
+
17
+ def apple_favicons
18
+ AllTheFavicons::Apple.all.map do |i|
19
+ tag(:link,
20
+ rel: "apple-touch-icon",
21
+ sizes: i[:sizes],
22
+ href: asset_path(i[:src]))
23
+ end
24
+ end
25
+
26
+ def tile_image_favicon
27
+ return nil unless AllTheFavicons::Tiles.tile_image?
28
+ tag(:meta,
29
+ name: "msapplication-TileImage",
30
+ content: asset_path(AllTheFavicons::Tiles.tile_image))
31
+ end
32
+
33
+ def pinned_tab_favicon
34
+ return nil unless AllTheFavicons::Apple.pinned_tab_icon?
35
+ tag(:link,
36
+ rel: "mask-icon",
37
+ href: asset_path(AllTheFavicons::Apple.pinned_tab_icon),
38
+ color: AllTheFavicons.pinned_tab_color)
39
+ end
40
+
41
+ def standard_favicons
42
+ AllTheFavicons::Favicons.all.map do |i|
43
+ tag(:link,
44
+ rel: "icon",
45
+ type: i[:type],
46
+ sizes: i[:sizes],
47
+ href: asset_path(i[:src]))
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <browserconfig>
3
+ <msapplication>
4
+ <tile>
5
+ <% @tiles.each do |icon| %>
6
+ <<%= icon[:name] %> src="<%= asset_path(icon[:src]) %>"/>
7
+ <% end %>
8
+ <% if @tile_color %>
9
+ <TileColor><%= @tile_color %></TileColor>
10
+ <% end %>
11
+ </tile>
12
+ </msapplication>
13
+ </browserconfig>
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ Rails.application.routes.draw do
2
+ get("/browserconfig.xml" => "favicons#browserconfig",
3
+ defaults: { format: "xml" })
4
+ get("/manifest.json" => "favicons#manifest",
5
+ defaults: { format: "json" }, as: "favicons_manifest")
6
+ end
@@ -0,0 +1 @@
1
+ require "all_the_favicons"
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+
3
+ require "vector2d"
4
+
5
+ require "all_the_favicons/engine"
6
+ require "all_the_favicons/base"
7
+ require "all_the_favicons/android"
8
+ require "all_the_favicons/apple"
9
+ require "all_the_favicons/favicons"
10
+ require "all_the_favicons/tiles"
11
+ require "all_the_favicons/version"
12
+
13
+ module AllTheFavicons
14
+ class << self
15
+ attr_accessor :ms_tile_color, :name, :pinned_tab_color, :theme_color
16
+
17
+ def ms_tile_color
18
+ @ms_tile_color || "#2d89ef"
19
+ end
20
+
21
+ def name
22
+ @name || Rails.application.class.parent_name
23
+ end
24
+
25
+ def pinned_tab_color
26
+ @pinned_tab_color || "#000000"
27
+ end
28
+
29
+ def theme_color
30
+ @theme_color || "#ffffff"
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,9 @@
1
+ module AllTheFavicons
2
+ class Android < AllTheFavicons::Base
3
+ class << self
4
+ def all
5
+ files(/^android-chrome/).map { |f| icon(f) }
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ module AllTheFavicons
2
+ class Apple < AllTheFavicons::Base
3
+ class << self
4
+ def all
5
+ files(/^apple.*\d+x\d+/).map { |f| icon(f) }
6
+ end
7
+
8
+ def pinned_tab_icon
9
+ files(/^safari-pinned-tab/).first
10
+ end
11
+
12
+ def pinned_tab_icon?
13
+ pinned_tab_icon ? true : false
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,51 @@
1
+ module AllTheFavicons
2
+ class Base
3
+ class << self
4
+ private
5
+
6
+ def assets_root
7
+ Rails.root.join("app", "assets", "favicons")
8
+ end
9
+
10
+ def content_type(str)
11
+ case File.extname(str.downcase)
12
+ when ".gif"
13
+ "image/gif"
14
+ when ".ico"
15
+ "image/x-icon"
16
+ when ".svg"
17
+ "image/svg+xml"
18
+ when ".png"
19
+ "image/png"
20
+ when ".jpg", ".jpeg"
21
+ "image/jpeg"
22
+ end
23
+ end
24
+
25
+ def density(str)
26
+ dimensions(str).x / 48.0
27
+ end
28
+
29
+ def dimensions(str)
30
+ Vector2d.parse(str.match(/\d+x\d+/)[0]).to_i_vector
31
+ end
32
+
33
+ def files(expr = nil)
34
+ return [] unless File.exist?(assets_root)
35
+ files = Dir.entries(assets_root)
36
+ .select { |f| f =~ /\.(jpg|jpeg|png|gif|ico|svg)$/ }
37
+ return files unless expr
38
+ files.select { |f| f =~ expr }
39
+ end
40
+
41
+ def icon(f)
42
+ {
43
+ src: f,
44
+ sizes: dimensions(f).to_s,
45
+ type: content_type(f),
46
+ density: density(f)
47
+ }
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+
3
+ module AllTheFavicons
4
+ class Engine < ::Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ module AllTheFavicons
2
+ class Favicons < AllTheFavicons::Base
3
+ class << self
4
+ def all
5
+ files(/^(favicon.*\d+x\d+|android-chrome-192x192)/).map { |f| icon(f) }
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,33 @@
1
+ module AllTheFavicons
2
+ class Tiles < AllTheFavicons::Base
3
+ class << self
4
+ def all
5
+ files(/^mstile/).map { |f| ms_icon(f) }
6
+ end
7
+
8
+ def tile_image
9
+ files(/^mstile-144x144/).first
10
+ end
11
+
12
+ def tile_image?
13
+ tile_image ? true : false
14
+ end
15
+
16
+ private
17
+
18
+ def ms_icon(f)
19
+ icon(f).merge(name: tile_name(f))
20
+ end
21
+
22
+ def square?(v)
23
+ v.x == v.y
24
+ end
25
+
26
+ def tile_name(f)
27
+ (square?(dimensions(f)) ? "square" : "wide") +
28
+ dimensions(f).to_s +
29
+ "logo"
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+
3
+ module AllTheFavicons
4
+ VERSION = "0.5.0".freeze
5
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: all-the-favicons
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Inge Jørgensen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: vector2d
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.2'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 2.2.1
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '2.2'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 2.2.1
47
+ description: A Rails engine that outputs favicons through the assets pipeline
48
+ email:
49
+ - inge@kord.no
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - MIT-LICENSE
55
+ - README.md
56
+ - Rakefile
57
+ - app/controllers/favicons_controller.rb
58
+ - app/helpers/favicons_helper.rb
59
+ - app/views/favicons/browserconfig.xml.erb
60
+ - config/routes.rb
61
+ - lib/all-the-favicons.rb
62
+ - lib/all_the_favicons.rb
63
+ - lib/all_the_favicons/android.rb
64
+ - lib/all_the_favicons/apple.rb
65
+ - lib/all_the_favicons/base.rb
66
+ - lib/all_the_favicons/engine.rb
67
+ - lib/all_the_favicons/favicons.rb
68
+ - lib/all_the_favicons/tiles.rb
69
+ - lib/all_the_favicons/version.rb
70
+ homepage: https://github.com/kord-as/all-the-favicons
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.9.2
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.4.5
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Favicons for the Rails assets pipeline
94
+ test_files: []