jekyll-favicon 1.0.0.pre.1 → 1.0.0.pre.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer/Dockerfile +1 -1
  3. data/.devcontainer/devcontainer.json +11 -4
  4. data/.github/workflows/test.yml +5 -5
  5. data/.gitignore +1 -2
  6. data/.reek.yml +25 -0
  7. data/.vscode/launch.json +16 -0
  8. data/.vscode/settings.json +7 -0
  9. data/.vscode/tasks.json +15 -0
  10. data/CHANGELOG.md +4 -0
  11. data/Gemfile +1 -1
  12. data/README.md +3 -3
  13. data/Rakefile +4 -4
  14. data/bin/debug +22 -0
  15. data/jekyll-favicon.gemspec +23 -23
  16. data/lib/jekyll-favicon.rb +5 -7
  17. data/lib/jekyll/favicon.rb +13 -16
  18. data/lib/jekyll/favicon/configuration.rb +11 -11
  19. data/lib/jekyll/favicon/configuration/defaults.rb +6 -6
  20. data/lib/jekyll/favicon/generator.rb +5 -6
  21. data/lib/jekyll/favicon/hooks.rb +4 -4
  22. data/lib/jekyll/favicon/static_data_file.rb +2 -2
  23. data/lib/jekyll/favicon/static_file.rb +18 -18
  24. data/lib/jekyll/favicon/static_file/convertible.rb +30 -27
  25. data/lib/jekyll/favicon/static_file/mutable.rb +16 -16
  26. data/lib/jekyll/favicon/static_file/referenceable.rb +2 -2
  27. data/lib/jekyll/favicon/static_file/sourceable.rb +7 -7
  28. data/lib/jekyll/favicon/static_file/taggable.rb +8 -14
  29. data/lib/jekyll/favicon/static_graphic_file.rb +2 -2
  30. data/lib/jekyll/favicon/tag.rb +9 -10
  31. data/lib/jekyll/favicon/utils.rb +24 -5
  32. data/lib/jekyll/favicon/utils/configuration/compact.rb +29 -32
  33. data/lib/jekyll/favicon/utils/configuration/merge.rb +41 -34
  34. data/lib/jekyll/favicon/utils/configuration/patch.rb +24 -23
  35. data/lib/jekyll/favicon/utils/convert.rb +15 -18
  36. data/lib/jekyll/favicon/utils/tag.rb +44 -28
  37. data/lib/jekyll/favicon/version.rb +1 -1
  38. metadata +7 -9
  39. data/gemfiles/jekyll36.gemfile +0 -6
  40. data/gemfiles/jekyll37.gemfile +0 -6
  41. data/gemfiles/jekyll38.gemfile +0 -6
  42. data/gemfiles/jekyll39.gemfile +0 -6
  43. data/gemfiles/jekyll40.gemfile +0 -6
  44. data/gemfiles/jekyll41.gemfile +0 -6
  45. data/gemfiles/jekyll42.gemfile +0 -6
@@ -1,18 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'jekyll/plugin'
4
- require 'jekyll/generator'
5
- require 'jekyll/favicon'
3
+ require "jekyll/plugin"
4
+ require "jekyll/generator"
5
+ require "jekyll/favicon"
6
6
 
7
7
  module Jekyll
8
8
  module Favicon
9
9
  # New generator that creates all the stastic icons and metadata files
10
10
  class Generator < Jekyll::Generator
11
- # :reek:UtilityFunction
12
11
  def generate(site)
13
12
  Favicon.assets(site)
14
- .select(&:generable?)
15
- .each { |asset| site.static_files << asset }
13
+ .select(&:generable?)
14
+ .each { |asset| site.static_files << asset }
16
15
  end
17
16
  end
18
17
  end
@@ -1,16 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'jekyll/hooks'
3
+ require "jekyll/hooks"
4
4
 
5
5
  Jekyll::Hooks.register :site, :after_init do |site|
6
6
  static_files = Jekyll::Favicon.assets(site)
7
- .uniq(&:path)
8
- excludes = site.config['exclude']
7
+ .uniq(&:path)
8
+ excludes = site.config["exclude"]
9
9
  static_files.each do |static_file|
10
10
  source = static_file.source_relative_path
11
11
  excludes << source and next if static_file.generable?
12
12
 
13
13
  Jekyll.logger.warn Jekyll::Favicon,
14
- "Missing #{source}, not generating favicons."
14
+ "Missing #{source}, not generating favicons."
15
15
  end
16
16
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'jekyll/favicon/static_file'
4
- require 'jekyll/favicon/static_file/mutable'
3
+ require "jekyll/favicon/static_file"
4
+ require "jekyll/favicon/static_file/mutable"
5
5
 
6
6
  module Jekyll
7
7
  module Favicon
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'pathname'
4
- require 'forwardable'
5
- require 'jekyll/static_file'
6
- require 'jekyll/favicon/static_file/sourceable'
7
- require 'jekyll/favicon/static_file/taggable'
8
- require 'jekyll/favicon/static_file/referenceable'
9
- require 'jekyll/favicon/utils'
10
- require 'jekyll/favicon/configuration'
3
+ require "pathname"
4
+ require "forwardable"
5
+ require "jekyll/static_file"
6
+ require "jekyll/favicon/static_file/sourceable"
7
+ require "jekyll/favicon/static_file/taggable"
8
+ require "jekyll/favicon/static_file/referenceable"
9
+ require "jekyll/favicon/utils"
10
+ require "jekyll/favicon/configuration"
11
11
 
12
12
  module Jekyll
13
13
  module Favicon
@@ -23,7 +23,7 @@ module Jekyll
23
23
  attr_reader :spec, :site
24
24
 
25
25
  def initialize(site, spec = {})
26
- raise StandardError unless spec.include? 'name'
26
+ raise StandardError unless spec.include? "name"
27
27
 
28
28
  @spec = spec
29
29
  spec_dir, spec_name = File.split spec_relative_path
@@ -43,9 +43,9 @@ module Jekyll
43
43
  end
44
44
 
45
45
  def href
46
- Pathname.new('/')
47
- .join(url)
48
- .to_s
46
+ Pathname.new("/")
47
+ .join(*[site.baseurl, url].compact)
48
+ .to_s
49
49
  end
50
50
 
51
51
  private
@@ -62,11 +62,11 @@ module Jekyll
62
62
  end
63
63
 
64
64
  def site_dir
65
- site_configuration.fetch('dir', '.')
65
+ site_configuration.fetch("dir", ".")
66
66
  end
67
67
 
68
68
  def site_background
69
- site_configuration.fetch('background', 'transparent')
69
+ site_configuration.fetch("background", "transparent")
70
70
  end
71
71
 
72
72
  def site_configuration
@@ -80,17 +80,17 @@ module Jekyll
80
80
  def spec_relative_pathname
81
81
  return spec_pathname if spec_pathname.relative?
82
82
 
83
- pathname.relative_path_from '/'
83
+ pathname.relative_path_from "/"
84
84
  end
85
85
 
86
86
  def spec_pathname
87
87
  Pathname.new(site_dir)
88
- .join(*spec_dir_name)
88
+ .join(*spec_dir_name)
89
89
  end
90
90
 
91
91
  def spec_dir_name
92
- spec.values_at('dir', 'name')
93
- .compact
92
+ spec.values_at("dir", "name")
93
+ .compact
94
94
  end
95
95
  end
96
96
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'jekyll/favicon/configuration/defaults'
4
- require 'jekyll/favicon/utils'
3
+ require "jekyll/favicon/configuration/defaults"
4
+ require "jekyll/favicon/utils"
5
5
 
6
6
  module Jekyll
7
7
  module Favicon
@@ -24,30 +24,28 @@ module Jekyll
24
24
  def convertible_patch(configuration)
25
25
  Utils.patch configuration do |value|
26
26
  case value
27
- when :sizes then sizes.join ' '
27
+ when :sizes then sizes.join " "
28
28
  else value
29
29
  end
30
30
  end
31
31
  end
32
32
 
33
33
  def sizes
34
- if (match = name.match(/^.*-(\d+x\d+)\..*$/)) then [match[1]]
35
- elsif (define = convert_spec['define'])
36
- define.split('=').last.split(',').collect { |size| [size, size].join 'x' }
37
- elsif (resize = convert_spec['resize']) then [resize]
38
- elsif (scale = convert_spec['scale']) then [scale]
34
+ if (match = Utils.name_to_size(name)) then [match[1]]
35
+ elsif (define = Utils.define_to_size(convert_spec["define"])) then define
36
+ elsif (resize = convert_spec["resize"]) then [resize]
37
+ elsif (scale = convert_spec["scale"]) then [scale]
39
38
  end
40
39
  end
41
40
 
42
41
  # Jekyll::StaticFile method
43
42
  # asks if dest mtime is older than source mtime after original modified?
44
43
  def modified?
45
- super || self.class.mtimes[href] < mtime
44
+ super || self.class.mtimes.fetch(href, -1) < mtime
46
45
  end
47
46
 
48
47
  # Jekyll::StaticFile method
49
48
  # adds dest mtime to list after original write
50
- # :reek:ControlParameter
51
49
  def write(dest)
52
50
  super(dest) && self.class.mtimes[href] = mtime
53
51
  end
@@ -58,8 +56,8 @@ module Jekyll
58
56
  # add file creation instead of copying
59
57
  def copy_file(dest_path)
60
58
  case @extname
61
- when '.svg' then super(dest_path)
62
- when '.ico', '.png'
59
+ when ".svg" then super(dest_path)
60
+ when ".ico", ".png"
63
61
  Utils.convert path, dest_path, convert
64
62
  else Jekyll.logger.warn "Jekyll::Favicon: Can't generate " \
65
63
  " #{dest_path}. Extension not supported."
@@ -67,46 +65,51 @@ module Jekyll
67
65
  end
68
66
 
69
67
  def convert_allow_empty?
70
- @extname == '.svg' && @extname == File.extname(path)
68
+ @extname == ".svg" && @extname == File.extname(path)
71
69
  end
72
70
 
73
71
  def convert_spec
74
- spec.fetch 'convert', {}
72
+ spec.fetch "convert", {}
73
+ end
74
+
75
+ def convertible_keys
76
+ convertible_defaults["defaults"].keys
75
77
  end
76
78
 
77
79
  def convert_normalize(options)
78
80
  return {} unless options
79
81
 
80
- Utils.compact options.slice(*convertible_defaults['defaults'].keys)
82
+ Utils.slice_and_compact options, convertible_keys
81
83
  end
82
84
 
83
- def convert_defaults
84
- convertible_defaults.dig File.extname(path), @extname
85
+ def convert_patch(options)
86
+ patched_options = convert_patch_options options
87
+ Utils.slice_and_compact patched_options, convertible_keys
85
88
  end
86
89
 
87
- # :reek:FeatureEnvy
88
- def convert_patch(options)
89
- %w[density extent].each do |name|
90
- method = "convert_patch_#{name}".to_sym
91
- options.merge! name => send(method, options[name])
90
+ def convert_patch_options(options)
91
+ %w[density extent].each_with_object(options) do |name, memo|
92
+ method = "convert_patch_option_#{name}".to_sym
93
+ memo[name] = send(method, options[name])
92
94
  end
93
- Utils.compact options.slice(*convertible_defaults['defaults'].keys)
94
95
  end
95
96
 
96
- def convert_patch_density(density)
97
+ def convert_patch_option_density(density)
97
98
  case density
98
99
  when :max
99
- length = sizes.collect { |size| size.split('x').max }.max.to_i
100
+ length = sizes.collect { |size| size.split("x").collect(&:to_i) }
101
+ .flatten
102
+ .max
100
103
  length * 3
101
104
  else density
102
105
  end
103
106
  end
104
107
 
105
- def convert_patch_extent(extent)
108
+ def convert_patch_option_extent(extent)
106
109
  case extent
107
110
  when :auto
108
111
  if (size = sizes.first)
109
- width, height = size.split 'x'
112
+ width, height = size.split "x"
110
113
  size if width != height
111
114
  end
112
115
  else extent
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rexml/document'
4
- require 'jekyll/favicon/utils'
5
- require 'jekyll/favicon/static_graphic_file'
3
+ require "rexml/document"
4
+ require "jekyll/favicon/utils"
5
+ require "jekyll/favicon/static_graphic_file"
6
6
 
7
7
  module Jekyll
8
8
  module Favicon
@@ -15,12 +15,12 @@ module Jekyll
15
15
 
16
16
  def mutation
17
17
  refers = case @extname
18
- when '.xml'
19
- mutation_refers.select { |refer| refer.key? 'browserconfig' }
18
+ when ".xml"
19
+ mutation_refers.select { |refer| refer.key? "browserconfig" }
20
20
  else
21
- mutation_refers.collect { |refer| refer['webmanifest'] }
22
- .compact
23
- end
21
+ mutation_refers.collect { |refer| refer["webmanifest"] }
22
+ .compact
23
+ end
24
24
  patch(Utils.merge(*refers) || {})
25
25
  end
26
26
 
@@ -41,8 +41,8 @@ module Jekyll
41
41
 
42
42
  def mutated_content
43
43
  case @extname
44
- when '.json', '.webmanifest', '.manifest' then mutated_content_json
45
- when '.xml' then mutated_content_xml
44
+ when ".json", ".webmanifest", ".manifest" then mutated_content_json
45
+ when ".xml" then mutated_content_xml
46
46
  end
47
47
  end
48
48
 
@@ -53,7 +53,7 @@ module Jekyll
53
53
 
54
54
  def mutated_content_xml
55
55
  mutated = Utils.mutate_element (mutable || REXML::Document.new), mutation
56
- output = String.new
56
+ output = +""
57
57
  mutated.write output
58
58
  output
59
59
  end
@@ -63,17 +63,17 @@ module Jekyll
63
63
 
64
64
  content = File.read path
65
65
  case File.extname path
66
- when '.xml' then REXML::Document.new content
66
+ when ".xml" then REXML::Document.new content
67
67
  else JSON.parse content
68
68
  end
69
69
  end
70
70
 
71
71
  def mutation_refers
72
72
  site.static_files
73
- .select { |static_file| static_file.is_a? StaticFile }
74
- .select(&:referenceable?)
75
- .collect(&:refer)
76
- .flatten
73
+ .select { |static_file| static_file.is_a? StaticFile }
74
+ .select(&:referenceable?)
75
+ .collect(&:refer)
76
+ .flatten
77
77
  end
78
78
  end
79
79
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'jekyll/favicon/configuration/defaults'
3
+ require "jekyll/favicon/configuration/defaults"
4
4
 
5
5
  module Jekyll
6
6
  module Favicon
@@ -14,7 +14,7 @@ module Jekyll
14
14
  end
15
15
 
16
16
  def refer
17
- patch spec.fetch('refer', [])
17
+ patch spec.fetch("refer", [])
18
18
  end
19
19
  end
20
20
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'jekyll/favicon/configuration/defaults'
4
- require 'jekyll/favicon/utils'
3
+ require "jekyll/favicon/configuration/defaults"
4
+ require "jekyll/favicon/utils"
5
5
 
6
6
  module Jekyll
7
7
  module Favicon
@@ -31,7 +31,7 @@ module Jekyll
31
31
  case options
32
32
  when String
33
33
  source_dir, source_name = File.split options
34
- { 'dir' => source_dir, 'name' => source_name }
34
+ {"dir" => source_dir, "name" => source_name}
35
35
  when Hash
36
36
  Utils.compact options
37
37
  else {}
@@ -39,15 +39,15 @@ module Jekyll
39
39
  end
40
40
 
41
41
  def self.source_filter(options)
42
- options.fetch 'source', {}
42
+ options.fetch "source", {}
43
43
  end
44
44
 
45
45
  private
46
46
 
47
47
  def source_relative_pathname
48
- Pathname.new(source['dir'])
49
- .join(source['name'])
50
- .cleanpath
48
+ Pathname.new(source["dir"])
49
+ .join(source["name"])
50
+ .cleanpath
51
51
  end
52
52
 
53
53
  def source_defaults
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rexml/document'
4
- require 'jekyll/favicon/configuration/defaults'
5
- require 'jekyll/favicon/utils'
3
+ require "rexml/document"
4
+ require "jekyll/favicon/configuration/defaults"
5
+ require "jekyll/favicon/utils"
6
6
 
7
7
  module Jekyll
8
8
  module Favicon
@@ -20,27 +20,21 @@ module Jekyll
20
20
  tag_name, tag_options = options.first
21
21
  tag_defaults = taggable_defaults[tag_name]
22
22
  tag_attributes = tag_defaults.merge tag_options
23
- tag_build tag_name, patch(tag_attributes)
23
+ Utils.build_tag tag_name, patch(tag_attributes)
24
24
  end
25
25
  end
26
26
 
27
27
  private
28
28
 
29
29
  def tag_spec
30
- spec.fetch 'tag', []
31
- end
32
-
33
- # :reek:UtilityFunction
34
- def tag_build(name, attributes = {})
35
- config = attributes.transform_keys { |key| "_#{key}" }
36
- Jekyll::Favicon::Utils.build_element name, nil, config
30
+ spec.fetch "tag", []
37
31
  end
38
32
 
39
33
  def mimetype
40
34
  mappings = {
41
- '.ico' => 'image/x-icon',
42
- '.png' => 'image/png',
43
- '.svg' => 'image/svg+xml'
35
+ ".ico" => "image/x-icon",
36
+ ".png" => "image/png",
37
+ ".svg" => "image/svg+xml"
44
38
  }
45
39
  mappings[extname]
46
40
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'jekyll/favicon/static_file'
4
- require 'jekyll/favicon/static_file/convertible'
3
+ require "jekyll/favicon/static_file"
4
+ require "jekyll/favicon/static_file/convertible"
5
5
 
6
6
  module Jekyll
7
7
  module Favicon
@@ -1,24 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'liquid'
4
- require 'jekyll/favicon/static_file'
3
+ require "liquid"
4
+ require "jekyll/favicon/static_file"
5
5
 
6
6
  module Jekyll
7
7
  module Favicon
8
8
  # New `favicon` tag include html tags on templates
9
9
  class Tag < Liquid::Tag
10
- # :reek:UtilityFunction
11
10
  def render(context)
12
11
  context.registers[:site]
13
- .static_files
14
- .select { |static_file| static_file.is_a? StaticFile }
15
- .select(&:taggable?)
16
- .collect(&:tags)
17
- .flatten
18
- .join("\n")
12
+ .static_files
13
+ .select { |static_file| static_file.is_a? StaticFile }
14
+ .select(&:taggable?)
15
+ .collect(&:tags)
16
+ .flatten
17
+ .join("\n")
19
18
  end
20
19
  end
21
20
  end
22
21
  end
23
22
 
24
- Liquid::Template.register_tag('favicon', Jekyll::Favicon::Tag)
23
+ Liquid::Template.register_tag("favicon", Jekyll::Favicon::Tag)