Directive Reference
A directive is a comment that starts with CodeBaker:. CodeBaker removes the comment, and what follows CodeBaker: takes its place, or is carried out as a command. This page lists every word that can follow it, with a link to the page that explains it. For a first look, read Keeping the Template Valid for Your IDE.
What can follow CodeBaker:
After CodeBaker: | What happens | Explained in |
|---|---|---|
A Pebble tag, for example {% if x %} | The tag takes the place of the comment | Keeping the Template Valid for Your IDE |
Any other text, for example background: ___color___; | The text takes the place of the comment, so the IDE sees a comment and the generated file gets the line | Keeping the Template Valid for Your IDE |
replace <value> => <replacement> [#tag] | A rule: swaps the value, on this line if the comment trails code, or from this line down if it stands alone | Replacing Real Values |
regex <pattern> => <replacement> [#tag] | The same, with a Java regular expression | Replacing Real Values |
off <value or #tag> ... and on <value or #tag> ... | Pauses and resumes the rules that match | Replacing Real Values |
reset | Removes every rule declared so far | Replacing Real Values |
separator | Becomes {% if not loop.last %},{% endif %}: a comma between the items of a loop | Generating JSON |
{% slot name %}, {% endslot %}, {% fragment id %}, {% endfragment %} | Slot markers for insert and replace: copied into the generated file exactly as written | Seed, Insert and Replace |
{% raw %}, {% endraw %}, {% verbatim %}, {% endverbatim %} | A raw block: the comment around the tag is removed first, and what is inside is never read or changed | Escaping Text |
Where you can write one
| Prefix | Languages |
|---|---|
// | PHP, Java, Kotlin, JavaScript, TypeScript, Go, SCSS, LESS |
/* ... */ | CSS and C-style block comments: write /* CodeBaker: ... */ |
# | Python, Ruby, shell, YAML |
-- | SQL, Lua |
<!-- ... --> | HTML, XML, Markdown |
A closing */ or --> is optional and is removed too. // is not a comment in plain CSS or in a <style> block.
Rules for every directive
- The directive is the last thing on its line. It runs to the end of the line.
CodeBaker:needs the colon and exactly that case.// CodeBaker is a tool,// see CodeBaker: docsand// codebaker: xare ordinary comments.- The first word after
CodeBaker:is reserved when it isreplace,regex,on,offorreset: it is a command, not text. - A line that holds only tags leaves no empty line. Its tags join the next line, which keeps its own indentation. The text that replaces a full-line comment starts at the beginning of the line.
- A rule works from its line downwards, once. It never changes the lines above it and needs no closing line.
- A directive that CodeBaker cannot parse is not an error. A
replacewith no replacement, for example, stays in the generated file as text. - A directive inside a raw block is only text. Nothing in a raw block is read.
- With another
syntax, the tags are written with its delimiters:<!-- CodeBaker: [% if x %] -->forsquare.
The order in which directives, rules, placeholders and Pebble are applied to a file is in How One File Is Processed.