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