Package: clyjin-templates
📑 Clyjin TemplatesCentralized template system to create files and directories.InstallationUsing PIP:pipinstallclyjin_templatesGetting StartedClyjin Templates uses Template Groups in order to define files and directories
to be created.Template Groups are defined using special convention. The central configuration
file of any group isspec.yml. The spec defines files and directories to
be created in form of nested objects.An example spec file looks like:name:my-exampledescription:example descriptionvars:a:b:c:default:truetemplates:template_1.py:template_2.py:tree:src:__init__.py:$content:"&template_1.py"drivers:main.py:$content:"&template_2.py"local:$type:dirREADME.md:$content:"somereadmetext"Which will produce the following file tree:.
├── src/
│   ├── __init__.py
│   ├── drivers/
│   │   └── main.py
│   └── local/
│       └── <empty-directory>
└── README.mdLet's consider each field of the spec above.NameName of template group to be associated with, e.g. on CLI calls.DescriptionHelper description for template group, displayed e.g. in CLI help messages.VarsVariables defined for current template group. Each variable might have a
default value and a list of scopes it is available in.Each var becomes available to be set via CLI on template group call. For our
example above, the call with all vars defined might look like:clyjintemplatesmy-example"a=10,b='hello, world!',c=false"Note that we could omittedc=false, since we defined a default value for it
in thespec.yml. Although, it would result in an error for other non-default
variables.TemplatesTemplate files defined to be referenced for this template group.For file nodes (see below), in$contentfield you can point to a template
object to be rendered into the file.TreeFile tree generated by this template group. Consists of nodes. The nodes can be
of two types - file or directory.Directory node is any spec's tree node with at least one subnode, or an empty
directory with$type: direxplicitly set. Other empty nodes (without subnodes
or other fields) are considered as empty files by default.File node is an empty spec's tree node or any node with$type: fileset
explicitly. File nodes have special field$contentwhich defines what
string will be pasted inside it on creation. The content field can have either
a direct string (simply written inspec.ymlfile), absolute or relative
(to working directory) path to template file, or pointer to in-spec defined
template. In our example latter is used in form of$content: "&template_1.py".Add a template groupIn order to make your template group available in the CLI, you need to register
it:clyjintemplates.add# orclyjintemplates.addpath/to/working/directoryWhich will automatically search forspec.ymlin the working directory and
then for referenced there template files. For our example it would be:.
├── spec.yml
├── template_1.py.mako
└── template_2.py.makoAll files will be copied toClyjinsystem directory for the plugin.Alternatively, you can explicitly define name of spec file:clyjintemplates.register-canother-spec-name.ymlInvoke a template groupIn order to create files and directories out of previously registered template
group you need:clyjintemplates<your-template-name>-dpath/to/output/directoryIn our example case, we can output our registered example in some current
directory:clyjintemplatesmy-exampleThis will output rendered contents of our chosen template group in
current or chosen (with-doption) directory.