jekyll-favicon 0.2.6 → 1.0.0.pre.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +5 -5
  2. data/.devcontainer/Dockerfile +20 -0
  3. data/.devcontainer/devcontainer.json +42 -0
  4. data/.github/ISSUE_TEMPLATE/bug_report.md +10 -13
  5. data/.github/PULL_REQUEST_TEMPLATE.md +11 -9
  6. data/.github/workflows/gem-push.yml +40 -0
  7. data/.github/workflows/test.yml +38 -0
  8. data/.gitignore +4 -0
  9. data/.reek.yml +25 -0
  10. data/.vscode/launch.json +16 -0
  11. data/.vscode/settings.json +7 -0
  12. data/.vscode/tasks.json +15 -0
  13. data/CHANGELOG.md +42 -0
  14. data/Gemfile +3 -1
  15. data/README.md +80 -20
  16. data/Rakefile +9 -7
  17. data/bin/console +1 -0
  18. data/bin/debug +22 -0
  19. data/config/jekyll/favicon.yml +115 -0
  20. data/config/jekyll/favicon/static_file.yml +3 -0
  21. data/config/jekyll/favicon/static_file/convertible.yml +42 -0
  22. data/config/jekyll/favicon/static_file/mutable.yml +22 -0
  23. data/config/jekyll/favicon/static_file/referenceable.yml +15 -0
  24. data/config/jekyll/favicon/static_file/sourceable.yml +3 -0
  25. data/config/jekyll/favicon/static_file/taggable.yml +22 -0
  26. data/jekyll-favicon.gemspec +24 -24
  27. data/lib/jekyll-favicon.rb +7 -16
  28. data/lib/jekyll/favicon.rb +19 -16
  29. data/lib/jekyll/favicon/configuration.rb +73 -0
  30. data/lib/jekyll/favicon/configuration/defaults.rb +49 -0
  31. data/lib/jekyll/favicon/generator.rb +10 -74
  32. data/lib/jekyll/favicon/hooks.rb +12 -10
  33. data/lib/jekyll/favicon/static_data_file.rb +17 -0
  34. data/lib/jekyll/favicon/static_file.rb +97 -0
  35. data/lib/jekyll/favicon/static_file/convertible.rb +121 -0
  36. data/lib/jekyll/favicon/static_file/mutable.rb +81 -0
  37. data/lib/jekyll/favicon/static_file/referenceable.rb +22 -0
  38. data/lib/jekyll/favicon/static_file/sourceable.rb +73 -0
  39. data/lib/jekyll/favicon/static_file/taggable.rb +53 -0
  40. data/lib/jekyll/favicon/static_graphic_file.rb +21 -0
  41. data/lib/jekyll/favicon/tag.rb +14 -17
  42. data/lib/jekyll/favicon/utils.rb +43 -0
  43. data/lib/jekyll/favicon/utils/configuration/compact.rb +58 -0
  44. data/lib/jekyll/favicon/utils/configuration/merge.rb +70 -0
  45. data/lib/jekyll/favicon/utils/configuration/patch.rb +49 -0
  46. data/lib/jekyll/favicon/utils/convert.rb +39 -0
  47. data/lib/jekyll/favicon/utils/tag.rb +70 -0
  48. data/lib/jekyll/favicon/version.rb +3 -1
  49. metadata +69 -67
  50. data/.rubocop.yml +0 -5
  51. data/.ruby-version +0 -1
  52. data/.travis.yml +0 -21
  53. data/Gemfile.lock +0 -97
  54. data/lib/browserconfig.rb +0 -54
  55. data/lib/hash.rb +0 -12
  56. data/lib/image.rb +0 -33
  57. data/lib/jekyll/favicon/config/defaults.yml +0 -54
  58. data/lib/jekyll/favicon/icon.rb +0 -73
  59. data/lib/jekyll/favicon/metadata.rb +0 -12
  60. data/lib/jekyll/favicon/templates/chrome.html.erb +0 -5
  61. data/lib/jekyll/favicon/templates/classic.html.erb +0 -8
  62. data/lib/jekyll/favicon/templates/ie.html.erb +0 -4
  63. data/lib/jekyll/favicon/templates/safari.html.erb +0 -8
  64. data/lib/string.rb +0 -14
  65. data/lib/webmanifest.rb +0 -30
data/lib/browserconfig.rb DELETED
@@ -1,54 +0,0 @@
1
- require 'rexml/document'
2
-
3
- # Build browserconfig XML
4
- class Browserconfig
5
- attr_accessor :document
6
-
7
- def load(source_path, config, prefix)
8
- @document = if File.exist? source_path
9
- REXML::Document.new File.read source_path
10
- else
11
- REXML::Document.new
12
- end
13
- add_browserconfig_schema
14
- add_browserconfig_elements config, prefix
15
- end
16
-
17
- def add(path, element, attributes = {}, text = nil)
18
- parent = @document.elements[path]
19
- parent.elements[element] = REXML::Element.new element
20
- attributes.each do |key, value|
21
- parent.elements[element].add_attribute key, value
22
- end
23
- parent.add_text text if text
24
- end
25
-
26
- def dump
27
- output = ''
28
- formatter = REXML::Formatters::Pretty.new 2
29
- formatter.compact = true
30
- formatter.write @document, output
31
- output
32
- end
33
-
34
- private
35
-
36
- def add_browserconfig_schema
37
- browserconfig = @document.elements['browserconfig']
38
- browserconfig ||= @document.elements.add 'browserconfig'
39
- msapplication = browserconfig.elements['msapplication']
40
- msapplication ||= browserconfig.elements.add 'msapplication'
41
- tile = msapplication.elements['tile']
42
- tile || msapplication.elements.add('tile')
43
- end
44
-
45
- def add_browserconfig_elements(config, prefix)
46
- path = 'browserconfig/msapplication/tile'
47
- pathname = Pathname.new prefix
48
- add path, 'square70x70logo', 'src' => pathname.join('favicon-128x128.png')
49
- add path, 'square150x150logo', 'src' => pathname.join('favicon-270x270.png')
50
- add path, 'wide310x150logo', 'src' => pathname.join('favicon-558x270.png')
51
- add path, 'square310x310logo', 'src' => pathname.join('favicon-558x558.png')
52
- add path, 'TileColor', {}, config['tile-color']
53
- end
54
- end
data/lib/hash.rb DELETED
@@ -1,12 +0,0 @@
1
- # Extend Hash with deep find of a key return array
2
- class Hash
3
- def deep_find(target)
4
- keys.collect do |key|
5
- if key == target
6
- self[key]
7
- elsif self[key].is_a? Hash
8
- self[key].deep_find(target)
9
- end
10
- end.compact.flatten
11
- end
12
- end
data/lib/image.rb DELETED
@@ -1,33 +0,0 @@
1
- # Build browserconfig XML
2
- module Image
3
- def self.convert(source, output, options = {})
4
- MiniMagick::Tool::Convert.new do |convert|
5
- options_for convert, options
6
- convert << source
7
- convert << output
8
- end
9
- end
10
-
11
- def self.options_for(convert, options)
12
- convert.flatten
13
- basic_options convert, options
14
- resize_options convert, options
15
- odd_options convert, options
16
- end
17
-
18
- def self.basic_options(convert, options)
19
- convert.background options[:background] if options[:background]
20
- convert.define options[:define] if options[:define]
21
- convert.density options[:density] if options[:density]
22
- convert.alpha options[:alpha] if options[:alpha]
23
- end
24
-
25
- def self.resize_options(convert, options)
26
- convert.resize options[:resize] if options[:resize]
27
- end
28
-
29
- def self.odd_options(convert, options)
30
- convert.gravity 'center' if options[:odd]
31
- convert.extent options[:resize] if options[:odd] && options[:resize]
32
- end
33
- end
@@ -1,54 +0,0 @@
1
- favicon:
2
- source: favicon.svg
3
- path: /assets/images
4
- background: white
5
- apple-touch-icon:
6
- background: white
7
- sizes:
8
- - 57x57
9
- - 76x76
10
- - 120x120
11
- - 152x152
12
- - 167x167
13
- - 180x180
14
- safari-pinned-tab:
15
- mask-icon-color: '#ffffff'
16
- ie:
17
- tile-color: '#ffffff'
18
- sizes:
19
- - 128x128
20
- - 270x270
21
- - 558x270
22
- - 558x558
23
- browserconfig:
24
- source: browserconfig.xml
25
- target: browserconfig.xml
26
- chrome:
27
- sizes:
28
- - 192x192
29
- - 96x96
30
- - 48x48
31
- manifest:
32
- source: manifest.webmanifest
33
- target: manifest.webmanifest
34
- sizes:
35
- - 192x192
36
- - 96x96
37
- - 48x48
38
- classic:
39
- sizes:
40
- - 16x16
41
- - 32x32
42
- - 64x64
43
- - 144x144
44
- svg:
45
- density: 2000
46
- dimensions: 1024x1024
47
- png:
48
- dimensions: 558x558
49
- ico:
50
- target: favicon.ico
51
- sizes:
52
- - 48x48
53
- - 32x32
54
- - 16x16
@@ -1,73 +0,0 @@
1
- module Jekyll
2
- module Favicon
3
- # Extended static file that generates multpiple favicons
4
- class Icon < Jekyll::StaticFile
5
- attr_accessor :replica
6
- attr_accessor :target
7
-
8
- def initialize(site, source, replica, target, collection = nil)
9
- @site = site
10
- @base = @site.source
11
- @dir = File.dirname source
12
- @name = File.basename source
13
- @replica = replica
14
- @target = target
15
- @collection = collection
16
- @relative_path = File.join(*[@dir, @name].compact)
17
- @extname = File.extname(target)
18
- @data = { 'name' => File.basename(target), 'layout' => nil }
19
- end
20
-
21
- def destination(dest)
22
- basename = File.basename(@target)
23
- @site.in_dest_dir(*[dest, destination_rel_dir, basename].compact)
24
- end
25
-
26
- def destination_rel_dir
27
- File.dirname @target
28
- end
29
-
30
- private
31
-
32
- def copy_file(dest_path)
33
- case @extname
34
- when '.svg' then FileUtils.cp @replica, dest_path
35
- when '.ico' then Image.convert @replica, dest_path, ico_options
36
- when '.png' then Image.convert @replica, dest_path, png_options
37
- else Jekyll.logger.warn "Jekyll::Favicon: Can't generate" \
38
- " #{dest_path}, extension not supported supported."
39
- end
40
- end
41
-
42
- def dimensions
43
- basename = File.basename(@target)
44
- basename[/favicon-(\d+x\d+).png/, 1].split('x').collect(&:to_i)
45
- end
46
-
47
- def png_options
48
- options = {}
49
- w, h = dimensions
50
- options[:background] = background_for dimensions
51
- options[:odd] = w != h
52
- options[:resize] = dimensions.join('x')
53
- options
54
- end
55
-
56
- def ico_options
57
- options = {}
58
- sizes = Favicon.config['ico']['sizes']
59
- options[:background] = background_for sizes.first
60
- options[:resize] = sizes.first
61
- ico_sizes = sizes.collect { |size| size.split('x').first }.join ','
62
- options[:define] = "icon:auto-resize=#{ico_sizes}"
63
- options
64
- end
65
-
66
- def background_for(size)
67
- category = Favicon.config['apple-touch-icon']
68
- return category['background'] if category['sizes'].include? size
69
- Favicon.config['background']
70
- end
71
- end
72
- end
73
- end
@@ -1,12 +0,0 @@
1
- module Jekyll
2
- module Favicon
3
- # Extended Page that generate files from ERB templates
4
- class Metadata < Jekyll::Page
5
- # rubocop:disable Naming/MemoizedInstanceVariableName
6
- def read_yaml(*)
7
- @data ||= {}
8
- end
9
- # rubocop:enable Naming/MemoizedInstanceVariableName
10
- end
11
- end
12
- end
@@ -1,5 +0,0 @@
1
- <!-- Chrome -->
2
- <%- Favicon.config['chrome']['sizes'].each do |size| -%>
3
- <link rel="icon" sizes="<%= size %>" href="<%= File.join prepend_path, Favicon.config['path'], "favicon-#{size}.png" %>">
4
- <%- end -%>
5
- <link rel="manifest" href="<%= File.join prepend_path, Favicon.config['chrome']['manifest']['target'] %>">
@@ -1,8 +0,0 @@
1
- <!-- Classic -->
2
- <%- favicon_ico_path = File.join prepend_path, Favicon.config['ico']['target'] -%>
3
- <link rel="shortcut icon" href="<%= favicon_ico_path %>">
4
- <link rel="icon" sizes="<%= Favicon.config['ico']['sizes'].join ' ' %>" href="<%= favicon_ico_path %>">
5
- <%- favicon_path = File.join prepend_path, Favicon.config['path'] -%>
6
- <%- Favicon.config['classic']['sizes'].each do |size| -%>
7
- <link rel="icon" sizes="<%= size %>" type="image/png" href="<%= File.join favicon_path, "favicon-#{size}.png" %>">
8
- <%- end -%>
@@ -1,4 +0,0 @@
1
- <!-- IE -->
2
- <meta name="msapplication-TileColor" content="<%= Favicon.config['ie']['tile-color'] %>">
3
- <meta name="msapplication-TileImage" content="<%= File.join prepend_path, Favicon.config['path'], 'favicon-144x144.png' %>">
4
- <meta name='msapplication-config' content="<%= File.join prepend_path, Favicon.config['ie']['browserconfig']['target'] %>">
@@ -1,8 +0,0 @@
1
- <!-- Safari -->
2
- <%- favicon_path = File.join prepend_path, Favicon.config['path'] -%>
3
- <%- Favicon.config['apple-touch-icon']['sizes'].each do |size| -%>
4
- <link rel="apple-touch-icon" sizes="<%= size %>" href="<%= File.join favicon_path, "favicon-#{size}.png" %>">
5
- <%- end -%>
6
- <% if Favicon.config['source'].svg? %>
7
- <link rel="mask-icon" color="<%= Favicon.config['safari-pinned-tab']['mask-icon-color'] %>" href="<%= File.join favicon_path, 'safari-pinned-tab.svg' %>">
8
- <% end %>
data/lib/string.rb DELETED
@@ -1,14 +0,0 @@
1
- # Extend String with extnames utils
2
- class String
3
- def svg?
4
- ['.svg'].include? File.extname self
5
- end
6
-
7
- def png?
8
- ['.png'].include? File.extname self
9
- end
10
-
11
- def ico?
12
- ['.ico'].include? File.extname self
13
- end
14
- end
data/lib/webmanifest.rb DELETED
@@ -1,30 +0,0 @@
1
- # Build Webmanifest JSON
2
- class Webmanifest
3
- attr_accessor :document
4
-
5
- def load(source_path, config, prefix)
6
- @document = if File.exist? source_path
7
- JSON.parse File.read source_path
8
- else
9
- {}
10
- end
11
- add_webmanifest_elements config, prefix
12
- end
13
-
14
- def dump
15
- JSON.pretty_generate document
16
- end
17
-
18
- private
19
-
20
- def add_webmanifest_elements(config, prefix)
21
- icons = config['sizes'].collect do |size|
22
- {
23
- src: File.join(prefix, "favicon-#{size}.png"),
24
- type: 'png',
25
- sizes: size
26
- }
27
- end
28
- @document = Jekyll::Utils.deep_merge_hashes @document, icons: icons
29
- end
30
- end