Diecutter: templates as a service

Presentation at an AFPY event, march 2013, Paris.

By Rémy Hubscher and Benoit Bryon.

Slides available on https://diecutter.readthedocs.io

This presentation is published under CC BY 3.0

Presenter Notes

Render templates

Client posts DATA to TEMPLATE which returns FILE

Presenter Notes

Render directories

Client posts DATA to DIRECTORY which returns ARCHIVE

Presenter Notes

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.io/diecutter.ini

Presenter Notes

Generate code

django startproject reloaded:

curl --data "django_project=demo"                      \
     http://diecutter.io/+django_project+  \
     > demo.zip

Presenter Notes

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?

Presenter Notes

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!

Presenter Notes

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.

Presenter Notes

KISS

  • focus on API
  • no builtin client
  • no builtin form validation (have a look at daybed)

Presenter Notes

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...

Presenter Notes

Roadmap

  • today: proof of concept, focus on API
  • tomorrow: rock-solid defaults, focus on stability & performance
  • later: make your own, focus on extensibility

Presenter Notes