Under the Hood
What CodeBaker does inside, in the order it does it: what each step of the dialog works out, how one file is processed, and how to choose the way a file is written. You do not need any of this to write your first templates. It helps when a result surprises you.
What happens inside the steps
The work is done in step 2. It resolves the values, reads the mapping and works out the content of every file. Step 3 shows exactly that result, and step 4 writes exactly what step 3 shows, including any edit you made there.
- The values and the JSON are covered in Step 2 and in the Configuration Reference.
$ref,$apiand$fileare in Advanced Templates.- The three passes and why
initexists are in Entry types and run order. - The whole generation is one undoable command: see Undo.
How one file is processed
The short version, in plain words and with an example, is on How One File Is Processed. This is the same order as a diagram.
Every file of the template goes through the same steps, in this order. The delimiters Pebble reads in step 7 are the ones your template chose with syntax, {{ }} and {% %} unless it says otherwise.
- Raw blocks and printed strings: Preserving code with raw blocks.
rawis just another name forverbatim. - Config replacements:
replace. - Rules and directives: How CodeBaker comments work and Inline & Block Replace.
- Declared placeholders:
placeholders. Whether to use them or another syntax:placeholdersorsyntax?. - The names of files and folders are filled in separately, with the same variables: Variables in file and folder names.
How should a file be written?
Each file of the template is written in one of a few ways. This is the decision to make for every file, and it is what the type of a mapping entry says.
- Ordinary files,
seed,json-upsert: Entry types and run order,seedandjson-upsert. - Slots,
insertandreplace:insertandreplace. - Leaving a file out: Mapping entries.
Why a file with a slot should be a seed
An insert goes into the generated result, not into the file already on disk. A file that is an ordinary template file is written again from the template on every run, so anything typed into its slot is gone after the next generation. Make the file a seed and it is written once, so the insert updates only its own fragment from then on.
- Without
seedthe second run would start from the template again, with an empty slot. - The text between the fragment markers belongs to the template and is replaced on the next run with the same
id. Everything else in the slot is yours. - More:
insertand Why did the text I typed into a slot disappear?
Where to read more
- How It Works: the whole process on one page.
- How One File Is Processed: the same order, in plain words and with an example.
- Advanced Templates: mapping, entry types,
seed,insert,replaceandjson-upsert.