Class: Cutaneous::CachedFileLoader

Inherits:
FileLoader show all
Defined in:
lib/cutaneous/loader.rb

Overview

Caches Template instances

Instance Attribute Summary

Attributes inherited from FileLoader

#format, #syntax, #template_class

Instance Method Summary collapse

Methods inherited from FileLoader

#convert, #exists?, #filename, #lexer, #location, #open_template, #path, #render

Constructor Details

#initialize(template_roots, format, extension = Cutaneous.extension) ⇒ CachedFileLoader

Returns a new instance of CachedFileLoader.



79
80
81
82
# File 'lib/cutaneous/loader.rb', line 79

def initialize(template_roots, format, extension = Cutaneous.extension)
  super
  @template_class = CachedTemplate
end

Instance Method Details

#template(template) ⇒ Object



96
97
98
99
# File 'lib/cutaneous/loader.rb', line 96

def template(template)
  return template_cache[template] if template_cache.key?(template)
  template_cache[template] = super
end

#template_cacheObject



84
85
86
# File 'lib/cutaneous/loader.rb', line 84

def template_cache
  @template_cache ||= {}
end

#write_compiled_scripts=(flag) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/cutaneous/loader.rb', line 88

def write_compiled_scripts=(flag)
  if flag
    @template_class = CachedTemplate
  else
    @template_class = Template
  end
end