jekyll-favicon 0.2.5 → 1.0.0.pre.1

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 (66) hide show
  1. checksums.yaml +5 -5
  2. data/.devcontainer/Dockerfile +20 -0
  3. data/.devcontainer/devcontainer.json +35 -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 +5 -0
  9. data/CHANGELOG.md +44 -0
  10. data/Gemfile +2 -0
  11. data/README.md +86 -20
  12. data/Rakefile +9 -7
  13. data/bin/console +1 -0
  14. data/config/jekyll/favicon.yml +115 -0
  15. data/config/jekyll/favicon/static_file.yml +3 -0
  16. data/config/jekyll/favicon/static_file/convertible.yml +42 -0
  17. data/config/jekyll/favicon/static_file/mutable.yml +22 -0
  18. data/config/jekyll/favicon/static_file/referenceable.yml +15 -0
  19. data/config/jekyll/favicon/static_file/sourceable.yml +3 -0
  20. data/config/jekyll/favicon/static_file/taggable.yml +22 -0
  21. data/gemfiles/jekyll36.gemfile +6 -0
  22. data/gemfiles/jekyll37.gemfile +6 -0
  23. data/gemfiles/jekyll38.gemfile +6 -0
  24. data/gemfiles/jekyll39.gemfile +6 -0
  25. data/gemfiles/jekyll40.gemfile +6 -0
  26. data/gemfiles/jekyll41.gemfile +6 -0
  27. data/gemfiles/jekyll42.gemfile +6 -0
  28. data/jekyll-favicon.gemspec +9 -9
  29. data/lib/jekyll-favicon.rb +7 -14
  30. data/lib/jekyll/favicon.rb +19 -13
  31. data/lib/jekyll/favicon/configuration.rb +73 -0
  32. data/lib/jekyll/favicon/configuration/defaults.rb +49 -0
  33. data/lib/jekyll/favicon/generator.rb +11 -74
  34. data/lib/jekyll/favicon/hooks.rb +12 -10
  35. data/lib/jekyll/favicon/static_data_file.rb +17 -0
  36. data/lib/jekyll/favicon/static_file.rb +97 -0
  37. data/lib/jekyll/favicon/static_file/convertible.rb +118 -0
  38. data/lib/jekyll/favicon/static_file/mutable.rb +81 -0
  39. data/lib/jekyll/favicon/static_file/referenceable.rb +22 -0
  40. data/lib/jekyll/favicon/static_file/sourceable.rb +73 -0
  41. data/lib/jekyll/favicon/static_file/taggable.rb +59 -0
  42. data/lib/jekyll/favicon/static_graphic_file.rb +21 -0
  43. data/lib/jekyll/favicon/tag.rb +14 -16
  44. data/lib/jekyll/favicon/utils.rb +24 -0
  45. data/lib/jekyll/favicon/utils/configuration/compact.rb +61 -0
  46. data/lib/jekyll/favicon/utils/configuration/merge.rb +63 -0
  47. data/lib/jekyll/favicon/utils/configuration/patch.rb +48 -0
  48. data/lib/jekyll/favicon/utils/convert.rb +42 -0
  49. data/lib/jekyll/favicon/utils/tag.rb +54 -0
  50. data/lib/jekyll/favicon/version.rb +3 -1
  51. metadata +71 -66
  52. data/.rubocop.yml +0 -5
  53. data/.travis.yml +0 -21
  54. data/Gemfile.lock +0 -97
  55. data/lib/browserconfig.rb +0 -54
  56. data/lib/hash.rb +0 -12
  57. data/lib/image.rb +0 -33
  58. data/lib/jekyll/favicon/config/defaults.yml +0 -54
  59. data/lib/jekyll/favicon/icon.rb +0 -74
  60. data/lib/jekyll/favicon/metadata.rb +0 -12
  61. data/lib/jekyll/favicon/templates/chrome.html.erb +0 -5
  62. data/lib/jekyll/favicon/templates/classic.html.erb +0 -8
  63. data/lib/jekyll/favicon/templates/ie.html.erb +0 -4
  64. data/lib/jekyll/favicon/templates/safari.html.erb +0 -8
  65. data/lib/string.rb +0 -14
  66. data/lib/webmanifest.rb +0 -30
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jekyll/favicon/configuration/defaults'
4
+
5
+ module Jekyll
6
+ module Favicon
7
+ class StaticFile < Jekyll::StaticFile
8
+ # Add reference to a static file
9
+ module Referenceable
10
+ include Configuration::Defaults
11
+
12
+ def referenceable?
13
+ refer.any?
14
+ end
15
+
16
+ def refer
17
+ patch spec.fetch('refer', [])
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jekyll/favicon/configuration/defaults'
4
+ require 'jekyll/favicon/utils'
5
+
6
+ module Jekyll
7
+ module Favicon
8
+ class StaticFile < Jekyll::StaticFile
9
+ # Add source to a static file
10
+ module Sourceable
11
+ include Configuration::Defaults
12
+
13
+ def sourceable?
14
+ source.any? && File.file?(path)
15
+ end
16
+
17
+ def source
18
+ Utils.merge sourceable_defaults, source_site, source_asset
19
+ end
20
+
21
+ # overrides Jekyll::StaticFile method
22
+ def path
23
+ File.join(*[@base, source_relative_path].compact)
24
+ end
25
+
26
+ def source_relative_path
27
+ source_relative_pathname.to_s
28
+ end
29
+
30
+ def self.source_normalize(options)
31
+ case options
32
+ when String
33
+ source_dir, source_name = File.split options
34
+ { 'dir' => source_dir, 'name' => source_name }
35
+ when Hash
36
+ Utils.compact options
37
+ else {}
38
+ end
39
+ end
40
+
41
+ def self.source_filter(options)
42
+ options.fetch 'source', {}
43
+ end
44
+
45
+ private
46
+
47
+ def source_relative_pathname
48
+ Pathname.new(source['dir'])
49
+ .join(source['name'])
50
+ .cleanpath
51
+ end
52
+
53
+ def source_defaults
54
+ sourceable_defaults
55
+ end
56
+
57
+ def source_site
58
+ site_config = Configuration.merged @site
59
+ config = Sourceable.source_filter site_config
60
+ Sourceable.source_normalize config
61
+ end
62
+
63
+ def source_spec
64
+ Sourceable.source_filter spec
65
+ end
66
+
67
+ def source_asset
68
+ Sourceable.source_normalize source_spec
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rexml/document'
4
+ require 'jekyll/favicon/configuration/defaults'
5
+ require 'jekyll/favicon/utils'
6
+
7
+ module Jekyll
8
+ module Favicon
9
+ class StaticFile < Jekyll::StaticFile
10
+ # Add tags to favicon's static files
11
+ module Taggable
12
+ include Configuration::Defaults
13
+
14
+ def taggable?
15
+ tags.any?
16
+ end
17
+
18
+ def tags
19
+ tag_spec.collect do |options|
20
+ tag_name, tag_options = options.first
21
+ tag_defaults = taggable_defaults[tag_name]
22
+ tag_attributes = tag_defaults.merge tag_options
23
+ tag_build tag_name, patch(tag_attributes)
24
+ end
25
+ end
26
+
27
+ private
28
+
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
37
+ end
38
+
39
+ def mimetype
40
+ mappings = {
41
+ '.ico' => 'image/x-icon',
42
+ '.png' => 'image/png',
43
+ '.svg' => 'image/svg+xml'
44
+ }
45
+ mappings[extname]
46
+ end
47
+
48
+ def taggable_patch(configuration)
49
+ Favicon::Utils.patch configuration do |value|
50
+ case value
51
+ when :mime then mimetype
52
+ else value
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jekyll/favicon/static_file'
4
+ require 'jekyll/favicon/static_file/convertible'
5
+
6
+ module Jekyll
7
+ module Favicon
8
+ # Favicon::StaticFile subclass
9
+ class StaticGraphicFile < StaticFile
10
+ include StaticFile::Convertible
11
+
12
+ def generable?
13
+ convertible? && super
14
+ end
15
+
16
+ def patch(configuration)
17
+ convertible_patch super(configuration)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,23 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'liquid'
4
+ require 'jekyll/favicon/static_file'
5
+
1
6
  module Jekyll
2
7
  module Favicon
3
- # New `favicon` tag for favicon include on templates
8
+ # New `favicon` tag include html tags on templates
4
9
  class Tag < Liquid::Tag
5
- def initialize(tag_name, text, tokens)
6
- super
7
- @text = text
8
- end
9
-
10
+ # :reek:UtilityFunction
10
11
  def render(context)
11
- site = context.registers[:site]
12
- prepend_path = site.baseurl || ''
13
- templates_dir = Favicon.templates
14
- head = "<!-- Begin Jekyll Favicon tag v#{Favicon::VERSION} -->"
15
- body = %w[classic safari chrome ie].collect do |template|
16
- template_path = File.join templates_dir, "#{template}.html.erb"
17
- ERB.new(File.read(template_path), nil, '-').result(binding).strip
18
- end
19
- foot = '<!-- End Jekyll Favicon tag -->'
20
- [head, body.join("\n"), foot].join("\n")
12
+ 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")
21
19
  end
22
20
  end
23
21
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jekyll/favicon/utils/configuration/compact'
4
+ require 'jekyll/favicon/utils/configuration/merge'
5
+ require 'jekyll/favicon/utils/configuration/patch'
6
+ require 'jekyll/favicon/utils/convert'
7
+ require 'jekyll/favicon/utils/tag'
8
+
9
+ module Jekyll
10
+ module Favicon
11
+ # Favicon utils functions
12
+ module Utils
13
+ include Configuration::Compact
14
+ include Configuration::Merge
15
+ include Configuration::Patch
16
+ include Convert
17
+ include Tag
18
+
19
+ def self.except(hash, *keys)
20
+ hash.reject { |key, _| keys.include? key }
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Favicon
5
+ module Utils
6
+ module Configuration
7
+ # Favicon configuration compact logic
8
+ module Compact
9
+ def self.included(klass)
10
+ klass.extend(ClassMethods)
11
+ end
12
+
13
+ # Nil and empty remove from configurations
14
+ module ClassMethods
15
+ def compact(compactable)
16
+ case compactable
17
+ when Hash, Array
18
+ compact_deep(compactable) || compactable.class[]
19
+ else
20
+ compactable
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def compact_deep(compactable)
27
+ case compactable
28
+ when Hash then compact_hash compactable
29
+ when Array then compact_array compactable
30
+ else compactable
31
+ end
32
+ end
33
+
34
+ def compact_hash(hash)
35
+ compacted_hash = hash.each_with_object({}) do |(key, value), memo|
36
+ next unless (compacted = compact_deep(value))
37
+
38
+ memo[key] = compacted
39
+ end
40
+ compact_shallow compacted_hash
41
+ end
42
+
43
+ def compact_array(array)
44
+ compacted_array = array.each_with_object([]) do |value, memo|
45
+ next unless (compacted = compact_deep(value))
46
+
47
+ memo << compacted
48
+ end
49
+ compact_shallow compacted_array
50
+ end
51
+
52
+ # :reek:UtilityFunction
53
+ def compact_shallow(compactable)
54
+ compactable.empty? ? nil : compactable.compact
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Favicon
5
+ module Utils
6
+ module Configuration
7
+ # Favicon configuration merge logic
8
+ module Merge
9
+ def self.included(klass)
10
+ klass.extend(ClassMethods)
11
+ end
12
+
13
+ # Merge configurations
14
+ module ClassMethods
15
+ def merge(left = nil, *right_and_or_rest)
16
+ return left if right_and_or_rest.empty?
17
+
18
+ right, *rest = right_and_or_rest
19
+ merged = merge_pair left, right
20
+ return merged if rest.empty?
21
+
22
+ merge(merged, *rest)
23
+ end
24
+
25
+ private
26
+
27
+ def merge_pair(left, right)
28
+ return right if !left || !right || !left.instance_of?(right.class)
29
+
30
+ case right
31
+ when Hash then merge_pair_hash left, right
32
+ when Array then merge_pair_array left, right
33
+ else right
34
+ end
35
+ end
36
+
37
+ def merge_pair_hash(left_hash, right_hash)
38
+ left_hash.merge(right_hash) do |_, left_value, right_value|
39
+ merge left_value, right_value
40
+ end
41
+ end
42
+
43
+ def merge_pair_array(left_array, right_array)
44
+ joint_array = left_array + right_array
45
+ joint_array.group_by { |map| merge_group map }
46
+ .collect { |group, values| merge_collect group, values }
47
+ .flatten
48
+ end
49
+
50
+ # :reek:UtilityFunction
51
+ def merge_group(map, keys = %w[name dir])
52
+ map.is_a?(Hash) ? map.values_at(*keys) : []
53
+ end
54
+
55
+ def merge_collect(group, values)
56
+ group.first ? merge(*values) : values
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Favicon
5
+ module Utils
6
+ module Configuration
7
+ # Favicon configuration patch logic
8
+ module Patch
9
+ def self.included(klass)
10
+ klass.extend(ClassMethods)
11
+ end
12
+
13
+ # Patch configuration with the block provided
14
+ module ClassMethods
15
+ def patch(value_or_values, &block)
16
+ patch_method = case value_or_values
17
+ when Array then :patch_array
18
+ when Hash then :patch_hash
19
+ when Symbol, String then :patch_value
20
+ else return value_or_values
21
+ end
22
+ send patch_method, value_or_values, &block
23
+ end
24
+
25
+ private
26
+
27
+ def patch_array(values, &block)
28
+ values.collect { |value| patch value, &block }
29
+ end
30
+
31
+ def patch_hash(values, &block)
32
+ values.transform_values { |value| patch value, &block }
33
+ end
34
+
35
+ def patch_value(value, &block)
36
+ block.call patch_value_string_symbol(value)
37
+ end
38
+
39
+ # :reek:UtilityFunction
40
+ def patch_value_string_symbol(value)
41
+ value.to_s.start_with?(':') ? value[1..-1].to_sym : value
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mini_magick'
4
+
5
+ module Jekyll
6
+ module Favicon
7
+ module Utils
8
+ # Favicon convert for include
9
+ module Convert
10
+ def self.included(klass)
11
+ klass.extend(ClassMethods)
12
+ end
13
+
14
+ # Favicon convert utils functions
15
+ module ClassMethods
16
+ def convert(input, output, options = {})
17
+ MiniMagick::Tool::Convert.new do |convert|
18
+ convert.flatten
19
+ convert_options(convert, options) << input << output
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def convert_options(convert, options = {})
26
+ priorities = %w[resize scale]
27
+ convert_apply convert, options.slice(*priorities)
28
+ common_options = options.reject { |key| priorities.include? key }
29
+ convert_apply convert, common_options
30
+ end
31
+
32
+ # :reek:UtilityFunction
33
+ def convert_apply(convert, options = {})
34
+ options.each_with_object(convert) do |(option, value), memo|
35
+ memo.send option.to_sym, value
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end