class Jekyll::LiquidRenderer

Public Class Methods

format_error(error, path) click to toggle source
# File lib/jekyll/liquid_renderer.rb, line 53
def self.format_error(error, path)
  "#{error.message} in #{path}"
end
new(site) click to toggle source
# File lib/jekyll/liquid_renderer.rb, line 13
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 61
def cache
  @cache ||= {}
end
file(filename) click to toggle source
# File lib/jekyll/liquid_renderer.rb, line 24
def file(filename)
  filename.match(filename_regex)
  filename =
    if Regexp.last_match(1) == theme_dir("")
      ::File.join(::File.basename(Regexp.last_match(1)), Regexp.last_match(2))
    else
      Regexp.last_match(2)
    end
  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 37
def increment_bytes(filename, bytes)
  @stats[filename][:bytes] += bytes
end
increment_count(filename) click to toggle source
# File lib/jekyll/liquid_renderer.rb, line 45
def increment_count(filename)
  @stats[filename][:count] += 1
end
increment_time(filename, time) click to toggle source
# File lib/jekyll/liquid_renderer.rb, line 41
def increment_time(filename, time)
  @stats[filename][:time] += time
end
measure_time() { || ... } click to toggle source
# File lib/jekyll/liquid_renderer/file.rb, line 58
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 19
def reset
  @stats = {}
  @cache = {}
end
stats_table(num_of_rows = 50) click to toggle source
# File lib/jekyll/liquid_renderer.rb, line 49
def stats_table(num_of_rows = 50)
  LiquidRenderer::Table.new(@stats).to_s(num_of_rows)
end

Private Instance Methods

filename_regex() click to toggle source
# File lib/jekyll/liquid_renderer.rb, line 67
def filename_regex
  @filename_regex ||= begin
    %r!\A(#{Regexp.escape(source_dir)}/|#{Regexp.escape(theme_dir.to_s)}/|/*)(.*)!i
  end
end
new_profile_hash() click to toggle source
# File lib/jekyll/liquid_renderer.rb, line 73
def new_profile_hash
  Hash.new { |hash, key| hash[key] = 0 }
end