Codepurify Templates
VS Code extension for Codepurify template language with syntax highlighting, intelligent autocomplete, and real-time error validation.
Features
- Multi-Language Support: Works with TypeScript, TSX, Markdown, and HTML files
- Syntax Highlighting: Full highlighting for
{| ... |} template expressions
- Intelligent Autocomplete: Context-aware variable completion from CSV definitions
- Real-time Validation: Instant error highlighting for unknown variables and syntax errors
- Control Flow Support: Proper highlighting for
if, loop, raw blocks
- Comment Support:
{|# comment #|} syntax highlighting
- Smart Delimiters: Auto-closing
{| and |} pairs
Supported File Extensions
.code - Standalone Codepurify templates
.codepurify - Alternative extension for Codepurify templates
Icon Theme
The extension includes a custom icon theme for Codepurify files:
Installation
- Install the Codepurify Templates extension
- Open VS Code Settings
- Navigate to File Icon Theme
- Select "Codepurify Icons" from the dropdown
Icons Included
- Files:
.code and .codepurify files get custom Codepurify icons
- Folders:
codepurify, codepurify-templates, examples, examplets folders get themed icons
Alternative: Material Icon Theme
If you prefer Material Icon Theme, you can map Codepurify files to existing icons:
{
"material-icon-theme.files.associations": {
"*.code": "template",
"*.codepurify": "template"
},
"material-icon-theme.folders.associations": {
"codepurify": "template",
"codepurify-templates": "template"
}
}
Installation
From VS Code Marketplace
- Open VS Code
- Go to Extensions (
Ctrl+Shift+X)
- Search for "Codepurify Templates"
- Click Install
Manual Installation (VSIX)
- Download the latest
.vsix file from Releases
- In VS Code: Extensions → "..." → "Install from VSIX..."
- Select the downloaded
.vsix file
Syntax Examples
Variables and Properties
{
!entity.name.casing.pascal!;
}
{
!field.name.casing.camel!;
}
{
!relation.target_entity.name.kebab!;
}
{
!entity.name.singular.casing.snake!;
}
Control Flow
{| if field.flags.is_string |}
@IsString()
{| /if |}
{| loop entity.fields.array.parts.items as field |}
{| field.name.casing.camel |}: string;
{| /loop |}
{| raw |}
// This code will be output exactly as written
{| /raw |}
{|# This is a comment #|}
{|# Multi-line comment
spanning multiple lines #|}
Error Validation
The extension provides real-time validation:
✅ Valid: {| entity.name.casing.camel |}
❌ Error: {| entity.name.casings.camel |} - Unknown variable casings
✅ Valid: {| if condition |} ... {| /if |}
❌ Error: {| if condition |} - Unclosed control flow
Autocomplete
The extension provides intelligent autocomplete for:
- Variables: All available variables from your template context
- Properties: Nested properties with dot notation
- Keywords:
if, loop, raw, else, etc.
- Snippets: Common template patterns
Type {| inside any supported file to see available completions.
Configuration
Variable Definitions
The extension reads variable definitions from a CSV file. Place your tempurify_v1_template_context_variables.csv in the data/ folder with the format:
path,name,description,type
entity.name.casing.camel,Camel Case,Camel case version of entity name,string
entity.fields.array.all,All Fields,Array of all field objects,array
Theme Customization
Customize colors in your VS Code settings:
{
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": "keyword.control.codepurify",
"settings": {
"foreground": "#C586C0"
}
},
{
"scope": "variable.other.codepurify",
"settings": {
"foreground": "#4FC1FF"
}
},
{
"scope": "comment.block.codepurify",
"settings": {
"foreground": "#6A9955"
}
}
]
}
}
Grammar Scopes
keyword.control.codepurify - Control flow keywords (if, loop, /if, /loop)
keyword.operator.word.codepurify - Operators (as, in, and, or, not, is)
variable.other.path.codepurify - Variable paths with dot notation
variable.other.identifier.codepurify - Simple identifiers
comment.block.codepurify - Template comments
meta.expression.codepurify - Complete template expressions
Development
File Structure
codepurify-vscode/
├── package.json # Extension manifest
├── language-configuration.json # Language configuration
├── language-configuration-*.json # Multi-language configs
├── syntaxes/
│ ├── codepurify.tmLanguage.json # Base grammar
│ ├── codepurify-ts.tmLanguage.json
│ ├── codepurify-tsx.tmLanguage.json
│ ├── codepurify-md.tmLanguage.json
│ └── codepurify-html.tmLanguage.json
├── snippets/
│ └── codepurify.json # Code snippets
├── data/
│ └── tempurify_v1_template_context_variables.csv
└── src/
└── extension.ts # Extension logic
Building and Testing
- Clone the repository
- Install dependencies:
npm install
- Compile:
npm run compile
- Test: Press
F5 to open Extension Development Host
- Package:
vsce package
Contributing
- Fork the repository
- Create a feature branch
- Update grammar or add new features
- Test thoroughly with various template files
- Submit a pull request
License
MIT License - see LICENSE file for details.
Support
Syntax Examples
Variables
{
!entity.name.casing.pascal!;
}
{
!field.name.casing.camel!;
}
{
!relation.target_entity.name.kebab!;
}
Control Flow
{| if field.flags.is_string |}
@IsString()
{| /if |}
{| loop entity.fields.array.parts.items as field |}
{| field.name.casing.camel |}: string;
{| /loop |}
{|# This is a comment #|}
{|# Multi-line comment
spanning multiple lines #|}
File Association
.code files are automatically associated with TypeScript, providing:
- TypeScript syntax highlighting
- JSX/TSX support
- IntelliSense for TypeScript code
- Proper indentation
- Comment toggling
Theme Customization
Add to your VS Code settings to customize colors:
{
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": "keyword.control.codepurify",
"settings": {
"foreground": "#C586C0"
}
},
{
"scope": "variable.other.codepurify",
"settings": {
"foreground": "#4FC1FF"
}
},
{
"scope": "comment.block.codepurify",
"settings": {
"foreground": "#6A9955"
}
}
]
}
}
Grammar Scopes
keyword.control.codepurify - Control flow keywords (if, loop, /if, /loop)
variable.other.codepurify - Variable access expressions
comment.block.codepurify - Template comments
Development
File Structure
codepurify-vscode/
├── package.json # Extension manifest
├── language-configuration.json # Language configuration
├── syntaxes/
│ └── codepurify.tmLanguage.json # TextMate grammar
└── README.md # This file
Testing
- Create test
.code files in the test/ directory
- Open Extension Development Host (
F5)
- Verify syntax highlighting works correctly
Contributing
- Update the TextMate grammar in
syntaxes/codepurify.tmLanguage.json
- Test with various template files
- Update documentation as needed
License
MIT