Class: Liquid2::HashLoader
- Inherits:
-
TemplateLoader
- Object
- TemplateLoader
- Liquid2::HashLoader
- Defined in:
- lib/liquid2/loader.rb
Overview
A template loader that reads templates from a hash.
Instance Method Summary collapse
-
#get_source(env, name, context: nil, **kwargs) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#initialize(templates) ⇒ HashLoader
constructor
A new instance of HashLoader.
Methods inherited from TemplateLoader
Constructor Details
#initialize(templates) ⇒ HashLoader
Returns a new instance of HashLoader.
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 |