Generation Engine#
Prept provides a rich API to facilitate dynamic behavior at generation time. The components of this API are documented on this page.
- class prept.GenerationEngine#
Engine for dynamic operations at generation time.
This class provides a rich interface for manipulating the generation time behavior.
Added in version 0.2.0.
- add_processor(path: str, proc_func: ProcessorFunctionT) None#
Registers a processor function for given path.
Processor function must take
GenerationContextas the only parameter.- Parameters:
path (
str) – The path or gitignore-like pattern for which processor is being defined. Files at this path will be processed through this processor.proc_func – The processor function.
- get_processors(path: str) tuple[ProcessorFunctionT, ...]#
Get the processors registered for the given path.
Returns a tuple of processor function objects.
- remove_processor(path: str, proc_func: ProcessorFunctionT) None#
Registers a processor function for given path.
Processor function must take
GenerationContextas the only parameter.ValueError is raised if no processor is registered for the given path.
- Parameters:
path (
str) – The path or gitignore-like pattern for which processor is being defined. Files at this path will be processed through this processor.proc_func – The processor function.
- clear_processors(path: str) None#
Removes all processors for the given path.
- processor(path: str) Callable[[ProcessorFunctionT], ProcessorFunctionT]#
Decorator interface for
add_processor()This decorator takes the same parameters as
add_processor()method and the decorated function must takeGenerationContextas only parameter.
- pre_generation_hook(func: GenerationHook) GenerationHook#
Decorator to register a pre-generation hook.
The function decorated by this method will be called when generation starts, before generation of any file.
- post_generation_hook(func: GenerationHook) GenerationHook#
Decorator to register a post-generation hook.
The function decorated by this method will be called when all files have been generated successfully.