Diecutter: templates as a service¶
Presentation at an AFPY event, march 2013, Paris.
By Rémy Hubscher and Benoit Bryon.
Slides available on http://diecutter.readthedocs.org
This presentation is published under CC BY 3.0
Render templates¶
Render directories¶
Generate configuration¶
Setup template “diecutter.ini” server-side:
diecutter.template_dir = {{ template_dir|default('') }}
diecutter.token = {{ token|default('') }}
diecutter.readonly = {{ readonly|default('false') }}
Generate configuration client-side:
wget --post-data="template_dir=src/templates" \
--output-document="diecutter.ini" \
http://diecutter.alwaysdata.net/diecutter.ini
Generate code¶
django startproject reloaded:
curl --data "django_project=demo" \
http://diecutter.alwaysdata.net/+django_project+ \
> demo.zip
PasteScript is complicated¶
- needs PasteScript and templates installed locally
- template registration is a pain:
- create template files (Cheetah markup)
- create template class (Cheetah Template)
- update template package’s entry points (setup.py)
- update your environment (reinstall/update)
- Cheetah?
Provisioners are overkill¶
- I just want to render a template against data!
- I don’t need Chef, Salt, Puppet & co.
- Templates aren’t only useful in provisioning.
And I’d like to reuse templates whatever the provisioning tool!
Diecutter’s REST API¶
- POST data and retrieve generated files
- GET raw content of templates
- PUT templates from client to server
- DELETE template (1)
- OPTIONS lists template variables (1)
- PATCH alters default values of variables (1)
(1) Work in progress.
Encapsulated implementation(s)¶
- template resources backend
- Today: local filesystem.
- Tomorrow: remote Git/Hg/..., NoSQL, include/extend URLs
- template engines
- Today: Jinja.
- Tomorrow: Cheetah, ERB, XSLT...
- response writers
- Today: return single file or ZIP archive.
- Tomorrow: tar.gz, write to storage, attachments, streaming, asynchronous generation...
Roadmap¶
- today: proof of concept, focus on API
- tomorrow: rock-solid defaults, focus on stability & performance
- later: make your own, focus on extensibility
Resources¶
- PyPI: https://pypi.python.org/pypi/diecutter
- Code repository: https://github.com/novagile/diecutter/
- Bugs and features: https://github.com/novagile/diecutter/issues
- Slides: http://tech.novapost.fr