Class: Bridgetown::LiquidRenderer

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/bridgetown-core/liquid_renderer.rb,
lib/bridgetown-core/liquid_renderer/file.rb,
lib/bridgetown-core/liquid_renderer/table.rb,
lib/bridgetown-core/liquid_renderer/file_system.rb

Defined Under Namespace

Classes: File, FileSystem, Table

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ LiquidRenderer

Returns a new instance of LiquidRenderer.



13
14
15
16
17
18
19
20
21
22
23
24
# 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.config.components_load_paths, "%s.liquid"
  )
  Liquid::Template.file_system.site = site

  Liquid::Template.error_mode = @site.config["liquid"]["error_mode"].to_sym
  reset
end

Class Method Details

.format_error(error, path) ⇒ Object



56
57
58
# File 'lib/bridgetown-core/liquid_renderer.rb', line 56

def self.format_error(error, path)
  "#{error.message} in #{path}"
end

Instance Method Details

#cacheObject

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.



64
65
66
# File 'lib/bridgetown-core/liquid_renderer.rb', line 64

def cache
  @cache ||= {}
end

#file(filename) ⇒ Object



32
33
34
35
36
37
38
# 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) ⇒ Object



40
41
42
# File 'lib/bridgetown-core/liquid_renderer.rb', line 40

def increment_bytes(filename, bytes)
  @stats[filename][:bytes] += bytes
end

#increment_count(filename) ⇒ Object



48
49
50
# File 'lib/bridgetown-core/liquid_renderer.rb', line 48

def increment_count(filename)
  @stats[filename][:count] += 1
end

#increment_time(filename, time) ⇒ Object



44
45
46
# File 'lib/bridgetown-core/liquid_renderer.rb', line 44

def increment_time(filename, time)
  @stats[filename][:time] += time
end

#resetObject



26
27
28
29
30
# 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) ⇒ Object



52
53
54
# 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