jekyll 4.0.1 → 4.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +350 -163
- data/LICENSE +21 -21
- data/README.markdown +86 -90
- 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 +190 -190
- data/lib/jekyll/cleaner.rb +111 -111
- data/lib/jekyll/collection.rb +309 -309
- data/lib/jekyll/command.rb +105 -103
- data/lib/jekyll/commands/build.rb +93 -93
- data/lib/jekyll/commands/clean.rb +45 -45
- data/lib/jekyll/commands/doctor.rb +177 -173
- data/lib/jekyll/commands/help.rb +34 -34
- data/lib/jekyll/commands/new.rb +169 -169
- data/lib/jekyll/commands/new_theme.rb +40 -42
- data/lib/jekyll/commands/serve/live_reload_reactor.rb +122 -122
- data/lib/jekyll/commands/serve/livereload_assets/livereload.js +1183 -1183
- data/lib/jekyll/commands/serve/servlet.rb +202 -202
- data/lib/jekyll/commands/serve/websockets.rb +81 -81
- data/lib/jekyll/commands/serve.rb +362 -354
- data/lib/jekyll/configuration.rb +313 -316
- data/lib/jekyll/converter.rb +54 -54
- data/lib/jekyll/converters/identity.rb +41 -41
- data/lib/jekyll/converters/markdown/kramdown_parser.rb +199 -130
- data/lib/jekyll/converters/markdown.rb +113 -113
- data/lib/jekyll/converters/smartypants.rb +70 -70
- data/lib/jekyll/convertible.rb +257 -254
- data/lib/jekyll/deprecator.rb +50 -50
- data/lib/jekyll/document.rb +544 -522
- data/lib/jekyll/drops/collection_drop.rb +20 -20
- data/lib/jekyll/drops/document_drop.rb +70 -69
- data/lib/jekyll/drops/drop.rb +293 -215
- data/lib/jekyll/drops/excerpt_drop.rb +19 -19
- data/lib/jekyll/drops/jekyll_drop.rb +32 -32
- data/lib/jekyll/drops/site_drop.rb +66 -66
- data/lib/jekyll/drops/static_file_drop.rb +14 -14
- data/lib/jekyll/drops/unified_payload_drop.rb +26 -26
- data/lib/jekyll/drops/url_drop.rb +140 -132
- data/lib/jekyll/entry_filter.rb +121 -110
- data/lib/jekyll/errors.rb +20 -20
- data/lib/jekyll/excerpt.rb +201 -201
- data/lib/jekyll/external.rb +79 -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 -68
- data/lib/jekyll/filters.rb +535 -454
- data/lib/jekyll/frontmatter_defaults.rb +240 -245
- data/lib/jekyll/generator.rb +5 -5
- data/lib/jekyll/hooks.rb +107 -106
- data/lib/jekyll/inclusion.rb +32 -0
- data/lib/jekyll/layout.rb +67 -62
- 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 -75
- data/lib/jekyll/liquid_renderer.rb +80 -77
- data/lib/jekyll/log_adapter.rb +151 -151
- data/lib/jekyll/mime.types +866 -866
- data/lib/jekyll/page.rb +217 -186
- data/lib/jekyll/page_excerpt.rb +25 -0
- data/lib/jekyll/page_without_a_file.rb +14 -14
- data/lib/jekyll/path_manager.rb +74 -31
- data/lib/jekyll/plugin.rb +92 -92
- data/lib/jekyll/plugin_manager.rb +115 -115
- data/lib/jekyll/profiler.rb +58 -0
- data/lib/jekyll/publisher.rb +23 -23
- data/lib/jekyll/reader.rb +192 -187
- data/lib/jekyll/readers/collection_reader.rb +23 -22
- data/lib/jekyll/readers/data_reader.rb +79 -75
- data/lib/jekyll/readers/layout_reader.rb +62 -61
- data/lib/jekyll/readers/page_reader.rb +25 -24
- data/lib/jekyll/readers/post_reader.rb +85 -84
- data/lib/jekyll/readers/static_file_reader.rb +25 -24
- data/lib/jekyll/readers/theme_assets_reader.rb +52 -51
- data/lib/jekyll/regenerator.rb +195 -195
- data/lib/jekyll/related_posts.rb +52 -52
- data/lib/jekyll/renderer.rb +265 -267
- data/lib/jekyll/site.rb +551 -527
- data/lib/jekyll/static_file.rb +208 -203
- data/lib/jekyll/stevenson.rb +60 -60
- data/lib/jekyll/tags/highlight.rb +110 -110
- data/lib/jekyll/tags/include.rb +275 -221
- data/lib/jekyll/tags/link.rb +42 -41
- data/lib/jekyll/tags/post_url.rb +106 -107
- data/lib/jekyll/theme.rb +86 -80
- data/lib/jekyll/theme_builder.rb +121 -121
- data/lib/jekyll/url.rb +167 -164
- 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 -82
- data/lib/jekyll/utils/thread_event.rb +31 -31
- data/lib/jekyll/utils/win_tz.rb +75 -75
- data/lib/jekyll/utils.rb +367 -367
- data/lib/jekyll/version.rb +5 -5
- data/lib/jekyll.rb +195 -206
- 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 +52 -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 -19
- 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 +20 -38
data/lib/jekyll/hooks.rb
CHANGED
@@ -1,106 +1,107 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Jekyll
|
4
|
-
module Hooks
|
5
|
-
DEFAULT_PRIORITY = 20
|
6
|
-
|
7
|
-
# compatibility layer for octopress-hooks users
|
8
|
-
PRIORITY_MAP = {
|
9
|
-
:low => 10,
|
10
|
-
:normal => 20,
|
11
|
-
:high => 30,
|
12
|
-
}.freeze
|
13
|
-
|
14
|
-
# initial empty hooks
|
15
|
-
@registry = {
|
16
|
-
:site => {
|
17
|
-
:after_init => [],
|
18
|
-
:after_reset => [],
|
19
|
-
:post_read => [],
|
20
|
-
:pre_render => [],
|
21
|
-
:post_render => [],
|
22
|
-
:post_write => [],
|
23
|
-
},
|
24
|
-
:pages => {
|
25
|
-
:post_init
|
26
|
-
:pre_render
|
27
|
-
:
|
28
|
-
:
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
:
|
33
|
-
:
|
34
|
-
:
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
:
|
40
|
-
:
|
41
|
-
|
42
|
-
|
43
|
-
:
|
44
|
-
},
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
:
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
#
|
98
|
-
hooks = @registry
|
99
|
-
|
100
|
-
|
101
|
-
hooks
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Hooks
|
5
|
+
DEFAULT_PRIORITY = 20
|
6
|
+
|
7
|
+
# compatibility layer for octopress-hooks users
|
8
|
+
PRIORITY_MAP = {
|
9
|
+
:low => 10,
|
10
|
+
:normal => 20,
|
11
|
+
:high => 30,
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
# initial empty hooks
|
15
|
+
@registry = {
|
16
|
+
:site => {
|
17
|
+
:after_init => [],
|
18
|
+
:after_reset => [],
|
19
|
+
:post_read => [],
|
20
|
+
:pre_render => [],
|
21
|
+
:post_render => [],
|
22
|
+
:post_write => [],
|
23
|
+
},
|
24
|
+
:pages => {
|
25
|
+
:post_init => [],
|
26
|
+
:pre_render => [],
|
27
|
+
:post_convert => [],
|
28
|
+
:post_render => [],
|
29
|
+
:post_write => [],
|
30
|
+
},
|
31
|
+
:posts => {
|
32
|
+
:post_init => [],
|
33
|
+
:pre_render => [],
|
34
|
+
:post_convert => [],
|
35
|
+
:post_render => [],
|
36
|
+
:post_write => [],
|
37
|
+
},
|
38
|
+
:documents => {
|
39
|
+
:post_init => [],
|
40
|
+
:pre_render => [],
|
41
|
+
:post_convert => [],
|
42
|
+
:post_render => [],
|
43
|
+
:post_write => [],
|
44
|
+
},
|
45
|
+
:clean => {
|
46
|
+
:on_obsolete => [],
|
47
|
+
},
|
48
|
+
}
|
49
|
+
|
50
|
+
# map of all hooks and their priorities
|
51
|
+
@hook_priority = {}
|
52
|
+
|
53
|
+
NotAvailable = Class.new(RuntimeError)
|
54
|
+
Uncallable = Class.new(RuntimeError)
|
55
|
+
|
56
|
+
# register hook(s) to be called later, public API
|
57
|
+
def self.register(owners, event, priority: DEFAULT_PRIORITY, &block)
|
58
|
+
Array(owners).each do |owner|
|
59
|
+
register_one(owner, event, priority_value(priority), &block)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Ensure the priority is a Fixnum
|
64
|
+
def self.priority_value(priority)
|
65
|
+
return priority if priority.is_a?(Integer)
|
66
|
+
|
67
|
+
PRIORITY_MAP[priority] || DEFAULT_PRIORITY
|
68
|
+
end
|
69
|
+
|
70
|
+
# register a single hook to be called later, internal API
|
71
|
+
def self.register_one(owner, event, priority, &block)
|
72
|
+
@registry[owner] ||= {
|
73
|
+
:post_init => [],
|
74
|
+
:pre_render => [],
|
75
|
+
:post_convert => [],
|
76
|
+
:post_render => [],
|
77
|
+
:post_write => [],
|
78
|
+
}
|
79
|
+
|
80
|
+
unless @registry[owner][event]
|
81
|
+
raise NotAvailable, "Invalid hook. #{owner} supports only the " \
|
82
|
+
"following hooks #{@registry[owner].keys.inspect}"
|
83
|
+
end
|
84
|
+
|
85
|
+
raise Uncallable, "Hooks must respond to :call" unless block.respond_to? :call
|
86
|
+
|
87
|
+
insert_hook owner, event, priority, &block
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.insert_hook(owner, event, priority, &block)
|
91
|
+
@hook_priority[block] = [-priority, @hook_priority.size]
|
92
|
+
@registry[owner][event] << block
|
93
|
+
end
|
94
|
+
|
95
|
+
# interface for Jekyll core components to trigger hooks
|
96
|
+
def self.trigger(owner, event, *args)
|
97
|
+
# proceed only if there are hooks to call
|
98
|
+
hooks = @registry.dig(owner, event)
|
99
|
+
return if hooks.nil? || hooks.empty?
|
100
|
+
|
101
|
+
# sort and call hooks according to priority and load order
|
102
|
+
hooks.sort_by { |h| @hook_priority[h] }.each do |hook|
|
103
|
+
hook.call(*args)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
class Inclusion
|
5
|
+
attr_reader :site, :name, :path
|
6
|
+
private :site
|
7
|
+
|
8
|
+
def initialize(site, base, name)
|
9
|
+
@site = site
|
10
|
+
@name = name
|
11
|
+
@path = PathManager.join(base, name)
|
12
|
+
end
|
13
|
+
|
14
|
+
def render(context)
|
15
|
+
@template ||= site.liquid_renderer.file(path).parse(content)
|
16
|
+
@template.render!(context)
|
17
|
+
rescue Liquid::Error => e
|
18
|
+
e.template_name = path
|
19
|
+
e.markup_context = "included " if e.markup_context.nil?
|
20
|
+
raise e
|
21
|
+
end
|
22
|
+
|
23
|
+
def content
|
24
|
+
@content ||= File.read(path, **site.file_read_opts)
|
25
|
+
end
|
26
|
+
|
27
|
+
def inspect
|
28
|
+
"#{self.class} #{path.inspect}"
|
29
|
+
end
|
30
|
+
alias_method :to_s, :inspect
|
31
|
+
end
|
32
|
+
end
|
data/lib/jekyll/layout.rb
CHANGED
@@ -1,62 +1,67 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Jekyll
|
4
|
-
class Layout
|
5
|
-
include Convertible
|
6
|
-
|
7
|
-
# Gets the Site object.
|
8
|
-
attr_reader :site
|
9
|
-
|
10
|
-
# Gets the name of this layout.
|
11
|
-
attr_reader :name
|
12
|
-
|
13
|
-
# Gets the path to this layout.
|
14
|
-
attr_reader :path
|
15
|
-
|
16
|
-
# Gets the path to this layout relative to its base
|
17
|
-
attr_reader :relative_path
|
18
|
-
|
19
|
-
# Gets/Sets the extension of this layout.
|
20
|
-
attr_accessor :ext
|
21
|
-
|
22
|
-
# Gets/Sets the Hash that holds the metadata for this layout.
|
23
|
-
attr_accessor :data
|
24
|
-
|
25
|
-
# Gets/Sets the content of this layout.
|
26
|
-
attr_accessor :content
|
27
|
-
|
28
|
-
# Initialize a new Layout.
|
29
|
-
#
|
30
|
-
# site - The Site.
|
31
|
-
# base - The String path to the source.
|
32
|
-
# name - The String filename of the post file.
|
33
|
-
def initialize(site, base, name)
|
34
|
-
@site = site
|
35
|
-
@base = base
|
36
|
-
@name = name
|
37
|
-
|
38
|
-
if site.theme && site.theme.layouts_path.eql?(base)
|
39
|
-
@base_dir = site.theme.root
|
40
|
-
@path = site.in_theme_dir(base, name)
|
41
|
-
else
|
42
|
-
@base_dir = site.source
|
43
|
-
@path = site.in_source_dir(base, name)
|
44
|
-
end
|
45
|
-
@relative_path = @path.sub(@base_dir, "")
|
46
|
-
|
47
|
-
self.data = {}
|
48
|
-
|
49
|
-
process(name)
|
50
|
-
read_yaml(base, name)
|
51
|
-
end
|
52
|
-
|
53
|
-
# Extract information from the layout filename.
|
54
|
-
#
|
55
|
-
# name - The String filename of the layout file.
|
56
|
-
#
|
57
|
-
# Returns nothing.
|
58
|
-
def process(name)
|
59
|
-
self.ext = File.extname(name)
|
60
|
-
end
|
61
|
-
|
62
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
class Layout
|
5
|
+
include Convertible
|
6
|
+
|
7
|
+
# Gets the Site object.
|
8
|
+
attr_reader :site
|
9
|
+
|
10
|
+
# Gets the name of this layout.
|
11
|
+
attr_reader :name
|
12
|
+
|
13
|
+
# Gets the path to this layout.
|
14
|
+
attr_reader :path
|
15
|
+
|
16
|
+
# Gets the path to this layout relative to its base
|
17
|
+
attr_reader :relative_path
|
18
|
+
|
19
|
+
# Gets/Sets the extension of this layout.
|
20
|
+
attr_accessor :ext
|
21
|
+
|
22
|
+
# Gets/Sets the Hash that holds the metadata for this layout.
|
23
|
+
attr_accessor :data
|
24
|
+
|
25
|
+
# Gets/Sets the content of this layout.
|
26
|
+
attr_accessor :content
|
27
|
+
|
28
|
+
# Initialize a new Layout.
|
29
|
+
#
|
30
|
+
# site - The Site.
|
31
|
+
# base - The String path to the source.
|
32
|
+
# name - The String filename of the post file.
|
33
|
+
def initialize(site, base, name)
|
34
|
+
@site = site
|
35
|
+
@base = base
|
36
|
+
@name = name
|
37
|
+
|
38
|
+
if site.theme && site.theme.layouts_path.eql?(base)
|
39
|
+
@base_dir = site.theme.root
|
40
|
+
@path = site.in_theme_dir(base, name)
|
41
|
+
else
|
42
|
+
@base_dir = site.source
|
43
|
+
@path = site.in_source_dir(base, name)
|
44
|
+
end
|
45
|
+
@relative_path = @path.sub(@base_dir, "")
|
46
|
+
|
47
|
+
self.data = {}
|
48
|
+
|
49
|
+
process(name)
|
50
|
+
read_yaml(base, name)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Extract information from the layout filename.
|
54
|
+
#
|
55
|
+
# name - The String filename of the layout file.
|
56
|
+
#
|
57
|
+
# Returns nothing.
|
58
|
+
def process(name)
|
59
|
+
self.ext = File.extname(name)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Returns the object as a debug String.
|
63
|
+
def inspect
|
64
|
+
"#<#{self.class} @path=#{@path.inspect}>"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -1,22 +1,22 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Jekyll
|
4
|
-
module LiquidExtensions
|
5
|
-
# Lookup a Liquid variable in the given context.
|
6
|
-
#
|
7
|
-
# context - the Liquid context in question.
|
8
|
-
# variable - the variable name, as a string.
|
9
|
-
#
|
10
|
-
# Returns the value of the variable in the context
|
11
|
-
# or the variable name if not found.
|
12
|
-
def lookup_variable(context, variable)
|
13
|
-
lookup = context
|
14
|
-
|
15
|
-
variable.split(".").each do |value|
|
16
|
-
lookup = lookup[value]
|
17
|
-
end
|
18
|
-
|
19
|
-
lookup || variable
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module LiquidExtensions
|
5
|
+
# Lookup a Liquid variable in the given context.
|
6
|
+
#
|
7
|
+
# context - the Liquid context in question.
|
8
|
+
# variable - the variable name, as a string.
|
9
|
+
#
|
10
|
+
# Returns the value of the variable in the context
|
11
|
+
# or the variable name if not found.
|
12
|
+
def lookup_variable(context, variable)
|
13
|
+
lookup = context
|
14
|
+
|
15
|
+
variable.split(".").each do |value|
|
16
|
+
lookup = lookup[value]
|
17
|
+
end
|
18
|
+
|
19
|
+
lookup || variable
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,77 +1,77 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Jekyll
|
4
|
-
class LiquidRenderer
|
5
|
-
class File
|
6
|
-
def initialize(renderer, filename)
|
7
|
-
@renderer = renderer
|
8
|
-
@filename = filename
|
9
|
-
end
|
10
|
-
|
11
|
-
def parse(content)
|
12
|
-
measure_time do
|
13
|
-
@renderer.cache[@filename] ||= Liquid::Template.parse(content, :line_numbers => true)
|
14
|
-
end
|
15
|
-
@template = @renderer.cache[@filename]
|
16
|
-
|
17
|
-
self
|
18
|
-
end
|
19
|
-
|
20
|
-
def render(*args)
|
21
|
-
reset_template_assigns
|
22
|
-
|
23
|
-
measure_time do
|
24
|
-
measure_bytes do
|
25
|
-
measure_counts do
|
26
|
-
@template.render(*args)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
# This method simply 'rethrows any error' before attempting to render the template.
|
33
|
-
def render!(*args)
|
34
|
-
reset_template_assigns
|
35
|
-
|
36
|
-
measure_time do
|
37
|
-
measure_bytes do
|
38
|
-
measure_counts do
|
39
|
-
@template.render!(*args)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def warnings
|
46
|
-
@template.warnings
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
# clear assigns to `Liquid::Template` instance prior to rendering since
|
52
|
-
# `Liquid::Template` instances are cached in Jekyll 4.
|
53
|
-
def reset_template_assigns
|
54
|
-
@template.instance_assigns.clear
|
55
|
-
end
|
56
|
-
|
57
|
-
def measure_counts
|
58
|
-
@renderer.increment_count(@filename)
|
59
|
-
yield
|
60
|
-
end
|
61
|
-
|
62
|
-
def measure_bytes
|
63
|
-
yield.tap do |str|
|
64
|
-
@renderer.increment_bytes(@filename, str.bytesize)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def measure_time
|
69
|
-
before = Time.now
|
70
|
-
yield
|
71
|
-
ensure
|
72
|
-
after = Time.now
|
73
|
-
@renderer.increment_time(@filename, after - before)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
class LiquidRenderer
|
5
|
+
class File
|
6
|
+
def initialize(renderer, filename)
|
7
|
+
@renderer = renderer
|
8
|
+
@filename = filename
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse(content)
|
12
|
+
measure_time do
|
13
|
+
@renderer.cache[@filename] ||= Liquid::Template.parse(content, :line_numbers => true)
|
14
|
+
end
|
15
|
+
@template = @renderer.cache[@filename]
|
16
|
+
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def render(*args)
|
21
|
+
reset_template_assigns
|
22
|
+
|
23
|
+
measure_time do
|
24
|
+
measure_bytes do
|
25
|
+
measure_counts do
|
26
|
+
@template.render(*args)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# This method simply 'rethrows any error' before attempting to render the template.
|
33
|
+
def render!(*args)
|
34
|
+
reset_template_assigns
|
35
|
+
|
36
|
+
measure_time do
|
37
|
+
measure_bytes do
|
38
|
+
measure_counts do
|
39
|
+
@template.render!(*args)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def warnings
|
46
|
+
@template.warnings
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
# clear assigns to `Liquid::Template` instance prior to rendering since
|
52
|
+
# `Liquid::Template` instances are cached in Jekyll 4.
|
53
|
+
def reset_template_assigns
|
54
|
+
@template.instance_assigns.clear
|
55
|
+
end
|
56
|
+
|
57
|
+
def measure_counts
|
58
|
+
@renderer.increment_count(@filename)
|
59
|
+
yield
|
60
|
+
end
|
61
|
+
|
62
|
+
def measure_bytes
|
63
|
+
yield.tap do |str|
|
64
|
+
@renderer.increment_bytes(@filename, str.bytesize)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def measure_time
|
69
|
+
before = Time.now
|
70
|
+
yield
|
71
|
+
ensure
|
72
|
+
after = Time.now
|
73
|
+
@renderer.increment_time(@filename, after - before)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|