Class: Knot::Render::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/knot/render/template.rb

Class Method Summary collapse

Class Method Details

.cacheObject



21
22
23
# File 'lib/knot/render/template.rb', line 21

def self.cache
  @cache ||= {}
end

.clear_cache!Object



25
26
27
# File 'lib/knot/render/template.rb', line 25

def self.clear_cache!
  @cache = {}
end

.for(filename, search_paths) ⇒ Object

Raises:



4
5
6
7
8
9
10
11
# File 'lib/knot/render/template.rb', line 4

def self.for(filename, search_paths)
  filename += ".html.erb"
  directory = search_paths.find { |path| File.exist?(File.join(path, filename)) }

  raise NoTemplateError, "couldn't find template #{filename} in #{search_paths.join(", ")}" if directory.nil?

  template_for(File.join(directory, filename))
end

.template_for(filename) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/knot/render/template.rb', line 13

def self.template_for(filename)
  if cache.keys.include?(filename)
    cache[filename]
  else
    cache[filename] = ERB.new(File.read(filename))
  end
end