Package: agen
A very simple code generator.Free software: MIT licenseDocumentation:https://agen.readthedocs.com/en/.FeaturesSimple and very simple APICustomJinja EnvsupportedCould be used as Command-Line-ToolsNo Templateagendon’t provide any template. It’s only provide some function,
to make code to be a template. If you need any public template, please
use the awesome open source tool,Cookiecutter.Why agen?agen is so lightweight, that could be perfectly integrated into your
project in minutes.I likeCookiecutter(It’s
so cool and so awesome), but most of it’s features are too heavyweight
for me.InstallationInstall with pip:pipinstallagenInstall with source code:clonehttps://github.com/yufeiminds/agen.gitcdagenpythonsetup.pyinstallQuickstart GuideInagen, usejinja2as
template engine for rendering, so, any feature ofjinja2template will be found inagen.File Generationfromagenimport(string_render,render,generate,generate_dir)# Render text from a templated stringstring_render('{{key}}',{'key':'value'})>'value'cattemplate.py>{{key}}# Render text from a template filerender('template.py',{'key':'value'})>'value'# Generate file from a template filegenerate('template.py','output.py',{'key':'value'})# Content of output.pyvalueDirectory GenerationIf we have a directory like this：directory├──__init__.py└──{{key}}.pycallgenerate_dirfunction：generate_dir('directory','mydir',{'key':'value'})will generatemydir├──__init__.py└──value.pyEvery pure text file will be render by template engine.context{'key': 'value'}also will be rendered automatically.Command Line ToolBasic Usageagenalso implement a very simple command line tool, use for
rendering the local template easily, but it only could be used on *UNIX
operation system.Usage: agen [OPTIONS] [NAMES]...

Options:
  -o, --out PATH      Output path or directory
  -s, --source PATH   Source path or directory
  -c, --context PATH  Path of context file
  --help              Show this message and exit.With no argument，agenwill search local template directory, eg.
on *NIX operation system, this directory are usually at:$ agen
--------------------------------------------
  agen Library
  see -> /Users/yufeili/.agen/templates
--------------------------------------------
directory   repo        single.txtThe simplest way to call：$ agen -s template_path -o ouput_path -c context.jsonSure,.yamlalso can be used ascontextfile. If theoutoption wasn’t provided, it will prompt for input on screen (defualt is
current directory).Full ExampleYou can specific three kinds of directory or file as thesource.Single File$ agen -s single.txt -o output.txt -c context.jsonDirectoryAny directory, such asdirectory
├── __init__.py
└── {{key}}.pyboth could besource, it also support to use template variable to
render the output file name.$ agen -s directory -o myapp -c context.jsonThis command will create a directory namedmyapp, and processing
recursively all files under thedirectory, output tomyappbase
on origin structure.RepositoryNoteagen is not designed as a command line tool, so for generating repository, recommend to use the awesomeCookiecutter.If there is an inner folder in a directory, and the directory has aagen.jsonoragen.yaml, it will be judged as aRepo，repo
├── README.md
├── agen.json
└── {{name}}
    ├── __init__.py
    └── {{name}}.pyThe default behavior of this tool will be changed, assuming thisRepo$ agen -s repo -o output -c context.jsonThis command will create a folder has the same name with inner
directory tooutputdirectory, if the name of folder is a
template string, it will be compiled as standard string then create a
folder, the other behavior same asdirectory.Thecontextis not required. If it wasn’t provided, it will load
theagen.[json|yaml]file, and prompt user for input.ExampleForcontext{'key': 'value'}，outputis current
directory, current value:.
└── value
    ├── __init__.py
    └── value.pyLocal Template DirectoryUse option argumentNAMES, could get files path from local templates
directory assource. The following two calls are equivalent in
*NIX systems:$ agen -s ~/.agen/templates/single.txt
$ agen single.txtCreditsAuthor : Yufei Liyufeiminds@gmail.comContact me: @yufeiminds (Facebook)、@YufeiMinds (Sina Weibo)ContributionWelcome to develop with me!Fork this repo & develop it.