class Bridgetown::LiquidRenderer
Public Class Methods
format_error(error, path)
click to toggle source
# File lib/bridgetown-core/liquid_renderer.rb, line 56 def self.format_error(error, path) "#{error.message} in #{path}" end
new(site)
click to toggle source
# File lib/bridgetown-core/liquid_renderer.rb, line 13 def initialize(site) @site = site # Set up Liquid file system access to components for the Render tag Liquid::Template.file_system = LiquidRenderer::FileSystem.new( @site.components_load_paths, "%s.liquid" ) Liquid::Template.file_system.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/bridgetown-core/liquid_renderer.rb, line 64 def cache @cache ||= {} end
file(filename)
click to toggle source
# File lib/bridgetown-core/liquid_renderer.rb, line 32 def file(filename) filename.match(filename_regex) filename = Regexp.last_match(2) LiquidRenderer::File.new(self, filename).tap do @stats[filename] ||= new_profile_hash end end
increment_bytes(filename, bytes)
click to toggle source
# File lib/bridgetown-core/liquid_renderer.rb, line 40 def increment_bytes(filename, bytes) @stats[filename][:bytes] += bytes end
increment_count(filename)
click to toggle source
# File lib/bridgetown-core/liquid_renderer.rb, line 48 def increment_count(filename) @stats[filename][:count] += 1 end
increment_time(filename, time)
click to toggle source
# File lib/bridgetown-core/liquid_renderer.rb, line 44 def increment_time(filename, time) @stats[filename][:time] += time end
measure_time() { || ... }
click to toggle source
# File lib/bridgetown-core/liquid_renderer/file.rb, line 61 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/bridgetown-core/liquid_renderer.rb, line 26 def reset @stats = {} @cache = {} Bridgetown::Converters::LiquidTemplates.cached_partials = {} end
stats_table(num_of_rows = 50)
click to toggle source
# File lib/bridgetown-core/liquid_renderer.rb, line 52 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/bridgetown-core/liquid_renderer.rb, line 70 def filename_regex @filename_regex ||= begin %r!\A(#{Regexp.escape(source_dir)}/|/*)(.*)!i end end
new_profile_hash()
click to toggle source
# File lib/bridgetown-core/liquid_renderer.rb, line 76 def new_profile_hash Hash.new { |hash, key| hash[key] = 0 } end