Class: Luoma::HashLoader

Inherits:
TemplateLoader show all
Defined in:
lib/luoma/loader.rb,
sig/luoma/loader.rbs

Overview

A template loader that reads templates from a hash.

Instance Method Summary collapse

Methods inherited from TemplateLoader

#load

Constructor Details

#initialize(templates) ⇒ HashLoader

Returns a new instance of HashLoader.

Signature:

  • (Hash<String, String>) -> void

Parameters:

  • templates (Hash[String, String])


38
39
40
41
# File 'lib/luoma/loader.rb', line 38

def initialize(templates)
  super()
  @templates = templates
end

Instance Method Details

#get_source(env, name, context: nil, **kwargs) ⇒ Object



43
44
45
46
47
48
# File 'lib/luoma/loader.rb', line 43

def get_source(env, name, context: nil, **kwargs)
  source = @templates[name]
  raise TemplateNotFoundError.new("template not found #{name}") unless source

  TemplateSource.new(source: source, name: name)
end