textX generator framework based on Jinja template engine
Project description
textX-jinja
Jinja based framework for textX generators. Use if you need to generate a set of template-based files from textX models.
How to use?
-
Create a folder containing files and folder which resemble the structure you want to generate. Each file may be a Jinja template (should end with
.jinja
extension). -
File names may contain variable parts in the form
__<varible name>__
(double underscores around the variable name). These parts of file names will be replaced by the value of the variable from the generator context. If the variable is iterable, a file will be created for each object. In that case, the value for substitution in the file name will be created by functionmap_names
, if given, orstr
of the object itself. The object will be available in the template under the nameobj
(support for iterables is still WIP!). If the variable is ofbool
type the file will be skipped if the variable value isFalse
. -
In your textX project register a generator (see registration).
from textx import generator from textxjinja import textx_jinja_generator @generator('mylang', 'mytarget') def mygenerator(metamodel, model, output_path, overwrite, debug): # template directory template_folder = os.path.join(os.path.dirname(__file__), 'templates') # create config dict with all variables that should be accessible # by templates config = {'some_variable': 'some value'} # Optionally provide Jinja filters def striptabs(s): return re.sub(r'^[ \t]+', '', s, flags=re.M) filters = { 'striptabs': striptabs } # call the generator textx_jinja_generator(template_folder, output_path, config, overwrite, filters)
-
Install your project (recommended is the usage of Python virtual environment):
pip install -e <path to your project>
-
Run your textX generator as usual:
$ textx generate ...
The generator will use the template folder for rendering files using Jinja
template engine. All files from the template folder which are not Jinja
templates (don't end with .jinja
' extensions) will be copied over to the
target folder unchanged (variable substitutions in file names still apply).
As a full example of its usage see startproject generator in textX-dev
project.
Templates for the startproject
command are here.
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
Built Distribution
File details
Details for the file textX-jinja-0.2.0.tar.gz
.
File metadata
- Download URL: textX-jinja-0.2.0.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 733f54397e143a3c77df41edf03156f03fd84490505d0fa242c8a01377605751 |
|
MD5 | c45852a8f9282b329fa0067333c264ca |
|
BLAKE2b-256 | 50934c7f8888bb8220ea032f5941d47ae57a74769c73cb9d2a36bba2b00b836e |
Provenance
File details
Details for the file textX_jinja-0.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: textX_jinja-0.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2e04eebdab4b2f697ff82ef17619dcbb281064949964df275814f23cc416f86 |
|
MD5 | 1ec2e28bcff48a8afd36736c2db0b4f9 |
|
BLAKE2b-256 | 092b4ffb1a08e84993863c531b2f0caaccfed890619a1404fc0ccf7617d599c5 |