All Features
Every CodeBaker feature in one place, grouped by what you do with it. Each row links to the page that explains it in detail.
- Writing template files
- Replacing values in code that stays valid
- Filters, system properties and data
- The template configuration
- Advanced mapping
- Updating existing files
- The generation dialog
- Installing and sharing templates
- Safety and the IDE
Writing template files
| Feature | What it does | Details |
|---|---|---|
| Templates are real files | A template is a folder of ordinary files with their own extensions, so the IDE highlights and inspects them as usual | Core Principles |
| Start from working code | Copy code that works, replace the parts that vary, and generate | Core Principles |
| Variables in file contents | {{ name }} is replaced in every file, with no setup | Variables in file content |
| Variables in file and folder names | {{entityKey}}.html on disk becomes task.html, and pages/{{entityKey}}/ becomes pages/task/ | Variables in file and folder names |
| Nested values | {{ user.name }} or ___user_dot_name___ reaches into objects and lists, in contents and in names | Nested properties |
| Conditions and loops | Full Pebble (Twig-like): if, else, for, expressions, comparisons and filters | Conditions and Loops, Pebble Syntax |
| Pebble syntax reference | The Pebble syntax you will use most, with checked examples, and what CodeBaker adds to it | Pebble Syntax |
| Custom placeholders | Declare another way to write a value, such as ___name___, under placeholders, so the template stays valid for the IDE | placeholders, Custom placeholders |
| Template syntax | Switch the whole template to other delimiters (curly, square, angle or your own), so a file's own {{ }} and {% %} stay plain text | syntax |
placeholders or syntax? | How the two settings differ and when to use each | placeholders or syntax? |
| Directives in comments | A comment that starts with CodeBaker: is replaced by whatever follows it, in //, /* */, #, -- and <!-- --> comments | How CodeBaker comments work |
| Mixing approaches | Placeholders, native Pebble, comment-prefixed tags and replace rules can be combined in one template | Mixing approaches |
| Protecting literal code | A raw (or verbatim) block keeps {{ }} and {% %} exactly as written, and nothing else changes it: not placeholders, not replace, not rules, not directives (Vue, Handlebars, Twig and so on) | Preserving code with raw blocks |
| One literal string | {{ 'text' }} prints the text as it is and protects it the same way | Preserving code with raw blocks |
| Whitespace control | A - inside a tag removes the whitespace before or after it | Whitespace control |
| Line breaks stay tidy | A line that holds only tags leaves no empty line, and a value at the end of a line keeps its line break | How CodeBaker comments work |
| How processing works | The order in which placeholders, directives and Pebble are applied, in six plain steps with an example | How One File Is Processed |
| Known limitations | Where a template can still trip up the IDE | Known Limitations |
Replacing values in code that stays valid
| Feature | What it does | Details |
|---|---|---|
| Inline replace | A trailing //CodeBaker: replace old => new swaps a value on that one line, so the template keeps real, working values | Inline replace |
| Block replace | One replace line applies to every match below it, with optional #tag groups | Block replace |
| Pause and resume | off and on pause or resume rules by value or by tag, for example to keep one block as it is | Pausing and resuming, Keeping one block as it is |
| Clear all rules | reset removes every rule declared so far | Clearing everything |
| Regular expressions | regex pattern => replacement with $1-style groups | Other forms |
| Protected text is skipped | Rules never rewrite text inside a raw or verbatim block, or a {{ 'text' }} string | Pitfalls |
| Rules work downwards | A block rule acts only below its declaration, so nothing has to be closed at the end | A rule works from its line downwards |
| Whole-template replacements | replace in the config swaps plain text in contents, names, open and expand | replace |
| IDE-valid CSS values | Keep real colors and units in the template and still make them variable | The problem this solves |
| IDE-valid strings | Put a Pebble expression inside a string, or set a variable first | Keeping string values IDE-valid |
| No duplicate declarations | A throwaway suffix such as ___alt1___ stops the IDE complaining about two branches that declare the same name | Avoiding duplicate declaration errors |
Filters, system properties and data
| Feature | What it does | Details |
|---|---|---|
| Any input style | Case filters split the input into words first, so user_profile, userProfile and USER PROFILE give the same result | Inflection filters |
| Inflection | pluralize, singularize, tableize, classify, foreignKey | Inflection |
| Case conversion | camelize, variable, underscore, dasherize, humanize, constantCase, dotCase, pathCase, trainCase and more, with aliases such as snakeCase and kebabCase | Case conversion |
| String helpers | slug, ucfirst, lcfirst | String helpers |
| Chaining and lists | Filters chain left to right and work item by item on a list | Chaining and lists |
| System properties | DATE, TIME, YEAR, USER, PROJECT_NAME, DIR_SLASH, NAMESPACE and more, in contents and in names | System properties |
| Overriding for one run | Edit a system property in the dialog for a single generation | Good to know |
| PHP namespace | In an IDE with PHP support NAMESPACE is filled from the folder you generate into (composer.json PSR-4 first), and a field for it is added to the dialog | The full list |
| Lists and objects | "{{ x | json }}" writes a list or object as valid JSON in a file | Lists and objects |
| Commas in loops | //CodeBaker: separator writes a comma between the items of a loop | Commas in loops |
| JSON5 to JSON | Write a template as .json5 and map it to a .json name: the result is converted to plain JSON by itself. format chooses it explicitly or turns it off | JSON5 templates |
The template configuration
The settings live in codebaker.config.json5, which is JSON5: comments and trailing commas are allowed. See the Configuration Reference for the complete schema.
| Setting | What it does | Details |
|---|---|---|
name | The name shown in New, Generate from Template | name |
id | A stable folder name used when the template is installed | id |
version | Shown next to the name, recorded in the history, compared when you install again | version |
description | One line shown in the sample list | description |
vars | One text field per variable, with a default; values may use Pebble and variables defined above them | vars |
| Typed values | A value that is exactly true, false or a plain number becomes a boolean or a number after resolution | vars |
json | An editable JSON area for lists and objects; each top-level key becomes a variable | json |
placeholders | Extra ways to write a value, such as ___VAR___ | placeholders |
syntax | The Pebble delimiters of the whole template, validated before anything is generated | syntax |
paths | The folders where the template is offered, with include and exclude globs | paths |
replace | Plain text replacements applied everywhere | replace |
ignore | Template files and folders that are not generated, such as author notes | ignore |
open | Files to open in the editor after generation | open |
expand | Folders to reveal in the Project view after generation | expand |
| Built-in variables | The system properties, and in an IDE with PHP support an automatic NAMESPACE field, come first | Built-in variables |
| Complete examples | A model generated inside app/Models, and several files generated from the project root | Complete examples |
| Your first template | Write a simple template from scratch | Your First Template |
Advanced mapping
The settings live in codebaker.advanced.json5. See Advanced Templates for everything on this page in detail.
| Feature | What it does | Details |
|---|---|---|
| Move or rename a file | Generate a file at another path or name | Mapping entries |
| One source, several outputs | A list of targets generates the same file more than once | Mapping entries |
| Skip a file | false or [] leaves a file or folder out | Mapping entries |
| Per-output data | data gives one output its own variables | What an item can contain |
Where target points | Relative to the source's folder, to the output root with a leading /, or up with .. | Where does target point? |
| Whole folders | Rename a folder or clone it once per item, with data inherited by its files | Folders |
| Run order | init entries first, then ordinary, seed and json-upsert, then insert and replace | Entry types and run order |
| Write once | seed writes a file only if it does not exist, so your edits survive later runs | seed |
| Grow a JSON list | json-upsert adds an entry to a JSON array or replaces the one with the same key, and needs no seed | json-upsert |
| A list inside a larger JSON file | path leads to the list, creates what is missing and leaves the rest of the file alone | path |
| Where a new entry goes | position: append, prepend, sortBy, after, before or index | Where a new entry goes |
| Nothing thrown away | A json-upsert that would have to discard data, or meets a target that is not JSON, stops with a message that names the file | What it refuses, If the target is not JSON |
| Data inside a script | wrapperPrefix and wrapperSuffix let a list live inside text such as const ENTITIES = [...]; | json-upsert |
| Read other files | $file loads a JSON5 file from the output, the template or the project | $file |
| Reuse a block | $ref points at another part of the same document with a JSON Pointer | $ref |
| Fetch data | $api loads JSON from a web address (GET or POST, headers, Basic authentication), with secrets hidden in the log | $api |
| Loops | A Pebble for around items creates one output per element of a list | Repeating in a loop |
| Conditional generation | if and else decide whether a file or an item exists | Conditional generation |
| Conditional naming | A target is rendered too, so a name can depend on a variable | Conditional naming |
| A full example | Seed and insert working together | A complete example |
Updating existing files
| Feature | What it does | Details |
|---|---|---|
| Slots | Mark a place in a file with {% slot name %} and {% endslot %}, bare or inside a CodeBaker: comment | insert |
| Insert | type: "insert" adds a fragment to a slot, or updates the fragment with the same id, and never removes anything else | insert |
| Append or prepend | mode places a new fragment at the end or the start of the slot | insert |
| Indentation | indent follows the neighboring line (auto), an offset from the slot's line, or an exact text | insert |
| Comment style | commentStyle writes new fragment markers as html, block, hash, sql, line or tag | insert |
| Safe by construction | The file you insert into is never run through the template engine, so a Vue or Twig file with its own {{ }} is safe | insert |
| Start from a prepared file | A seed file on the entry creates the target when it does not exist yet | insert |
| Replace a slot | type: "replace" swaps the whole content of a slot | replace |
| Keep your own edits | Make the file a seed, so each run only updates its own fragment | Why did the text I typed into a slot disappear? |
The generation dialog
Generating always runs the same four steps. See the Generation Workflow.
| Step | What happens | Details |
|---|---|---|
| The whole process | Diagrams of the big picture, what happens inside the steps and how to choose how a file is written | How It Works |
| 1. Properties | A form with the system properties, one field per vars entry and the JSON editor | Step 1 |
| Values with expressions | A field may use Pebble and the fields above it | Step 1 |
| History | The last 20 runs of a template are kept, and the newest one pre-fills the form | History |
| 2. Progress | A log of resolved properties, JSON, references and files, with the reason when something fails | Step 2 |
| Write check | Before anything is written, every file the generation would change is checked: a read-only file or folder is listed, and nothing is written yet | When something fails |
| 3. Preview | A tree of everything that will be written, colored as new, modified, edited or unchanged | Step 3 |
| Edit before writing | The generated text is editable, and your edits are what gets written | Editing the generated code |
| Compare with the file | The IDE's diff viewer, with a three-way merge for files that already exist | Comparing with the existing file |
| 4. Finish | All files are written in one IDE command, then open and expand run | Step 4 |
| Undo | The whole generation is a single undoable command | Undo |
Installing and sharing templates
| Feature | What it does | Details |
|---|---|---|
| Sample templates | Install the bundled Hello World and CRUD Demo from the menu | Getting Started |
| Install from a link | A .zip link, or a GitHub repository, branch, tag or folder | Install from a link |
| Install from a file | A .zip file from disk | Install from a file |
| One-click install | An Install in IDE button on a web page, with a confirmation before anything is installed | One click from a web page |
| Which links work | The accepted link forms and their rules | Which links work |
| Versions | One installed version per template id, with a choice to replace, install side by side or cancel | Where it is installed |
| Archive limits | Size, file count, redirect and depth limits that protect against oversized or malicious archives | Limits |
| Removing a template | Delete its folder; files it already generated stay | Removing a template |
| Sharing your own | Publish a template as a link or a file | Sharing your own template |
| Templates live in Git | The .CodeBaker/ folder is committed with your code, so a team shares the same templates | Getting Started |
Safety and the IDE
| Feature | What it does | Details |
|---|---|---|
| Review before writing | Nothing is written until you finish the preview, and existing files ask for confirmation | Step 3 |
| IDE highlighting of directives | The CodeBaker: that starts a directive comment is colored, so you can tell it from an ordinary comment | How CodeBaker comments work |
| Early, clear errors | An invalid syntax or $ref, a failing $api or a malformed slot stops with a message that says what is wrong | syntax, $ref |
| Secrets are hidden | $api credentials and headers are masked in the generation log | $api |
| Stays inside the project | A template cannot read or write files outside your project, and a path that tries to leave it is refused | Stay safe |
| Limits | Pebble cannot load other templates or reach into Java, a huge range or output is refused, and install archives have size limits | Stay safe, Limits |
| Files are written with care | An existing file is changed in place, so permissions, owner and symbolic links stay. A new file gets the executable bits of its template file. Binary files are copied byte for byte, and text keeps its encoding | Step 4 |
| Install only trusted templates | A template writes files and can fetch from addresses it names | Stay safe |
| Troubleshooting | The usual install problems and their fixes | Troubleshooting |
Where to go next
- Getting Started - Install the plugin and try the samples
- Template Basics - How a template is written
- Configuration Reference - Every setting in
codebaker.config.json5 - Advanced Templates - Everything in
codebaker.advanced.json5 - Known Limitations - What to watch out for