From 5902c57f42ced02d9c825bb7a6a41543499cc88a Mon Sep 17 00:00:00 2001 From: Alawode Oluwandabira Date: Fri, 21 May 2021 18:54:04 +0300 Subject: [PATCH] Add some Generator documentation. --- README.md | 16 ++++++++++++++++ src/Fornax.Core/Model.fs | 14 ++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e91b1c5..1da21c7 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,22 @@ let config = { ``` +Possible Generator Triggers are: +- `Once` : Runs once, globally. +- `OnFile filename`: Run once for the given filename. +- `OnFileExt extension` : Runs once for each file with the given extension. +- `OnFilePredicate predicate` : Runs once for each file satisfying the predicate (`string -> string`). + +Possible Generator Outputs are: +- `SameFileName` : Output has the same filename as input file. +- `ChangeExtension newExtension` : Output has the same filename but with extention change to `newExtension`. +- `NewFileName newFileName` : Output filename is `newFileName`. +- `Custom mapper` : Output filename is the result of applying the mapper to the input filename. +- `MultipleFiles mapper` : Outputs multiple files, the names of which are a result of applying the mapper to the first string output of the generator. + +**Note**: For `MultipleFiles` the `generate` function *must* output a `list`. + + ## How to contribute *Imposter syndrome disclaimer*: I want your help. No really, I do. diff --git a/src/Fornax.Core/Model.fs b/src/Fornax.Core/Model.fs index 2be61e0..bf871a4 100644 --- a/src/Fornax.Core/Model.fs +++ b/src/Fornax.Core/Model.fs @@ -1327,17 +1327,23 @@ module Config = | Once ///Generator runs once, for given filename (file name is relative to project root, for example `post/post.md`). It runs only if the given file exist. | OnFile of filename : string - ///Generator runs for any file with given extension (for example `md`) + ///Generator runs for any file with given extension (for example `md`). | OnFileExt of extension: string - ///Generator runs for any file matching predicate. Parameters of predicate are absolut path to project root, and path to the file relative to project root. + ///Generator runs for any file matching predicate. Parameters of predicate are absolute path to project root, and path to the file relative to project root. | OnFilePredicate of predicate: ((string * string) -> bool) type GeneratorOutput = + ///Generates a file with the same name. | SameFileName + ///Generates a file with the same base name but with the extension changed. | ChangeExtension of newExtension: string + ///Generates a file with name `newFileName`. | NewFileName of newFileName: string - | Custom of (string -> string) - | MultipleFiles of (string -> string) + ///Generates a file with the name as the result of `mapper orignalFileName`. + | Custom of mapper: (string -> string) + ///Generates multiple files with each name being the result of applying the mapper to the first string of the generator output. + ///The generator must have a type `SiteContents -> string -> string -> list` + | MultipleFiles of mapper: (string -> string) type GeneratorConfig = { Script: string