Class: Bunto::LiquidRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/bunto/liquid_renderer.rb,
lib/bunto/liquid_renderer/file.rb

Defined Under Namespace

Classes: File, Table

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ LiquidRenderer

Returns a new instance of LiquidRenderer.



6
7
8
9
10
# File 'lib/bunto/liquid_renderer.rb', line 6

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

Class Method Details

.format_error(e, path) ⇒ Object



43
44
45
46
47
48
# File 'lib/bunto/liquid_renderer.rb', line 43

def self.format_error(e, path)
  if e.is_a? Tags::IncludeTagError
    return "#{e.message} in #{e.path}, included in #{path}"
  end
  "#{e.message} in #{path}"
end

Instance Method Details

#file(filename) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/bunto/liquid_renderer.rb', line 16

def file(filename)
  filename = @site.in_source_dir(filename).sub(
    %r!\A#{Regexp.escape(@site.source)}/!,
    ""
  )

  LiquidRenderer::File.new(self, filename).tap do
    @stats[filename] ||= {}
    @stats[filename][:count] ||= 0
    @stats[filename][:count] += 1
  end
end

#increment_bytes(filename, bytes) ⇒ Object



29
30
31
32
# File 'lib/bunto/liquid_renderer.rb', line 29

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

#increment_time(filename, time) ⇒ Object



34
35
36
37
# File 'lib/bunto/liquid_renderer.rb', line 34

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

#resetObject



12
13
14
# File 'lib/bunto/liquid_renderer.rb', line 12

def reset
  @stats = {}
end

#stats_table(n = 50) ⇒ Object



39
40
41
# File 'lib/bunto/liquid_renderer.rb', line 39

def stats_table(n = 50)
  LiquidRenderer::Table.new(@stats).to_s(n)
end