Skip to content

Commit

Permalink
Add some Generator documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
oluwandabira authored and Krzysztof-Cieslak committed May 24, 2021
1 parent c9d8b94 commit 5902c57
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<string * string>`.


## How to contribute

*Imposter syndrome disclaimer*: I want your help. No really, I do.
Expand Down
14 changes: 10 additions & 4 deletions src/Fornax.Core/Model.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string * string>`
| MultipleFiles of mapper: (string -> string)

type GeneratorConfig = {
Script: string
Expand Down

0 comments on commit 5902c57

Please sign in to comment.