Tutorial on how to write templates for ZopeSkel.
Why and when
Do you have code you write over and over again? Is the code almost the same each time and are the places where you change stuff always the same? You can avoid writing all that code by creating a template.
You can write the template the way you want. This is just a system. This means you can version control your own process by documenting it in a template.
Basics of template writing
The first question you need to ask yourself is “what do I want?” The
next thing you will want to investigate is what you have already got.
You can use “
bin/templer --list” and “
bin/templer <template_name> --list-variables” to find out more about the templates ZopeSkel has
to offer. Then have a look at the code provided by the template.
To wire everything up, you need to do four basic things:
- Create a class.
- Import the class to a package namespace.
- Provide an entry point.
- Write the actual template itself.
Cris has already written the documentation for this tutorial. It currently lives on his laptop, but it should be posted online soon. I (Mark) decided to just write down some notes instead of trying to replicate Cris' documentation.
The related documentation can be found here:
- Do not install ZopeSkel in your global Python! Always use a virtualenv or buildout.
- If you want to use pip, use version 1.1 or later.
- To use the package while developing, use “
python setup.py develop” (so “
develop” instead of “
- If you are using a buildout, you can also use mr.developer.
- The modes are incrementally inclusive: the questions for the “easy” mode are also asked in the “expert” mode, etc.
- Which namespace to choose: if you want to contribute the
templates and they might be useful for others: use the
templernamespace; for your own project/infrastructure specific templates, use your company’s namespace.