Skip to main content

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​

FeatureWhat it doesDetails
Templates are real filesA template is a folder of ordinary files with their own extensions, so the IDE highlights and inspects them as usualCore Principles
Start from working codeCopy code that works, replace the parts that vary, and generateCore Principles
Variables in file contents{{ name }} is replaced in every file, with no setupVariables 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 namesNested properties
Conditions and loopsFull Pebble (Twig-like): if, else, for, expressions, comparisons and filtersConditions and Loops, Pebble Syntax
Pebble syntax referenceThe Pebble syntax you will use most, with checked examples, and what CodeBaker adds to itPebble Syntax
Custom placeholdersDeclare another way to write a value, such as ___name___, under placeholders, so the template stays valid for the IDEplaceholders, Custom placeholders
Template syntaxSwitch the whole template to other delimiters (curly, square, angle or your own), so a file's own {{ }} and {% %} stay plain textsyntax
placeholders or syntax?How the two settings differ and when to use eachplaceholders or syntax?
Directives in commentsA comment that starts with CodeBaker: is replaced by whatever follows it, in //, /* */, #, -- and <!-- --> commentsHow CodeBaker comments work
Mixing approachesPlaceholders, native Pebble, comment-prefixed tags and replace rules can be combined in one templateMixing approaches
Protecting literal codeA 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 wayPreserving code with raw blocks
Whitespace controlA - inside a tag removes the whitespace before or after itWhitespace control
Line breaks stay tidyA line that holds only tags leaves no empty line, and a value at the end of a line keeps its line breakHow CodeBaker comments work
How processing worksThe order in which placeholders, directives and Pebble are applied, in six plain steps with an exampleHow One File Is Processed
Known limitationsWhere a template can still trip up the IDEKnown Limitations

Replacing values in code that stays valid​

FeatureWhat it doesDetails
Inline replaceA trailing //CodeBaker: replace old => new swaps a value on that one line, so the template keeps real, working valuesInline replace
Block replaceOne replace line applies to every match below it, with optional #tag groupsBlock replace
Pause and resumeoff and on pause or resume rules by value or by tag, for example to keep one block as it isPausing and resuming, Keeping one block as it is
Clear all rulesreset removes every rule declared so farClearing everything
Regular expressionsregex pattern => replacement with $1-style groupsOther forms
Protected text is skippedRules never rewrite text inside a raw or verbatim block, or a {{ 'text' }} stringPitfalls
Rules work downwardsA block rule acts only below its declaration, so nothing has to be closed at the endA rule works from its line downwards
Whole-template replacementsreplace in the config swaps plain text in contents, names, open and expandreplace
IDE-valid CSS valuesKeep real colors and units in the template and still make them variableThe problem this solves
IDE-valid stringsPut a Pebble expression inside a string, or set a variable firstKeeping string values IDE-valid
No duplicate declarationsA throwaway suffix such as ___alt1___ stops the IDE complaining about two branches that declare the same nameAvoiding duplicate declaration errors

Filters, system properties and data​

FeatureWhat it doesDetails
Any input styleCase filters split the input into words first, so user_profile, userProfile and USER PROFILE give the same resultInflection filters
Inflectionpluralize, singularize, tableize, classify, foreignKeyInflection
Case conversioncamelize, variable, underscore, dasherize, humanize, constantCase, dotCase, pathCase, trainCase and more, with aliases such as snakeCase and kebabCaseCase conversion
String helpersslug, ucfirst, lcfirstString helpers
Chaining and listsFilters chain left to right and work item by item on a listChaining and lists
System propertiesDATE, TIME, YEAR, USER, PROJECT_NAME, DIR_SLASH, NAMESPACE and more, in contents and in namesSystem properties
Overriding for one runEdit a system property in the dialog for a single generationGood to know
PHP namespaceIn 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 dialogThe full list
Lists and objects"{{ x | json }}" writes a list or object as valid JSON in a fileLists and objects
Commas in loops//CodeBaker: separator writes a comma between the items of a loopCommas in loops
JSON5 to JSONWrite 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 offJSON5 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.

SettingWhat it doesDetails
nameThe name shown in New, Generate from Templatename
idA stable folder name used when the template is installedid
versionShown next to the name, recorded in the history, compared when you install againversion
descriptionOne line shown in the sample listdescription
varsOne text field per variable, with a default; values may use Pebble and variables defined above themvars
Typed valuesA value that is exactly true, false or a plain number becomes a boolean or a number after resolutionvars
jsonAn editable JSON area for lists and objects; each top-level key becomes a variablejson
placeholdersExtra ways to write a value, such as ___VAR___placeholders
syntaxThe Pebble delimiters of the whole template, validated before anything is generatedsyntax
pathsThe folders where the template is offered, with include and exclude globspaths
replacePlain text replacements applied everywherereplace
ignoreTemplate files and folders that are not generated, such as author notesignore
openFiles to open in the editor after generationopen
expandFolders to reveal in the Project view after generationexpand
Built-in variablesThe system properties, and in an IDE with PHP support an automatic NAMESPACE field, come firstBuilt-in variables
Complete examplesA model generated inside app/Models, and several files generated from the project rootComplete examples
Your first templateWrite a simple template from scratchYour First Template

Advanced mapping​

The settings live in codebaker.advanced.json5. See Advanced Templates for everything on this page in detail.

FeatureWhat it doesDetails
Move or rename a fileGenerate a file at another path or nameMapping entries
One source, several outputsA list of targets generates the same file more than onceMapping entries
Skip a filefalse or [] leaves a file or folder outMapping entries
Per-output datadata gives one output its own variablesWhat an item can contain
Where target pointsRelative to the source's folder, to the output root with a leading /, or up with ..Where does target point?
Whole foldersRename a folder or clone it once per item, with data inherited by its filesFolders
Run orderinit entries first, then ordinary, seed and json-upsert, then insert and replaceEntry types and run order
Write onceseed writes a file only if it does not exist, so your edits survive later runsseed
Grow a JSON listjson-upsert adds an entry to a JSON array or replaces the one with the same key, and needs no seedjson-upsert
A list inside a larger JSON filepath leads to the list, creates what is missing and leaves the rest of the file alonepath
Where a new entry goesposition: append, prepend, sortBy, after, before or indexWhere a new entry goes
Nothing thrown awayA json-upsert that would have to discard data, or meets a target that is not JSON, stops with a message that names the fileWhat it refuses, If the target is not JSON
Data inside a scriptwrapperPrefix 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
LoopsA Pebble for around items creates one output per element of a listRepeating in a loop
Conditional generationif and else decide whether a file or an item existsConditional generation
Conditional namingA target is rendered too, so a name can depend on a variableConditional naming
A full exampleSeed and insert working togetherA complete example

Updating existing files​

FeatureWhat it doesDetails
SlotsMark a place in a file with {% slot name %} and {% endslot %}, bare or inside a CodeBaker: commentinsert
Inserttype: "insert" adds a fragment to a slot, or updates the fragment with the same id, and never removes anything elseinsert
Append or prependmode places a new fragment at the end or the start of the slotinsert
Indentationindent follows the neighboring line (auto), an offset from the slot's line, or an exact textinsert
Comment stylecommentStyle writes new fragment markers as html, block, hash, sql, line or taginsert
Safe by constructionThe file you insert into is never run through the template engine, so a Vue or Twig file with its own {{ }} is safeinsert
Start from a prepared fileA seed file on the entry creates the target when it does not exist yetinsert
Replace a slottype: "replace" swaps the whole content of a slotreplace
Keep your own editsMake the file a seed, so each run only updates its own fragmentWhy did the text I typed into a slot disappear?

The generation dialog​

Generating always runs the same four steps. See the Generation Workflow.

StepWhat happensDetails
The whole processDiagrams of the big picture, what happens inside the steps and how to choose how a file is writtenHow It Works
1. PropertiesA form with the system properties, one field per vars entry and the JSON editorStep 1
Values with expressionsA field may use Pebble and the fields above itStep 1
HistoryThe last 20 runs of a template are kept, and the newest one pre-fills the formHistory
2. ProgressA log of resolved properties, JSON, references and files, with the reason when something failsStep 2
Write checkBefore anything is written, every file the generation would change is checked: a read-only file or folder is listed, and nothing is written yetWhen something fails
3. PreviewA tree of everything that will be written, colored as new, modified, edited or unchangedStep 3
Edit before writingThe generated text is editable, and your edits are what gets writtenEditing the generated code
Compare with the fileThe IDE's diff viewer, with a three-way merge for files that already existComparing with the existing file
4. FinishAll files are written in one IDE command, then open and expand runStep 4
UndoThe whole generation is a single undoable commandUndo

Installing and sharing templates​

FeatureWhat it doesDetails
Sample templatesInstall the bundled Hello World and CRUD Demo from the menuGetting Started
Install from a linkA .zip link, or a GitHub repository, branch, tag or folderInstall from a link
Install from a fileA .zip file from diskInstall from a file
One-click installAn Install in IDE button on a web page, with a confirmation before anything is installedOne click from a web page
Which links workThe accepted link forms and their rulesWhich links work
VersionsOne installed version per template id, with a choice to replace, install side by side or cancelWhere it is installed
Archive limitsSize, file count, redirect and depth limits that protect against oversized or malicious archivesLimits
Removing a templateDelete its folder; files it already generated stayRemoving a template
Sharing your ownPublish a template as a link or a fileSharing your own template
Templates live in GitThe .CodeBaker/ folder is committed with your code, so a team shares the same templatesGetting Started

Safety and the IDE​

FeatureWhat it doesDetails
Review before writingNothing is written until you finish the preview, and existing files ask for confirmationStep 3
IDE highlighting of directivesThe CodeBaker: that starts a directive comment is colored, so you can tell it from an ordinary commentHow CodeBaker comments work
Early, clear errorsAn invalid syntax or $ref, a failing $api or a malformed slot stops with a message that says what is wrongsyntax, $ref
Secrets are hidden$api credentials and headers are masked in the generation log$api
Stays inside the projectA template cannot read or write files outside your project, and a path that tries to leave it is refusedStay safe
LimitsPebble cannot load other templates or reach into Java, a huge range or output is refused, and install archives have size limitsStay safe, Limits
Files are written with careAn 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 encodingStep 4
Install only trusted templatesA template writes files and can fetch from addresses it namesStay safe
TroubleshootingThe usual install problems and their fixesTroubleshooting

Where to go next​