Extending Gray Goo’s Template Library

Importing Template Packages

A Template Package is a file (actually, a .tar.gz) that contains one or more templates.

To install a package into your library use graygoo install URL:

$ graygoo install http://flyingelephantsoftware.de/graygoo/flask

Warning

Templates are basically plugins, and are executed on your machine with your privileges, so they are potentially dangerous. you MUST only install from sources you trust. If in doubt, don’t.

Creating own Packages

To create a package of your templates, that can be shared with other users, use graygoo package PACKAGENAME TEMPLATENAME [TEMPLATENAME] ...

$ graygoo package mypackage.tar.gz yourname.example

The resulting package can be distributed, to be installed via graygoo install.

Creating custom Templates

A Template is basically a directory in graygoo’s searchpath (usually ~/.graygoo) with a graygoo.json configuration file in it.

To create an empty template, you can use graygoo (yay, recursive):

$ cd ~/.graygoo
$ graygoo graygoo.template name="yourname.example"
generating 'yourname.example/graygoo.json'
generating 'yourname.example/example.txt'

The graygoo.json should look like this:

{
  "name": "yourname.example",
  "description": "Enter a description for yourname.example",
  "arguments": {
    "arg": "Some Argument"
  },
  "render": [
    {
      "source": "example.txt",
      "target": "example.txt"
    }
  ]
}

name and description are just what to expect, adjust them to your needs.

arguments is a dictionary of the names of the arguments your template accepts as keys and a description of the argument as value.

render is a list of files to copy when the template is rendered. source is the path to the file to copy, relative to the template directory, target is the path where to copy the file, relative to the current working directory, when graygoo is invoked.

It is possible to use standard python string placeholders (like %(name)s) in the target path and in the file contents. These placeholders will be replaced with the arguments the user provides when the template is rendered.