jekyll 4.2.1 → 4.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +474 -350
- data/LICENSE +21 -21
- data/README.markdown +83 -86
- data/exe/jekyll +57 -57
- data/lib/blank_template/_config.yml +3 -3
- data/lib/blank_template/_layouts/default.html +12 -12
- data/lib/blank_template/_sass/main.scss +9 -9
- data/lib/blank_template/assets/css/main.scss +4 -4
- data/lib/blank_template/index.md +8 -8
- data/lib/jekyll/cache.rb +186 -190
- data/lib/jekyll/cleaner.rb +111 -111
- data/lib/jekyll/collection.rb +310 -309
- data/lib/jekyll/command.rb +105 -105
- data/lib/jekyll/commands/build.rb +82 -93
- data/lib/jekyll/commands/clean.rb +44 -45
- data/lib/jekyll/commands/doctor.rb +177 -177
- data/lib/jekyll/commands/help.rb +34 -34
- data/lib/jekyll/commands/new.rb +168 -169
- data/lib/jekyll/commands/new_theme.rb +39 -40
- data/lib/jekyll/commands/serve/live_reload_reactor.rb +119 -122
- data/lib/jekyll/commands/serve/livereload_assets/livereload.js +1183 -1183
- data/lib/jekyll/commands/serve/mime_types_charset.json +71 -0
- data/lib/jekyll/commands/serve/servlet.rb +206 -202
- data/lib/jekyll/commands/serve/websockets.rb +81 -81
- data/lib/jekyll/commands/serve.rb +367 -362
- data/lib/jekyll/configuration.rb +313 -313
- data/lib/jekyll/converter.rb +54 -54
- data/lib/jekyll/converters/identity.rb +41 -41
- data/lib/jekyll/converters/markdown/kramdown_parser.rb +197 -199
- data/lib/jekyll/converters/markdown.rb +113 -113
- data/lib/jekyll/converters/smartypants.rb +70 -70
- data/lib/jekyll/convertible.rb +257 -257
- data/lib/jekyll/data_entry.rb +83 -0
- data/lib/jekyll/data_hash.rb +61 -0
- data/lib/jekyll/deprecator.rb +50 -50
- data/lib/jekyll/document.rb +543 -544
- data/lib/jekyll/drops/collection_drop.rb +20 -20
- data/lib/jekyll/drops/document_drop.rb +71 -70
- data/lib/jekyll/drops/drop.rb +293 -293
- data/lib/jekyll/drops/excerpt_drop.rb +23 -19
- data/lib/jekyll/drops/jekyll_drop.rb +32 -32
- data/lib/jekyll/drops/site_drop.rb +71 -66
- data/lib/jekyll/drops/static_file_drop.rb +14 -14
- data/lib/jekyll/drops/theme_drop.rb +36 -0
- data/lib/jekyll/drops/unified_payload_drop.rb +30 -26
- data/lib/jekyll/drops/url_drop.rb +140 -140
- data/lib/jekyll/entry_filter.rb +117 -121
- data/lib/jekyll/errors.rb +20 -20
- data/lib/jekyll/excerpt.rb +200 -201
- data/lib/jekyll/external.rb +75 -79
- data/lib/jekyll/filters/date_filters.rb +110 -110
- data/lib/jekyll/filters/grouping_filters.rb +64 -64
- data/lib/jekyll/filters/url_filters.rb +98 -98
- data/lib/jekyll/filters.rb +532 -535
- data/lib/jekyll/frontmatter_defaults.rb +238 -240
- data/lib/jekyll/generator.rb +5 -5
- data/lib/jekyll/hooks.rb +107 -107
- data/lib/jekyll/inclusion.rb +32 -32
- data/lib/jekyll/layout.rb +55 -67
- data/lib/jekyll/liquid_extensions.rb +22 -22
- data/lib/jekyll/liquid_renderer/file.rb +77 -77
- data/lib/jekyll/liquid_renderer/table.rb +55 -55
- data/lib/jekyll/liquid_renderer.rb +80 -80
- data/lib/jekyll/log_adapter.rb +151 -151
- data/lib/jekyll/mime.types +939 -866
- data/lib/jekyll/page.rb +215 -217
- data/lib/jekyll/page_excerpt.rb +25 -25
- data/lib/jekyll/page_without_a_file.rb +14 -14
- data/lib/jekyll/path_manager.rb +74 -74
- data/lib/jekyll/plugin.rb +92 -92
- data/lib/jekyll/plugin_manager.rb +123 -115
- data/lib/jekyll/profiler.rb +55 -58
- data/lib/jekyll/publisher.rb +23 -23
- data/lib/jekyll/reader.rb +209 -192
- data/lib/jekyll/readers/collection_reader.rb +23 -23
- data/lib/jekyll/readers/data_reader.rb +116 -79
- data/lib/jekyll/readers/layout_reader.rb +62 -62
- data/lib/jekyll/readers/page_reader.rb +25 -25
- data/lib/jekyll/readers/post_reader.rb +85 -85
- data/lib/jekyll/readers/static_file_reader.rb +25 -25
- data/lib/jekyll/readers/theme_assets_reader.rb +52 -52
- data/lib/jekyll/regenerator.rb +195 -195
- data/lib/jekyll/related_posts.rb +52 -52
- data/lib/jekyll/renderer.rb +263 -265
- data/lib/jekyll/site.rb +582 -551
- data/lib/jekyll/static_file.rb +205 -208
- data/lib/jekyll/stevenson.rb +60 -60
- data/lib/jekyll/tags/highlight.rb +114 -110
- data/lib/jekyll/tags/include.rb +275 -275
- data/lib/jekyll/tags/link.rb +42 -42
- data/lib/jekyll/tags/post_url.rb +106 -106
- data/lib/jekyll/theme.rb +90 -86
- data/lib/jekyll/theme_builder.rb +121 -121
- data/lib/jekyll/url.rb +167 -167
- data/lib/jekyll/utils/ansi.rb +57 -57
- data/lib/jekyll/utils/exec.rb +26 -26
- data/lib/jekyll/utils/internet.rb +37 -37
- data/lib/jekyll/utils/platforms.rb +67 -67
- data/lib/jekyll/utils/thread_event.rb +31 -31
- data/lib/jekyll/utils/win_tz.rb +46 -75
- data/lib/jekyll/utils.rb +378 -367
- data/lib/jekyll/version.rb +5 -5
- data/lib/jekyll.rb +197 -195
- data/lib/site_template/.gitignore +5 -5
- data/lib/site_template/404.html +25 -25
- data/lib/site_template/_config.yml +55 -55
- data/lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb +29 -29
- data/lib/site_template/about.markdown +18 -18
- data/lib/site_template/index.markdown +6 -6
- data/lib/theme_template/CODE_OF_CONDUCT.md.erb +74 -74
- data/lib/theme_template/Gemfile +4 -4
- data/lib/theme_template/LICENSE.txt.erb +21 -21
- data/lib/theme_template/README.md.erb +50 -52
- data/lib/theme_template/_layouts/default.html +1 -1
- data/lib/theme_template/_layouts/page.html +5 -5
- data/lib/theme_template/_layouts/post.html +5 -5
- data/lib/theme_template/example/_config.yml.erb +1 -1
- data/lib/theme_template/example/_post.md +12 -12
- data/lib/theme_template/example/index.html +14 -14
- data/lib/theme_template/example/style.scss +7 -7
- data/lib/theme_template/gitignore.erb +6 -6
- data/lib/theme_template/theme.gemspec.erb +16 -16
- data/rubocop/jekyll/assert_equal_literal_actual.rb +149 -149
- data/rubocop/jekyll/no_p_allowed.rb +23 -23
- data/rubocop/jekyll/no_puts_allowed.rb +23 -23
- data/rubocop/jekyll.rb +5 -5
- metadata +62 -14
@@ -1,55 +1,55 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Jekyll
|
4
|
-
class LiquidRenderer
|
5
|
-
class Table
|
6
|
-
GAUGES = [:count, :bytes, :time].freeze
|
7
|
-
|
8
|
-
def initialize(stats)
|
9
|
-
@stats = stats
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_s(num_of_rows = 50)
|
13
|
-
Jekyll::Profiler.tabulate(data_for_table(num_of_rows))
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
# rubocop:disable Metrics/AbcSize
|
19
|
-
def data_for_table(num_of_rows)
|
20
|
-
sorted = @stats.sort_by { |_, file_stats| -file_stats[:time] }
|
21
|
-
sorted = sorted.slice(0, num_of_rows)
|
22
|
-
|
23
|
-
table = [header_labels]
|
24
|
-
totals = Hash.new { |hash, key| hash[key] = 0 }
|
25
|
-
|
26
|
-
sorted.each do |filename, file_stats|
|
27
|
-
GAUGES.each { |gauge| totals[gauge] += file_stats[gauge] }
|
28
|
-
row = []
|
29
|
-
row << filename
|
30
|
-
row << file_stats[:count].to_s
|
31
|
-
row << format_bytes(file_stats[:bytes])
|
32
|
-
row << format("%.3f", file_stats[:time])
|
33
|
-
table << row
|
34
|
-
end
|
35
|
-
|
36
|
-
footer = []
|
37
|
-
footer << "TOTAL (for #{sorted.size} files)"
|
38
|
-
footer << totals[:count].to_s
|
39
|
-
footer << format_bytes(totals[:bytes])
|
40
|
-
footer << format("%.3f", totals[:time])
|
41
|
-
table << footer
|
42
|
-
end
|
43
|
-
# rubocop:enable Metrics/AbcSize
|
44
|
-
|
45
|
-
def header_labels
|
46
|
-
GAUGES.map { |gauge| gauge.to_s.capitalize }.unshift("Filename")
|
47
|
-
end
|
48
|
-
|
49
|
-
def format_bytes(bytes)
|
50
|
-
bytes /= 1024.0
|
51
|
-
format("%.2fK", bytes)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
class LiquidRenderer
|
5
|
+
class Table
|
6
|
+
GAUGES = [:count, :bytes, :time].freeze
|
7
|
+
|
8
|
+
def initialize(stats)
|
9
|
+
@stats = stats
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s(num_of_rows = 50)
|
13
|
+
Jekyll::Profiler.tabulate(data_for_table(num_of_rows))
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
# rubocop:disable Metrics/AbcSize
|
19
|
+
def data_for_table(num_of_rows)
|
20
|
+
sorted = @stats.sort_by { |_, file_stats| -file_stats[:time] }
|
21
|
+
sorted = sorted.slice(0, num_of_rows)
|
22
|
+
|
23
|
+
table = [header_labels]
|
24
|
+
totals = Hash.new { |hash, key| hash[key] = 0 }
|
25
|
+
|
26
|
+
sorted.each do |filename, file_stats|
|
27
|
+
GAUGES.each { |gauge| totals[gauge] += file_stats[gauge] }
|
28
|
+
row = []
|
29
|
+
row << filename
|
30
|
+
row << file_stats[:count].to_s
|
31
|
+
row << format_bytes(file_stats[:bytes])
|
32
|
+
row << format("%.3f", file_stats[:time])
|
33
|
+
table << row
|
34
|
+
end
|
35
|
+
|
36
|
+
footer = []
|
37
|
+
footer << "TOTAL (for #{sorted.size} files)"
|
38
|
+
footer << totals[:count].to_s
|
39
|
+
footer << format_bytes(totals[:bytes])
|
40
|
+
footer << format("%.3f", totals[:time])
|
41
|
+
table << footer
|
42
|
+
end
|
43
|
+
# rubocop:enable Metrics/AbcSize
|
44
|
+
|
45
|
+
def header_labels
|
46
|
+
GAUGES.map { |gauge| gauge.to_s.capitalize }.unshift("Filename")
|
47
|
+
end
|
48
|
+
|
49
|
+
def format_bytes(bytes)
|
50
|
+
bytes /= 1024.0
|
51
|
+
format("%.2fK", bytes)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -1,80 +1,80 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "liquid_renderer/file"
|
4
|
-
require_relative "liquid_renderer/table"
|
5
|
-
|
6
|
-
module Jekyll
|
7
|
-
class LiquidRenderer
|
8
|
-
def initialize(site)
|
9
|
-
@site = site
|
10
|
-
Liquid::Template.error_mode = @site.config["liquid"]["error_mode"].to_sym
|
11
|
-
reset
|
12
|
-
end
|
13
|
-
|
14
|
-
def reset
|
15
|
-
@stats = {}
|
16
|
-
@cache = {}
|
17
|
-
end
|
18
|
-
|
19
|
-
def file(filename)
|
20
|
-
filename = normalize_path(filename)
|
21
|
-
LiquidRenderer::File.new(self, filename).tap do
|
22
|
-
@stats[filename] ||= new_profile_hash
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def increment_bytes(filename, bytes)
|
27
|
-
@stats[filename][:bytes] += bytes
|
28
|
-
end
|
29
|
-
|
30
|
-
def increment_time(filename, time)
|
31
|
-
@stats[filename][:time] += time
|
32
|
-
end
|
33
|
-
|
34
|
-
def increment_count(filename)
|
35
|
-
@stats[filename][:count] += 1
|
36
|
-
end
|
37
|
-
|
38
|
-
def stats_table(num_of_rows = 50)
|
39
|
-
LiquidRenderer::Table.new(@stats).to_s(num_of_rows)
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.format_error(error, path)
|
43
|
-
"#{error.message} in #{path}"
|
44
|
-
end
|
45
|
-
|
46
|
-
# A persistent cache to store and retrieve parsed templates based on the filename
|
47
|
-
# via `LiquidRenderer::File#parse`
|
48
|
-
#
|
49
|
-
# It is emptied when `self.reset` is called.
|
50
|
-
def cache
|
51
|
-
@cache ||= {}
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
-
|
56
|
-
def normalize_path(filename)
|
57
|
-
@normalize_path ||= {}
|
58
|
-
@normalize_path[filename] ||= begin
|
59
|
-
theme_dir = @site.theme&.root
|
60
|
-
case filename
|
61
|
-
when %r!\A(#{Regexp.escape(@site.source)}/)(?<rest>.*)!io
|
62
|
-
Regexp.last_match(:rest)
|
63
|
-
when %r!(/gems/.*)*/gems/(?<dirname>[^/]+)(?<rest>.*)!,
|
64
|
-
%r!(?<dirname>[^/]+/lib)(?<rest>.*)!
|
65
|
-
"#{Regexp.last_match(:dirname)}#{Regexp.last_match(:rest)}"
|
66
|
-
when theme_dir && %r!\A#{Regexp.escape(theme_dir)}/(?<rest>.*)!io
|
67
|
-
PathManager.join(@site.theme.basename, Regexp.last_match(:rest))
|
68
|
-
when %r!\A/(.*)!
|
69
|
-
Regexp.last_match(1)
|
70
|
-
else
|
71
|
-
filename
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def new_profile_hash
|
77
|
-
Hash.new { |hash, key| hash[key] = 0 }
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "liquid_renderer/file"
|
4
|
+
require_relative "liquid_renderer/table"
|
5
|
+
|
6
|
+
module Jekyll
|
7
|
+
class LiquidRenderer
|
8
|
+
def initialize(site)
|
9
|
+
@site = site
|
10
|
+
Liquid::Template.error_mode = @site.config["liquid"]["error_mode"].to_sym
|
11
|
+
reset
|
12
|
+
end
|
13
|
+
|
14
|
+
def reset
|
15
|
+
@stats = {}
|
16
|
+
@cache = {}
|
17
|
+
end
|
18
|
+
|
19
|
+
def file(filename)
|
20
|
+
filename = normalize_path(filename)
|
21
|
+
LiquidRenderer::File.new(self, filename).tap do
|
22
|
+
@stats[filename] ||= new_profile_hash
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def increment_bytes(filename, bytes)
|
27
|
+
@stats[filename][:bytes] += bytes
|
28
|
+
end
|
29
|
+
|
30
|
+
def increment_time(filename, time)
|
31
|
+
@stats[filename][:time] += time
|
32
|
+
end
|
33
|
+
|
34
|
+
def increment_count(filename)
|
35
|
+
@stats[filename][:count] += 1
|
36
|
+
end
|
37
|
+
|
38
|
+
def stats_table(num_of_rows = 50)
|
39
|
+
LiquidRenderer::Table.new(@stats).to_s(num_of_rows)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.format_error(error, path)
|
43
|
+
"#{error.message} in #{path}"
|
44
|
+
end
|
45
|
+
|
46
|
+
# A persistent cache to store and retrieve parsed templates based on the filename
|
47
|
+
# via `LiquidRenderer::File#parse`
|
48
|
+
#
|
49
|
+
# It is emptied when `self.reset` is called.
|
50
|
+
def cache
|
51
|
+
@cache ||= {}
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def normalize_path(filename)
|
57
|
+
@normalize_path ||= {}
|
58
|
+
@normalize_path[filename] ||= begin
|
59
|
+
theme_dir = @site.theme&.root
|
60
|
+
case filename
|
61
|
+
when %r!\A(#{Regexp.escape(@site.source)}/)(?<rest>.*)!io
|
62
|
+
Regexp.last_match(:rest)
|
63
|
+
when %r!(/gems/.*)*/gems/(?<dirname>[^/]+)(?<rest>.*)!,
|
64
|
+
%r!(?<dirname>[^/]+/lib)(?<rest>.*)!
|
65
|
+
"#{Regexp.last_match(:dirname)}#{Regexp.last_match(:rest)}"
|
66
|
+
when theme_dir && %r!\A#{Regexp.escape(theme_dir)}/(?<rest>.*)!io
|
67
|
+
PathManager.join(@site.theme.basename, Regexp.last_match(:rest))
|
68
|
+
when %r!\A/(.*)!
|
69
|
+
Regexp.last_match(1)
|
70
|
+
else
|
71
|
+
filename
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def new_profile_hash
|
77
|
+
Hash.new { |hash, key| hash[key] = 0 }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/lib/jekyll/log_adapter.rb
CHANGED
@@ -1,151 +1,151 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Jekyll
|
4
|
-
class LogAdapter
|
5
|
-
attr_reader :writer, :messages, :level
|
6
|
-
|
7
|
-
LOG_LEVELS = {
|
8
|
-
:debug => ::Logger::DEBUG,
|
9
|
-
:info => ::Logger::INFO,
|
10
|
-
:warn => ::Logger::WARN,
|
11
|
-
:error => ::Logger::ERROR,
|
12
|
-
}.freeze
|
13
|
-
|
14
|
-
# Public: Create a new instance of a log writer
|
15
|
-
#
|
16
|
-
# writer - Logger compatible instance
|
17
|
-
# log_level - (optional, symbol) the log level
|
18
|
-
#
|
19
|
-
# Returns nothing
|
20
|
-
def initialize(writer, level = :info)
|
21
|
-
@messages = []
|
22
|
-
@writer = writer
|
23
|
-
self.log_level = level
|
24
|
-
end
|
25
|
-
|
26
|
-
# Public: Set the log level on the writer
|
27
|
-
#
|
28
|
-
# level - (symbol) the log level
|
29
|
-
#
|
30
|
-
# Returns nothing
|
31
|
-
def log_level=(level)
|
32
|
-
writer.level = level if level.is_a?(Integer) && level.between?(0, 3)
|
33
|
-
writer.level = LOG_LEVELS[level] ||
|
34
|
-
raise(ArgumentError, "unknown log level")
|
35
|
-
@level = level
|
36
|
-
end
|
37
|
-
|
38
|
-
def adjust_verbosity(options = {})
|
39
|
-
# Quiet always wins.
|
40
|
-
if options[:quiet]
|
41
|
-
self.log_level = :error
|
42
|
-
elsif options[:verbose]
|
43
|
-
self.log_level = :debug
|
44
|
-
end
|
45
|
-
debug "Logging at level:", LOG_LEVELS.key(writer.level).to_s
|
46
|
-
debug "Jekyll Version:", Jekyll::VERSION
|
47
|
-
end
|
48
|
-
|
49
|
-
# Public: Print a debug message
|
50
|
-
#
|
51
|
-
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
52
|
-
# message - the message detail
|
53
|
-
#
|
54
|
-
# Returns nothing
|
55
|
-
def debug(topic, message = nil, &block)
|
56
|
-
write(:debug, topic, message, &block)
|
57
|
-
end
|
58
|
-
|
59
|
-
# Public: Print a message
|
60
|
-
#
|
61
|
-
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
62
|
-
# message - the message detail
|
63
|
-
#
|
64
|
-
# Returns nothing
|
65
|
-
def info(topic, message = nil, &block)
|
66
|
-
write(:info, topic, message, &block)
|
67
|
-
end
|
68
|
-
|
69
|
-
# Public: Print a message
|
70
|
-
#
|
71
|
-
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
72
|
-
# message - the message detail
|
73
|
-
#
|
74
|
-
# Returns nothing
|
75
|
-
def warn(topic, message = nil, &block)
|
76
|
-
write(:warn, topic, message, &block)
|
77
|
-
end
|
78
|
-
|
79
|
-
# Public: Print an error message
|
80
|
-
#
|
81
|
-
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
82
|
-
# message - the message detail
|
83
|
-
#
|
84
|
-
# Returns nothing
|
85
|
-
def error(topic, message = nil, &block)
|
86
|
-
write(:error, topic, message, &block)
|
87
|
-
end
|
88
|
-
|
89
|
-
# Public: Print an error message and immediately abort the process
|
90
|
-
#
|
91
|
-
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
92
|
-
# message - the message detail (can be omitted)
|
93
|
-
#
|
94
|
-
# Returns nothing
|
95
|
-
def abort_with(topic, message = nil, &block)
|
96
|
-
error(topic, message, &block)
|
97
|
-
abort
|
98
|
-
end
|
99
|
-
|
100
|
-
# Internal: Build a topic method
|
101
|
-
#
|
102
|
-
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
103
|
-
# message - the message detail
|
104
|
-
#
|
105
|
-
# Returns the formatted message
|
106
|
-
def message(topic, message = nil)
|
107
|
-
raise ArgumentError, "block or message, not both" if block_given? && message
|
108
|
-
|
109
|
-
message = yield if block_given?
|
110
|
-
message = message.to_s.gsub(%r!\s+!, " ")
|
111
|
-
topic = formatted_topic(topic, block_given?)
|
112
|
-
out = topic + message
|
113
|
-
messages << out
|
114
|
-
out
|
115
|
-
end
|
116
|
-
|
117
|
-
# Internal: Format the topic
|
118
|
-
#
|
119
|
-
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
120
|
-
# colon -
|
121
|
-
#
|
122
|
-
# Returns the formatted topic statement
|
123
|
-
def formatted_topic(topic, colon = false)
|
124
|
-
"#{topic}#{colon ? ": " : " "}".rjust(20)
|
125
|
-
end
|
126
|
-
|
127
|
-
# Internal: Check if the message should be written given the log level.
|
128
|
-
#
|
129
|
-
# level_of_message - the Symbol level of message, one of :debug, :info, :warn, :error
|
130
|
-
#
|
131
|
-
# Returns whether the message should be written.
|
132
|
-
def write_message?(level_of_message)
|
133
|
-
LOG_LEVELS.fetch(level) <= LOG_LEVELS.fetch(level_of_message)
|
134
|
-
end
|
135
|
-
|
136
|
-
# Internal: Log a message.
|
137
|
-
#
|
138
|
-
# level_of_message - the Symbol level of message, one of :debug, :info, :warn, :error
|
139
|
-
# topic - the String topic or full message
|
140
|
-
# message - the String message (optional)
|
141
|
-
# block - a block containing the message (optional)
|
142
|
-
#
|
143
|
-
# Returns false if the message was not written, otherwise returns the value of calling
|
144
|
-
# the appropriate writer method, e.g. writer.info.
|
145
|
-
def write(level_of_message, topic, message = nil, &block)
|
146
|
-
return false unless write_message?(level_of_message)
|
147
|
-
|
148
|
-
writer.public_send(level_of_message, message(topic, message, &block))
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
class LogAdapter
|
5
|
+
attr_reader :writer, :messages, :level
|
6
|
+
|
7
|
+
LOG_LEVELS = {
|
8
|
+
:debug => ::Logger::DEBUG,
|
9
|
+
:info => ::Logger::INFO,
|
10
|
+
:warn => ::Logger::WARN,
|
11
|
+
:error => ::Logger::ERROR,
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
# Public: Create a new instance of a log writer
|
15
|
+
#
|
16
|
+
# writer - Logger compatible instance
|
17
|
+
# log_level - (optional, symbol) the log level
|
18
|
+
#
|
19
|
+
# Returns nothing
|
20
|
+
def initialize(writer, level = :info)
|
21
|
+
@messages = []
|
22
|
+
@writer = writer
|
23
|
+
self.log_level = level
|
24
|
+
end
|
25
|
+
|
26
|
+
# Public: Set the log level on the writer
|
27
|
+
#
|
28
|
+
# level - (symbol) the log level
|
29
|
+
#
|
30
|
+
# Returns nothing
|
31
|
+
def log_level=(level)
|
32
|
+
writer.level = level if level.is_a?(Integer) && level.between?(0, 3)
|
33
|
+
writer.level = LOG_LEVELS[level] ||
|
34
|
+
raise(ArgumentError, "unknown log level")
|
35
|
+
@level = level
|
36
|
+
end
|
37
|
+
|
38
|
+
def adjust_verbosity(options = {})
|
39
|
+
# Quiet always wins.
|
40
|
+
if options[:quiet]
|
41
|
+
self.log_level = :error
|
42
|
+
elsif options[:verbose]
|
43
|
+
self.log_level = :debug
|
44
|
+
end
|
45
|
+
debug "Logging at level:", LOG_LEVELS.key(writer.level).to_s
|
46
|
+
debug "Jekyll Version:", Jekyll::VERSION
|
47
|
+
end
|
48
|
+
|
49
|
+
# Public: Print a debug message
|
50
|
+
#
|
51
|
+
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
52
|
+
# message - the message detail
|
53
|
+
#
|
54
|
+
# Returns nothing
|
55
|
+
def debug(topic, message = nil, &block)
|
56
|
+
write(:debug, topic, message, &block)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Public: Print a message
|
60
|
+
#
|
61
|
+
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
62
|
+
# message - the message detail
|
63
|
+
#
|
64
|
+
# Returns nothing
|
65
|
+
def info(topic, message = nil, &block)
|
66
|
+
write(:info, topic, message, &block)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Public: Print a message
|
70
|
+
#
|
71
|
+
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
72
|
+
# message - the message detail
|
73
|
+
#
|
74
|
+
# Returns nothing
|
75
|
+
def warn(topic, message = nil, &block)
|
76
|
+
write(:warn, topic, message, &block)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Public: Print an error message
|
80
|
+
#
|
81
|
+
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
82
|
+
# message - the message detail
|
83
|
+
#
|
84
|
+
# Returns nothing
|
85
|
+
def error(topic, message = nil, &block)
|
86
|
+
write(:error, topic, message, &block)
|
87
|
+
end
|
88
|
+
|
89
|
+
# Public: Print an error message and immediately abort the process
|
90
|
+
#
|
91
|
+
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
92
|
+
# message - the message detail (can be omitted)
|
93
|
+
#
|
94
|
+
# Returns nothing
|
95
|
+
def abort_with(topic, message = nil, &block)
|
96
|
+
error(topic, message, &block)
|
97
|
+
abort
|
98
|
+
end
|
99
|
+
|
100
|
+
# Internal: Build a topic method
|
101
|
+
#
|
102
|
+
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
103
|
+
# message - the message detail
|
104
|
+
#
|
105
|
+
# Returns the formatted message
|
106
|
+
def message(topic, message = nil)
|
107
|
+
raise ArgumentError, "block or message, not both" if block_given? && message
|
108
|
+
|
109
|
+
message = yield if block_given?
|
110
|
+
message = message.to_s.gsub(%r!\s+!, " ")
|
111
|
+
topic = formatted_topic(topic, block_given?)
|
112
|
+
out = topic + message
|
113
|
+
messages << out
|
114
|
+
out
|
115
|
+
end
|
116
|
+
|
117
|
+
# Internal: Format the topic
|
118
|
+
#
|
119
|
+
# topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
|
120
|
+
# colon -
|
121
|
+
#
|
122
|
+
# Returns the formatted topic statement
|
123
|
+
def formatted_topic(topic, colon = false)
|
124
|
+
"#{topic}#{colon ? ": " : " "}".rjust(20)
|
125
|
+
end
|
126
|
+
|
127
|
+
# Internal: Check if the message should be written given the log level.
|
128
|
+
#
|
129
|
+
# level_of_message - the Symbol level of message, one of :debug, :info, :warn, :error
|
130
|
+
#
|
131
|
+
# Returns whether the message should be written.
|
132
|
+
def write_message?(level_of_message)
|
133
|
+
LOG_LEVELS.fetch(level) <= LOG_LEVELS.fetch(level_of_message)
|
134
|
+
end
|
135
|
+
|
136
|
+
# Internal: Log a message.
|
137
|
+
#
|
138
|
+
# level_of_message - the Symbol level of message, one of :debug, :info, :warn, :error
|
139
|
+
# topic - the String topic or full message
|
140
|
+
# message - the String message (optional)
|
141
|
+
# block - a block containing the message (optional)
|
142
|
+
#
|
143
|
+
# Returns false if the message was not written, otherwise returns the value of calling
|
144
|
+
# the appropriate writer method, e.g. writer.info.
|
145
|
+
def write(level_of_message, topic, message = nil, &block)
|
146
|
+
return false unless write_message?(level_of_message)
|
147
|
+
|
148
|
+
writer.public_send(level_of_message, message(topic, message, &block))
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|