templify
File generation helper using a data dictionary and Jinja2 template files.
Input
- Data dictionary: The data used for rendering templates.
- Templates: The template files used for rendering. Supported formats:
- Jinja2 templates (
*.j2) - Injection templates (
*.inj)
- Jinja2 templates (
Output
- Rendered or updated files based on the provided templates and data dictionary.
Additional Features
- Recursive Rendering: Recursively render all
*.j2files in the given template folder. - Dynamic File/Folder Names: File or folder names can be rendered using the data dictionary.
- Manual Sections: Preserve specific sections in the output files that should not be overwritten when generating again. These sections are marked with
MANUAL SECTION STARTandMANUAL SECTION END. - Injection Templates: Use
*.injtemplates with regex patterns to inject content into specific parts of the output files.
Usage
Example Code
use HashMap;
use Path;
use RenderHelper;
use env_logger;
use env;
use ;
Example Template (template.j2)
Hello, {{ context.name }}!
This is a test template.
Example Output
Hello, World!
This is a test template.
Manual Sections
To preserve specific sections in the output files, use the following markers in your templates:
// MANUAL SECTION START: init-custom-var
// This content will be preserved.
custom_var = 1;
// MANUAL SECTION END
Injection Templates
To inject content into specific parts of the output files, use the following format in your templates:
<!-- injection-pattern: test-pattern -->
^(?P<injection>.*)$
<!-- injection-string-start -->
Injected Content
<!-- injection-string-end -->