Enhanced file expansion using Jinja2 templates
Project description
JExpand - Jinja2 Template File Expander
Enhanced file expansion using Jinja2 templates with flexible functionality for including files, conditional content, and more.
Installation
pip install -e .
Usage
Command Line
# Basic usage
jexpand template.md > expanded.md
# With output file
jexpand template.md --output_path expanded.md
# Non-strict mode (won't fail on missing files)
jexpand template.md --strict=False
Python Module
# Run as module
python -m jexpand template.md > expanded.md
Template Features
JExpand supports powerful Jinja2 templates with custom functions and filters:
Custom Functions
include_file(path)- Include the contents of a filefile_exists(path)- Check if a file existsfile_size(path)- Get file size in bytesfile_extension(path)- Get file extensionbasename(path)- Get basename of filedirname(path)- Get directory name of file
Custom Filters
code_block(language)- Wrap content in markdown code blockindent(spaces)- Indent each line with specified spacescomment_out(comment_char)- Comment out each line
Example Template
# My Project Documentation
## Source Implementation
{{ include_file('src/main.py') | code_block('python') }}
## Configuration
{% if file_exists('config.yaml') %}
{{ include_file('config.yaml') | code_block('yaml') }}
{% else %}
No configuration file found.
{% endif %}
## Multiple Files
{% for file_path in ['file1.py', 'file2.py'] %}
### {{ basename(file_path) }}
{{ include_file(file_path) | indent(4) }}
{% endfor %}
Development
Local Installation
# Install in development mode
pip install -e .
# Test the command
jexpand --help
Package Structure
jexpand/
├── jexpand/
│ ├── __init__.py # Main package code
│ └── __main__.py # Module entry point
├── pyproject.toml # Package configuration
├── README.md # This file
└── setup.py # Setuptools configuration
License
MIT License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
jexpand-1.0.0.tar.gz
(4.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jexpand-1.0.0.tar.gz.
File metadata
- Download URL: jexpand-1.0.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e4740381e6489f7bd18cea3b7d5489bf16f1369b403e679e8c6d4477da209bc
|
|
| MD5 |
34b53b02aa194bc3305d04c738f932dd
|
|
| BLAKE2b-256 |
e91276dbedc5a37e5e334f200ac8649c172c93e14e94ce9de3103a99dbf02c96
|
File details
Details for the file jexpand-1.0.0-py3-none-any.whl.
File metadata
- Download URL: jexpand-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9cdac68e6105d45cc42dc66fe9fc506f8bd96393dcdd4a91c08f0c642214bc80
|
|
| MD5 |
a2f4096afa32ca26d256066503cb6176
|
|
| BLAKE2b-256 |
c475fa9fcf09a65b36d1655d053738eb98edaf615b30800219a080e3f608e30d
|