asset忘了上传了,重新传一下,增加了模板引擎(见README),修复了printable的目录bug
This commit is contained in:
commit
294abad18b
550 files changed
+62291
No files matched your search
@@ -0,0 +1,68 @@
|
||||
import { assertEquals } from "@std/assert";
|
||||
import { parse as parseToml } from "@std/toml";
|
||||
import { createTemplateVariables, renderTemplate } from "./template_engine.ts";
|
||||
|
||||
Deno.test("renders Nunjucks variables, conditionals, loops, and constants", () => {
|
||||
const result = renderTemplate(
|
||||
`{% set color = "red" %}{% if enabled %}{% for item in items %}{{ item }}:{{ color }};{% endfor %}{% endif %}`,
|
||||
{ enabled: true, items: ["a", "b"] },
|
||||
);
|
||||
assertEquals(result, "a:red;b:red;");
|
||||
});
|
||||
|
||||
Deno.test("parses TOML variables and applies CLI overrides", async () => {
|
||||
const path = await Deno.makeTempFile({ suffix: ".toml" });
|
||||
try {
|
||||
await Deno.writeTextFile(path, `title = "From TOML"\ncount = 2\n`);
|
||||
const variables = await createTemplateVariables({
|
||||
"vars-file": path,
|
||||
title: "From CLI",
|
||||
enabled: "false",
|
||||
}, { journal: { variables: { fallback: true } } });
|
||||
assertEquals(variables.title, "From CLI");
|
||||
assertEquals(variables.count, 2);
|
||||
assertEquals(variables.enabled, false);
|
||||
assertEquals(variables.fallback, true);
|
||||
assertEquals(typeof variables.currentDate, "string");
|
||||
} finally {
|
||||
await Deno.remove(path);
|
||||
}
|
||||
});
|
||||
|
||||
Deno.test("config TOML variables are included below per-setting and CLI values", async () => {
|
||||
const path = await Deno.makeTempFile({ suffix: ".toml" });
|
||||
try {
|
||||
await Deno.writeTextFile(path, `title = "From file"\n`);
|
||||
const variables = await createTemplateVariables(
|
||||
{
|
||||
"vars-file": path,
|
||||
title: "From CLI",
|
||||
},
|
||||
{ journal: { variables: { title: "From setting", setting: true } } },
|
||||
{
|
||||
title: "From config",
|
||||
global: true,
|
||||
},
|
||||
);
|
||||
assertEquals(variables.title, "From CLI");
|
||||
assertEquals(variables.global, true);
|
||||
assertEquals(variables.setting, true);
|
||||
} finally {
|
||||
await Deno.remove(path);
|
||||
}
|
||||
});
|
||||
|
||||
Deno.test("default TOML config contains build settings and vars tables", async () => {
|
||||
const config = parseToml(await Deno.readTextFile("./config.toml")) as {
|
||||
asset_base: string;
|
||||
settings: Array<{ name: string }>;
|
||||
vars: Record<string, unknown>;
|
||||
};
|
||||
assertEquals(config.asset_base, "../../assets");
|
||||
assertEquals(config.settings.map((setting) => setting.name), [
|
||||
"mobile",
|
||||
"computer",
|
||||
"printable",
|
||||
]);
|
||||
assertEquals(typeof config.vars, "object");
|
||||
});
|
||||
Reference in new issue
Block a user