add applyTemplateFile

applyTemplate now returns the output alone and that's the version passed
to all entries and shit

this allows a user (krizej) to do inline templates
This commit is contained in:
jacekpoz 2024-09-13 16:05:30 +02:00
parent 592db7009f
commit e7543840b0
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8

View file

@ -32,16 +32,19 @@ pkgs: src: {extraArgs, entries, templates}: let
applyTemplate = templateFn: entry: let
template = templateFn (args // entry);
in
if isBaseTemplate template then {
inherit (entry) file;
inherit (template) output;
}
if isBaseTemplate template then
template.output
else let
newEntry = template.output // {inherit (entry) file;};
newEntry = template.output;
foundTemplateFn = findTemplateFn newEntry;
in
applyTemplate foundTemplateFn newEntry;
applyTemplateFile = templateFn: entry: {
inherit (entry) file;
output = applyTemplate templateFn entry;
};
replaceSuffix = from: to: string:
if !(hasSuffix from string) then
abort "invalid suffix `${from}` for string `${string}`"
@ -80,7 +83,7 @@ pkgs: src: {extraArgs, entries, templates}: let
foundTemplateFn = findTemplateFn entry;
entry = getEntry entryFile;
in
applyTemplate foundTemplateFn entry;
applyTemplateFile foundTemplateFn entry;
in /*sh*/''
${concatMapStrings