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
@@ -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,53 @@
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
+ Utils.build_tag 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
+ def mimetype
34
+ mappings = {
35
+ ".ico" => "image/x-icon",
36
+ ".png" => "image/png",
37
+ ".svg" => "image/svg+xml"
38
+ }
39
+ mappings[extname]
40
+ end
41
+
42
+ def taggable_patch(configuration)
43
+ Favicon::Utils.patch configuration do |value|
44
+ case value
45
+ when :mime then mimetype
46
+ else value
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ 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,26 +1,23 @@
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
10
  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")
11
+ context.registers[:site]
12
+ .static_files
13
+ .select { |static_file| static_file.is_a? StaticFile }
14
+ .select(&:taggable?)
15
+ .collect(&:tags)
16
+ .flatten
17
+ .join("\n")
21
18
  end
22
19
  end
23
20
  end
24
21
  end
25
22
 
26
- Liquid::Template.register_tag('favicon', Jekyll::Favicon::Tag)
23
+ Liquid::Template.register_tag("favicon", Jekyll::Favicon::Tag)
@@ -0,0 +1,43 @@
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
+
23
+ def self.define_to_size(define)
24
+ return unless define
25
+
26
+ define.split("=")
27
+ .last
28
+ .split(",")
29
+ .collect { |size| [size, size].join "x" }
30
+ end
31
+
32
+ def self.name_to_size(name)
33
+ size_in_name_regex = /^.*-(\d+x\d+)\..*$/
34
+ name.match size_in_name_regex
35
+ end
36
+
37
+ def self.slice_and_compact(hash, keys)
38
+ compactable = hash.slice(*keys)
39
+ Utils.compact compactable
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,58 @@
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
+ def self.compact_deep(compactable)
14
+ case compactable
15
+ when Hash then compact_hash compactable
16
+ when Array then compact_array compactable
17
+ else compactable
18
+ end
19
+ end
20
+
21
+ def self.compact_hash(hash)
22
+ compacted_hash = hash.each_with_object({}) do |(key, value), memo|
23
+ next unless (compacted = compact_deep(value))
24
+
25
+ memo[key] = compacted
26
+ end
27
+ compact_shallow compacted_hash
28
+ end
29
+
30
+ def self.compact_array(array)
31
+ compacted_array = array.each_with_object([]) do |value, memo|
32
+ next unless (compacted = compact_deep(value))
33
+
34
+ memo << compacted
35
+ end
36
+ compact_shallow compacted_array
37
+ end
38
+
39
+ def self.compact_shallow(compactable)
40
+ compactable.empty? ? nil : compactable.compact
41
+ end
42
+
43
+ # Nil and empty remove from configurations
44
+ module ClassMethods
45
+ def compact(compactable)
46
+ case compactable
47
+ when Hash, Array
48
+ Compact.compact_deep(compactable) || compactable.class[]
49
+ else
50
+ compactable
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,70 @@
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
+ def self.merge_multiple(left = nil, *right_and_or_rest)
14
+ return left if right_and_or_rest.empty?
15
+
16
+ right, *rest = right_and_or_rest
17
+ merged = merge_pair left, right
18
+ return merged if rest.empty?
19
+
20
+ merge_multiple(merged, *rest)
21
+ end
22
+
23
+ def self.merge_pair(left, right)
24
+ return right if !left || !right || !left.instance_of?(right.class)
25
+
26
+ case right
27
+ when Hash then merge_pair_hash left, right
28
+ when Array then merge_pair_array left, right
29
+ else right
30
+ end
31
+ end
32
+
33
+ def self.merge_pair_hash(left_hash, right_hash)
34
+ left_hash.merge(right_hash) do |_, left_value, right_value|
35
+ merge_multiple left_value, right_value
36
+ end
37
+ end
38
+
39
+ def self.merge_pair_array(left_array, right_array)
40
+ joint_array = left_array + right_array
41
+ joint_array.group_by { |map| merge_group map }
42
+ .collect { |group, values| merge_collect group, values }
43
+ .flatten
44
+ end
45
+
46
+ def self.merge_group(map, keys = %w[name dir])
47
+ map.is_a?(Hash) ? map.values_at(*keys) : []
48
+ end
49
+
50
+ def self.merge_collect(group, values)
51
+ group.first ? merge_multiple(*values) : values
52
+ end
53
+
54
+ # Merge configurations
55
+ module ClassMethods
56
+ def merge(left = nil, *right_and_or_rest)
57
+ return left if right_and_or_rest.empty?
58
+
59
+ right, *rest = right_and_or_rest
60
+ merged = Merge.merge_pair left, right
61
+ return merged if rest.empty?
62
+
63
+ Merge.merge_multiple(merged, *rest)
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,49 @@
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
+ def self.patch_unknown(value_or_values, &block)
14
+ patch_method = case value_or_values
15
+ when Array then :patch_array
16
+ when Hash then :patch_hash
17
+ when Symbol, String then :patch_value
18
+ else return value_or_values
19
+ end
20
+ send patch_method, value_or_values, &block
21
+ end
22
+
23
+ def self.patch_array(values, &block)
24
+ values.collect { |value| patch_unknown value, &block }
25
+ end
26
+
27
+ def self.patch_hash(values, &block)
28
+ values.transform_values { |value| patch_unknown value, &block }
29
+ end
30
+
31
+ def self.patch_value(value, &block)
32
+ block.call patch_value_string_symbol(value)
33
+ end
34
+
35
+ def self.patch_value_string_symbol(value)
36
+ value.to_s.start_with?(":") ? value[1..].to_sym : value
37
+ end
38
+
39
+ # Patch configuration with the block provided
40
+ module ClassMethods
41
+ def patch(value_or_values, &block)
42
+ Patch.patch_unknown value_or_values, &block
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,39 @@
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
+ def self.convert_apply(convert, options = {})
15
+ options.each_with_object(convert) do |(option, value), memo|
16
+ memo.send option.to_sym, value
17
+ end
18
+ end
19
+
20
+ def self.convert_options(convert, options = {})
21
+ priorities = %w[resize scale]
22
+ convert_apply convert, options.slice(*priorities)
23
+ common_options = options.reject { |key| priorities.include? key }
24
+ convert_apply convert, common_options
25
+ end
26
+
27
+ # Favicon convert utils functions
28
+ module ClassMethods
29
+ def convert(input, output, options = {})
30
+ MiniMagick::Tool::Convert.new do |convert|
31
+ convert.flatten
32
+ Convert.convert_options(convert, options) << input << output
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end