simplify internal engine functions
now they tend to take in functions instead of files
This commit is contained in:
parent
0b7f0fd888
commit
3565101316
1 changed files with 20 additions and 22 deletions
42
engine.nix
42
engine.nix
|
@ -15,22 +15,21 @@ pkgs: src: {extraArgs, entries, templates}: let
|
||||||
isBaseTemplate = template:
|
isBaseTemplate = template:
|
||||||
isString template.output;
|
isString template.output;
|
||||||
|
|
||||||
findTemplateFile = entry: let
|
findTemplateFn = entry: let
|
||||||
_template = findFirst (templateFile: let
|
template = findFirst (templateFile: let
|
||||||
templateFn = import templateFile;
|
templateFn = import templateFile;
|
||||||
template = templateFn (functionArgs templateFn);
|
template' = templateFn (functionArgs templateFn);
|
||||||
in
|
in
|
||||||
template.name == entry.template)
|
template'.name == entry.template)
|
||||||
null
|
null
|
||||||
templates;
|
templates;
|
||||||
in
|
in
|
||||||
if _template == null then
|
if template == null then
|
||||||
abort "unknown template `${entry.template}`"
|
abort "unknown template `${entry.template}`"
|
||||||
else
|
else
|
||||||
_template;
|
(import template);
|
||||||
|
|
||||||
applyTemplate = templateFile: entry: let
|
applyTemplate = templateFn: entry: let
|
||||||
templateFn = import templateFile;
|
|
||||||
template = templateFn (args // entry);
|
template = templateFn (args // entry);
|
||||||
in
|
in
|
||||||
if isBaseTemplate template then {
|
if isBaseTemplate template then {
|
||||||
|
@ -39,9 +38,9 @@ pkgs: src: {extraArgs, entries, templates}: let
|
||||||
}
|
}
|
||||||
else let
|
else let
|
||||||
newEntry = template.output // {inherit (entry) file;};
|
newEntry = template.output // {inherit (entry) file;};
|
||||||
foundTemplateFile = findTemplateFile newEntry;
|
foundTemplateFn = findTemplateFn newEntry;
|
||||||
in
|
in
|
||||||
applyTemplate foundTemplateFile newEntry;
|
applyTemplate foundTemplateFn newEntry;
|
||||||
|
|
||||||
replaceSuffix = from: to: string:
|
replaceSuffix = from: to: string:
|
||||||
if !(hasSuffix from string) then
|
if !(hasSuffix from string) then
|
||||||
|
@ -49,8 +48,7 @@ pkgs: src: {extraArgs, entries, templates}: let
|
||||||
else
|
else
|
||||||
concatStrings [ (removeSuffix from string) to ];
|
concatStrings [ (removeSuffix from string) to ];
|
||||||
|
|
||||||
getTemplateFormat = entry: templateFile: let
|
getTemplateFormat = entry: templateFn: let
|
||||||
templateFn = import templateFile;
|
|
||||||
# getEntry needs to go down to the base template for the format
|
# getEntry needs to go down to the base template for the format
|
||||||
# but any template through the way can ask for a file
|
# but any template through the way can ask for a file
|
||||||
# so we just give it a placeholder - an empty string here
|
# so we just give it a placeholder - an empty string here
|
||||||
|
@ -61,15 +59,15 @@ pkgs: src: {extraArgs, entries, templates}: let
|
||||||
template.format
|
template.format
|
||||||
else let
|
else let
|
||||||
newEntry = template.output;
|
newEntry = template.output;
|
||||||
foundTemplateFile = findTemplateFile newEntry;
|
foundTemplateFn = findTemplateFn newEntry;
|
||||||
in
|
in
|
||||||
getTemplateFormat newEntry foundTemplateFile;
|
getTemplateFormat newEntry foundTemplateFn;
|
||||||
|
|
||||||
getEntry = entryFile: let
|
getEntry = entryFile: let
|
||||||
sourceFile = toString (removePrefix src entryFile);
|
sourceFile = toString (removePrefix src entryFile);
|
||||||
entry = (import entryFile) args;
|
entry = (import entryFile) args;
|
||||||
foundTemplateFile = findTemplateFile entry;
|
foundTemplateFn = findTemplateFn entry;
|
||||||
entryFormat = getTemplateFormat entry foundTemplateFile;
|
entryFormat = getTemplateFormat entry foundTemplateFn;
|
||||||
in
|
in
|
||||||
if !(hasAttr "file" entry) then
|
if !(hasAttr "file" entry) then
|
||||||
entry // {
|
entry // {
|
||||||
|
@ -79,10 +77,10 @@ pkgs: src: {extraArgs, entries, templates}: let
|
||||||
entry;
|
entry;
|
||||||
|
|
||||||
processEntryFile = entryFile: let
|
processEntryFile = entryFile: let
|
||||||
foundTemplateFile = findTemplateFile entry;
|
foundTemplateFn = findTemplateFn entry;
|
||||||
entry = getEntry entryFile;
|
entry = getEntry entryFile;
|
||||||
in
|
in
|
||||||
applyTemplate foundTemplateFile entry;
|
applyTemplate foundTemplateFn entry;
|
||||||
|
|
||||||
in /*sh*/''
|
in /*sh*/''
|
||||||
${concatMapStrings
|
${concatMapStrings
|
||||||
|
|
Loading…
Reference in a new issue