/
NOTES.txt
106 lines (82 loc) · 2.59 KB
/
NOTES.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
The build process
=================
We start with 3 things:
- A template definition
- A list of substitution variables
- A target directory
The template definition is a list of individual file templates.
The list of variables contains the following details:
- name - the variable name
- prompt - boolean or prompt string
- default - a default value
External format of a template
=============================
version: 1
variables:
- name: var1
prompt: Prompt for variable 1
default: default value
- name: var2
prompt: no
default: default value
files:
- name: <value>
content: <value>
encoding: utf-8
executable: yes
- name: dir1
directory: yes
- name: dir2/
- name: emptyfile
defaults:
encoding: utf-8
renderer: none
filename_renderer: none
The format of a <value> is one of:
1. A string
2. value: str or from: filename
renderer: none
Internal format of a template
=============================
A template is a list of items. Each item is a dictionary with the following
elements:
- name: the file name (directories are created as needed)
- directory: boolean, is this file a directory?
- encoding: the encoding of the file content (not used if content is binary)
- content: the file content
- executable: boolean, set the executable bit?
- binary: boolean, is the file binary? May not be needed (renderer covers this?)
- renderer: a function to update the content before writing, for example
- jinja2 render
- base64 decode
Obtaining template items
========================
Template items can come from:
- A YAML format definition
- { 'variables': [ { ... }, ... ], 'files': [ ... ] }
- A set of files on the filesystem
- A set of files from a zip file
Rendering content
=================
Content can be rendered in a number of ways:
- Direct copy of the data into the filesystem
- Jinja2 templating
- Python format() method
- Python %-formatting
- StringTemplate $-formatting
File and directory names need rendering as well.
Variables
=========
Variables are defined in the template, and may be supplied by any of the
following methods:
- As parameters in internal API calls
- As arguments from the command line
- As interactive user input (prompted)
- From a configuration file
- Global
- Per-user
- Per-template (possibly, maybe have template name glob matching, maybe YAGNI)
Possible enhancements
=====================
- "gen pack TEMPLATE" Create a packed template format (maybe sqlite) for
templates. Could hold multiple templates per file.