class Jekyll::LiquidRenderer
Public Class Methods
format_error(error, path)
click to toggle source
# File lib/jekyll/liquid_renderer.rb, line 42 def self.format_error(error, path) "#{error.message} in #{path}" end
new(site)
click to toggle source
# File lib/jekyll/liquid_renderer.rb, line 8 def initialize(site) @site = site Liquid::Template.error_mode = @site.config["liquid"]["error_mode"].to_sym reset end
Public Instance Methods
cache()
click to toggle source
A persistent cache to store and retrieve parsed templates based on the filename via ‘LiquidRenderer::File#parse`
It is emptied when ‘self.reset` is called.
# File lib/jekyll/liquid_renderer.rb, line 50 def cache @cache ||= {} end
file(filename)
click to toggle source
# File lib/jekyll/liquid_renderer.rb, line 19 def file(filename) filename = normalize_path(filename) LiquidRenderer::File.new(self, filename).tap do @stats[filename] ||= new_profile_hash end end
increment_bytes(filename, bytes)
click to toggle source
# File lib/jekyll/liquid_renderer.rb, line 26 def increment_bytes(filename, bytes) @stats[filename][:bytes] += bytes end
increment_count(filename)
click to toggle source
# File lib/jekyll/liquid_renderer.rb, line 34 def increment_count(filename) @stats[filename][:count] += 1 end
increment_time(filename, time)
click to toggle source
# File lib/jekyll/liquid_renderer.rb, line 30 def increment_time(filename, time) @stats[filename][:time] += time end
measure_time() { || ... }
click to toggle source
# File lib/jekyll/liquid_renderer/file.rb, line 68 def measure_time before = Time.now yield ensure after = Time.now @renderer.increment_time(@filename, after - before) end
reset()
click to toggle source
# File lib/jekyll/liquid_renderer.rb, line 14 def reset @stats = {} @cache = {} end
stats_table(num_of_rows = 50)
click to toggle source
# File lib/jekyll/liquid_renderer.rb, line 38 def stats_table(num_of_rows = 50) LiquidRenderer::Table.new(@stats).to_s(num_of_rows) end
Private Instance Methods
new_profile_hash()
click to toggle source
# File lib/jekyll/liquid_renderer.rb, line 76 def new_profile_hash Hash.new { |hash, key| hash[key] = 0 } end
normalize_path(filename)
click to toggle source
# File lib/jekyll/liquid_renderer.rb, line 56 def normalize_path(filename) @normalize_path ||= {} @normalize_path[filename] ||= begin theme_dir = @site.theme&.root case filename when %r!\A(#{Regexp.escape(@site.source)}/)(?<rest>.*)!io Regexp.last_match(:rest) when %r!(/gems/.*)*/gems/(?<dirname>[^/]+)(?<rest>.*)!, %r!(?<dirname>[^/]+/lib)(?<rest>.*)! "#{Regexp.last_match(:dirname)}#{Regexp.last_match(:rest)}" when theme_dir && %r!\A#{Regexp.escape(theme_dir)}/(?<rest>.*)!io PathManager.join(@site.theme.basename, Regexp.last_match(:rest)) when %r!\A/(.*)! Regexp.last_match(1) else filename end end end