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.1.tar.gz
(4.6 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.1.tar.gz.
File metadata
- Download URL: jexpand-1.0.1.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad187fcdaa47e4eda263ef1d74640159fefdb0d8009316e999d6cd8b7f522d5d
|
|
| MD5 |
1a8e8a698ae5d8e03e7cf2c0c4aab30b
|
|
| BLAKE2b-256 |
306005045d3dc0514002e2fc72d0bac2a50cb8f201a32f349edb8241c9d12422
|
File details
Details for the file jexpand-1.0.1-py3-none-any.whl.
File metadata
- Download URL: jexpand-1.0.1-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a814220bc8a2e0e0b0f186147ead33b68165f81b04751209d848295831b1fea
|
|
| MD5 |
c94d6b39f96512114fbd878889df57fe
|
|
| BLAKE2b-256 |
5db2bd220d6558a8888ccf2ee9455e219ebb2e9c5e15deb21347c3c35739ddf5
|