Utility for generating files and directories from templates.
Project description
Introduction
PopPage is a simple command-line utility originally intended as a static website generator but has since grown into a cookiecutter clone. The main features of PopPage are:
Uses Jinja2 templates to generate output.
Fairly good support for cookiecutter templates.
Uses YAML to store default key/values for template variables.
Output can be single files or directories.
Key/values applied to the templates variables can specified on the command line.
A collection of templates is available here.
Status
Currently, this project is in the development release stage. While this project is suitable for use, please note that there may be incompatibilities in new releases.
Release notes are maintained in the project changelog.
Requirements
PopPage runs on Python 2.7/3.x and uses some third-party libraries.
Installation
PopPage is available on PyPI here and can be installed with pip using the following command: pip install poppage
Usage
PopPage can be run from the command line using poppage. Type poppage --help for usage information. The following subcommands are available:
check - Check the given INPATH template for variables.
make - Generates directories and files based on the given INPATH template.
run - Generates the OUTPATH, executes commands, then deletes OUTPATH.
Some Important Notes
Before showing any examples, keep these notes in mind:
Template file/directory names can contain template variables (e.g. {{foo}}.txt). The provided key/values will be used for the output file generation unless an explicit OUTPATH is provided.
The output will be passed to stdout if INPATH is a file (rather than a directory) and INPATH does not contain a template variable and no OUTPATH is specified.
CLI Key/Values
The following is a quick example of using PopPage from the CLI:
Template file (template.jinja2):
Hello {{name}}!
PopPage command:
poppage make --inpath template.jinja2 --string name world
Output to stdout:
Hello world!
YAML Key/Values
Additionally, default key/values can be stored in a YAML file:
Template file (template.jinja2):
Hello {{name}}!
Defaults file (defaults.yaml):
name: sun
PopPage command:
poppage make --inpath template.jinja2 --defaults defaults.yaml
Output to stdout:
Hello sun!
Option Defaults
Default utility options can be provided in the defaults file under the __opt__ root key.
Check out these examples:
Basic option defaults:
__opt__: inpath: template.jinja2 outpath: myfile.txt
Another options example:
__opt__: inpath: template.jinja2 outpath: myfile.py execute: python myfile.py
For make commands, multiple inpath and outpath pairs can be specified, the lists are zipped to join the pairs:
__opt__: command: make inpath: - template1.jinja2 - template2.jinja2 outpath: - myfile1.py - myfile2.py
The execute option can be a template:
__opt__: inpath: template.jinja2 execute: python {{outpath}}
Populate the options using a YAML file:
__opt__: !opt myopts.yaml
Demo Video
A quick demo video is available here on YouTube. This video demos using a single set of requirements information to generate native shell scripts for both Windows and Linux. The templates used in this demo are available on GitHub at the following locations:
Similar
The following projects are similar and may be worth checking out:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file poppage-0.8.1.tar.gz
.
File metadata
- Download URL: poppage-0.8.1.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 608e5fd96432df940885326094c866a2a11b1afab8f16f02d88cb369154ede32 |
|
MD5 | 2496728c803023887ccd2d1ba04bc5de |
|
BLAKE2b-256 | 9c04c17a7d298de7b6d8514f80df67ea94d41c6f54b7f8860d7a276504caea10 |