From 78d7fc46febe3f2d5ebc1bea4761d115bb26f117 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Tue, 11 Oct 2022 21:40:21 +0200 Subject: Lua: add function `pandoc.template.apply` The new function applies a context, containing variable assignments, to a template. --- .../test/lua/module/pandoc-template.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'pandoc-lua-engine/test/lua') diff --git a/pandoc-lua-engine/test/lua/module/pandoc-template.lua b/pandoc-lua-engine/test/lua/module/pandoc-template.lua index 5b31e5ae0..bda24da65 100644 --- a/pandoc-lua-engine/test/lua/module/pandoc-template.lua +++ b/pandoc-lua-engine/test/lua/module/pandoc-template.lua @@ -62,4 +62,24 @@ return { ) end), }, + group 'apply' { + test('is function', function () + assert.are_equal(type(template.apply), 'function') + end), + test('returns a Doc value', function () + local tmpl = template.compile('placeholder') + assert.are_equal( + pandoc.utils.type(template.apply(tmpl, {})), + 'Doc' + ) + end), + test('applies the given context', function () + local tmpl = template.compile('song: $title$') + local context = {title = 'Along Comes Mary'} + assert.are_equal( + template.apply(tmpl, context):render(), + 'song: Along Comes Mary' + ) + end), + }, } -- cgit v1.2.3