set context's template_name with template's name

This commit is contained in:
Michael Go
2023-02-28 10:55:38 -04:00
parent 428c66ffac
commit 24dceef552
7 changed files with 63 additions and 57 deletions
+7 -26
View File
@@ -39,11 +39,12 @@ module Minitest
def assert_template_result(
expected, template, assigns = {},
message: nil, partials: nil, error_mode: nil, render_errors: false
message: nil, partials: nil, error_mode: nil, render_errors: false,
template_factory: nil
)
template = Liquid::Template.parse(template, line_numbers: true, error_mode: error_mode&.to_sym)
file_system = StubFileSystem.new(partials || {})
registers = Liquid::Registers.new(file_system: file_system)
registers = Liquid::Registers.new(file_system: file_system, template_factory: template_factory)
context = Liquid::Context.build(static_environments: assigns, rethrow_errors: !render_errors, registers: registers)
output = template.render(context)
assert_equal(expected, output, message)
@@ -209,30 +210,10 @@ class StubTemplateFactory
@count = 0
end
def for(_template_name)
def for(template_name)
@count += 1
Liquid::Template.new
end
end
class MemoryFileSystem
def initialize(values)
# values is a hash of template_path => template_source
@snippets = {}
values.each do |file_path, source|
key = file_path.split('/').last.delete_suffix(".liquid")
@snippets[key] = {
source: source,
actual_template_name: file_path,
}
end
end
def read_template_file(template_name)
@snippets[template_name][:source]
end
def actual_template_name(template_name)
@snippets[template_name][:actual_template_name].delete_suffix(".liquid")
template = Liquid::Template.new
template.name = "some/path/" + template_name
template
end
end