canmove, Confirmed users, Bureaucrats and Sysops emeriti
1,093
edits
No edit summary |
|||
| Line 16: | Line 16: | ||
foo/ | foo/ | ||
<nowiki>README- | <nowiki>README-{project}.txt</nowiki> | ||
bar/ | bar/ | ||
new.js | new.js | ||
| Line 24: | Line 24: | ||
== Dynamic values == | == Dynamic values == | ||
In the example above, you undoubtedly noticed the rather odd name of the README file: <tt>README-<nowiki> | In the example above, you undoubtedly noticed the rather odd name of the README file: <tt>README-<nowiki>{project}</nowiki>.txt</tt>. When installing a template, the Python server uses the [http://code.google.com/p/json-template/ JSON Template] template engine on both the filenames and the file contents. | ||
So, if this template is installed into a project called "helloworld", you would see README-helloworld.txt at the top level of the project. | So, if this template is installed into a project called "helloworld", you would see README-helloworld.txt at the top level of the project. | ||
By default, the following variables are available: | |||
; project: the project name | |||
; username: the username of the project's owner | |||
; filename: the name of the file that is being generated | |||
You can pass in additional values. Any undefined variables referenced in the template are simply replaced with an empty string. | |||
== Web API == | == Web API == | ||
| Line 46: | Line 52: | ||
the project, with the common root for the files chopped off. | the project, with the common root for the files chopped off. | ||
Additionally, filenames containing { will be treated as | Additionally, filenames containing { will be treated as JSON Template | ||
templates and the contents of files will be treated as | templates and the contents of files will be treated as JSON Template | ||
templates. This means that the filenames can contain variables | templates. This means that the filenames can contain variables | ||
that are substituted when the template is installed into the | that are substituted when the template is installed into the | ||
| Line 53: | Line 59: | ||
and small amounts of logic. | and small amounts of logic. | ||
These | These JSON Template templates automatically have the following | ||
variables: | |||
* project: the project name | |||
* username: the project owner's username | |||
* filename: the name of the file being generated | |||
You can pass in a dictionary for other_vars and those values | |||
will also be available in the templates. | |||
""" | """ | ||