Class: Liquid2::HashLoader

Inherits:
TemplateLoader show all
Defined in:
lib/liquid2/loader.rb

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.

Parameters:

  • templates (Hash<String, String>)

    A mapping of template names to template source text.



47
48
49
50
# File 'lib/liquid2/loader.rb', line 47

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

Instance Method Details

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

rubocop:disable Lint/UnusedMethodArgument



52
53
54
55
56
57
58
# File 'lib/liquid2/loader.rb', line 52

def get_source(env, name, context: nil, **kwargs) # rubocop:disable Lint/UnusedMethodArgument
  if (text = @templates[name])
    TemplateSource.new(source: text, name: name)
  else
    raise LiquidTemplateNotFoundError.new("template not found #{name}", nil)
  end
end