### Example Clay Generator Configuration (generator.json) Source: https://github.com/morkeleb/clay/blob/master/README.md This example demonstrates the overall structure of a `generator.json` file. It defines the sequence of steps Clay will take to generate code, along with optional handlebar partials and formatters. This configuration drives the code generation process based on the input domain model. ```JSON { "partials": [], "steps": [ { "runCommand": "jhipster microservice" }, { "generate": "templates/jdl-files", "select": "$.jsonpath.statement" }, { "runCommand": "jhipster import-jdl {{service.name}}", "select": "$.jsonpath.statement" }, { "copy": "git+morkeleb/foundation", "select": "$.jsonpath.statement", "target": "{{microservice}}" } ], "formatters": ["clay-generator-formatter-prettier"] } ``` -------------------------------- ### Install Clay CLI Tool Globally Source: https://github.com/morkeleb/clay/blob/master/README.md This command installs the Clay code generator as a global command-line tool using npm. Installing it globally allows you to run 'clay' commands from any directory in your terminal. ```npm npm install -g clay-generator ``` -------------------------------- ### Initialize New Clay Generator Source: https://github.com/morkeleb/clay/blob/master/README.md This variation of the 'init' command helps in quickly setting up a new custom generator for your Clay project. It creates a dedicated directory for the generator under 'clay/generators/' and includes a basic 'generator.json' file. This provides a starting point for defining the steps and configurations of your new generator. ```shell clay init generator ``` -------------------------------- ### Clay Generator Configuration with Formatters Source: https://github.com/morkeleb/clay/blob/master/README.md This JSON snippet provides a complete example of a `generator.json` configuration. It includes an empty `partials` array, a `formatters` array specifying an external formatter, and a `steps` array demonstrating various step types like `runCommand`, `generate`, and `copy`. ```JSON { "partials":[], "formatters":["clay-generator-formatter-prettier"], "steps":[ { "runCommand": "yo newservice" }, { "generate": "templates/html", "select": "jsonpath statement" }, { "runCommand": "yo servicepart {{service.name}}", "select": "jsonpath statement" }, { "copy": "foundation", "select": "jsonpath statement", "target": "{{microservice}}" } ] } ``` -------------------------------- ### Clay Handlebars Template Example Source: https://github.com/morkeleb/clay/blob/master/README.md This Handlebars template example demonstrates dynamic code generation. It defines a JavaScript function with placeholders for parameters, type names, and event names, allowing the generator to produce varied output based on the input model. ```Handlebars var command = function (user, {{ parameters }}) { var {{lowerCase type.name}} = repository.find('{{type.name}}', id); if({{lowerCase type.name}}){ eventsource.raise('{{raises}}', [user, {{parameters}}]); } } ``` -------------------------------- ### Handlebars Partial and Variable Usage Source: https://github.com/morkeleb/clay/blob/master/test/samples/templates/simple/{{name}}.txt This snippet showcases two core Handlebars features: `{{>partialName}}` for embedding other template files or fragments, and `{{variableName}}` for rendering data passed into the template context. This pattern is widely used for building dynamic web pages. ```Handlebars {{>hello}}\n{{name}} ``` -------------------------------- ### Example Clay Domain Model (models.json) Source: https://github.com/morkeleb/clay/blob/master/README.md This snippet illustrates the structure of a `models.json` file, which defines the domain model for Clay. It includes properties for the model's name, associated generators, mixins (JavaScript functions for model modifications), and the core JSON structure of the model itself. Reserved properties like `mixin` and `include` are used for dynamic model composition. ```JSON { name: 'mymodel', generators: [ 'documentation', 'backend.json' ], mixins: [ 'has_created.js', 'has_error.js' ], model: { events: [ {include: 'standardevents.json'} ], types:[ { name: 'order', mixin: [has_created, has_errors], commands: [ { name: 'finish_order', raise: 'order_finished', parameters: [ { name: 'finished' } ] } ], fields: [ { name: 'test' } ] } ] } } ``` -------------------------------- ### Clay Handlebars Partial Inclusion Example Source: https://github.com/morkeleb/clay/blob/master/README.md This Handlebars snippet illustrates how to include a partial named 'header' within a template. Partials help in reusing common template components like headers or footers. ```Handlebars {{>header }}

{{name}}

``` -------------------------------- ### Initialize Clay Project Source: https://github.com/morkeleb/clay/blob/master/README.md The 'init' command is used to set up a new Clay project in the current directory by creating a '.clay' file. This file is crucial for Clay's operations, allowing other commands like 'generate' and 'clean' to function without requiring explicit model and output path arguments. If a '.clay' file already exists, the command will fail to prevent overwriting. ```shell clay init ``` -------------------------------- ### GitHub Copilot Instructions for Clay Generator Source: https://github.com/morkeleb/clay/blob/master/README.md This markdown content is designed to be placed in a `copilot-instructions.md` file within a Clay project. Its purpose is to educate GitHub Copilot about Clay's architecture, key concepts (models, generators, templates), common development tasks, available CLI commands, and best practices, thereby enabling Copilot to provide intelligent, context-aware suggestions for Clay-related development. ```markdown # Clay Generator Instructions for GitHub Copilot ## Overview Clay is a template-focused code generator that uses JSON models and Handlebars templates to generate code. The system consists of models, generators, templates, and partials. ## Key Concepts ### Models (model.json) - JSON files that describe the domain model - Can include mixins and includes for modularity - Support JSONPath selectors for targeting specific parts - Reserved properties: `mixin`, `include`, `generators` ### Generators (generator.json) - Define steps to transform models into code - Support three types of steps: - `generate`: Use Handlebars templates - `copy`: Copy files/directories - `runCommand`: Execute shell commands - Can include partials and formatters ### Templates - Use Handlebars syntax with extensive helper library - Support dynamic file paths using model data - Include lobars helpers for string manipulation (camelCase, kebabCase, etc.) ## Common Tasks ### Creating Models When creating model.json files: - Use clear, descriptive property names - Leverage JSONPath for selecting data subsets - Consider using mixins for reusable functionality - Structure data to match the intended output ### Writing Templates When creating Handlebars templates: - Use appropriate helpers: `{{pascalCase name}}`, `{{kebabCase name}}`, etc. - Leverage partials for reusable components - Use conditional logic: `{{#if condition}}...{{/if}}` - Iterate with: `{{#each items}}...{{/each}}` ### Configuring Generators When setting up generator.json: - Order steps logically (dependencies first) - Use JSONPath selectors to target specific model parts - Include formatters for code quality - Test with `clay test-path` command ## Available Commands - `clay generate ` - Generate code - `clay clean ` - Clean generated files - `clay watch ` - Watch for changes - `clay test-path ` - Test JSONPath selectors - `clay init` - Initialize Clay project ## Best Practices - Use semantic naming for models and generators - Keep templates focused and modular - Test JSONPath expressions before using in generators - Use the .clay file for tracking generated files - Leverage mixins for common model transformations ``` -------------------------------- ### Clay Generator Step Parameters Reference Source: https://github.com/morkeleb/clay/blob/master/README.md This API documentation outlines the configurable parameters for individual steps within a Clay generator. Each parameter controls a specific aspect of the step's behavior, such as command execution, file generation, or content copying. ```APIDOC Step Parameters: runCommand: type: string optional: true description: A string representing the shell command to execute. npxCommand: type: boolean optional: true description: A boolean indicating whether the command should be run using `npx`. generate: type: string optional: true description: A string specifying the path to the handlebar template to use for file generation. touch: type: boolean optional: true description: If true, ensures the file is only generated if it does not already exist. select: type: string optional: true description: A JSONPath string to filter the model for the step. copy: type: string optional: true description: A string representing the source path to copy. target: type: string optional: true description: A string specifying the target path for the generated or copied files. ``` -------------------------------- ### Clay Command-Line Interface Usage Source: https://github.com/morkeleb/clay/blob/master/README.md Running the 'clay' command without any arguments displays its general usage, available options, and a list of all supported commands. This output serves as a quick reference for interacting with the Clay CLI. ```shell clay Usage: clay [options] [command] Options: -V, --version output the version number -v, --verbose ignore test hook -h, --help output usage information Commands: test-path test a json-path selector using your model clean cleans up the output of the generators generate runs the generators watch runs the generators on filechanges in the models directory init [type] [name] initializes the folder with an empty .clay file or a generator ``` -------------------------------- ### Recommended Clay Project Directory Layout Source: https://github.com/morkeleb/clay/blob/master/README.md This structure illustrates a recommended way to organize your Clay project, keeping models and custom generators within a dedicated 'clay' directory. This layout simplifies the use of the 'clay watch' command, enabling continuous development on both generators and the model. It promotes modularity and ease of management for different parts of your generated system. ```plaintext . ├── dataaccess │   ├── generator.json │   └── template │   └── db.js ├── frontend │   ├── components │   │   ├── {{pascalCase\ name}}Components.js │   ├── generator.json │   ├── partials │   │   └── form-fields.js │   └── reducers │      └── {{kebabCase\ name}}.reducer.js ├── mixins │   └── default_actions.mixin.js └── model.json ``` -------------------------------- ### Clay Handlebars Helper: markdown Source: https://github.com/morkeleb/clay/blob/master/README.md This API documentation describes the `markdown` Handlebars helper available in Clay. It renders a given string as HTML using Markdown syntax. ```APIDOC markdown: description: Renders a string as HTML using Markdown. usage: "{{markdown description}}" ``` -------------------------------- ### Clay Generator Copy Step Configuration Source: https://github.com/morkeleb/clay/blob/master/README.md This JSON snippet demonstrates a 'copy' step in a Clay generator. It copies the 'foundation' directory, filtering the model using JSONPath, and targets a dynamically generated path based on the type's name. ```JSON { "copy": "foundation", "select": "$.model.types[*]", "target": "{{name}}/foundation" } ``` -------------------------------- ### Clay Generator Run Command Step with npx Source: https://github.com/morkeleb/clay/blob/master/README.md This JSON snippet illustrates a 'runCommand' step that executes a shell command using `npx`. The `npxCommand` flag ensures the command is run via npx. ```JSON { "runCommand": "yo newservice", "npxCommand": true } ``` -------------------------------- ### Clay Generator Step: Run Shell Command Source: https://github.com/morkeleb/clay/blob/master/README.md This snippet shows how to define a step within `generator.json` to execute an arbitrary shell command. The `npxCommand` parameter can be used to specify if the command should be run via `npx`, useful for executing CLI tools. ```JSON { "runCommand": "yo newservice", "npxCommand": true } ``` -------------------------------- ### Clay Generator Handlebars Template Generation with Touch Source: https://github.com/morkeleb/clay/blob/master/README.md This JSON snippet demonstrates a 'generate' step similar to the previous one, but with the `touch` option enabled. This ensures the file is only generated if it does not already exist at the target location. ```JSON { "generate": "templates/java{{name}}.js", "select": "$.model.types[*]", "target": "src/{{name}}.js", "touch": true } ``` -------------------------------- ### Clay Generator Step: Copy Files Source: https://github.com/morkeleb/clay/blob/master/README.md This snippet demonstrates how to configure a step to copy files from a specified source to a target location. Similar to other steps, it supports a `select` JSONPath expression to apply the copy operation based on filtered model data. ```JSON { "copy": "foundation", "select": "$.model.types[*]", "target": "{{name}}/foundation" } ``` -------------------------------- ### Generate Code with Clay Source: https://github.com/morkeleb/clay/blob/master/README.md The 'generate' command is central to Clay's functionality, taking a model and an output path to produce code. It processes the specified model through configured generators and writes the resulting files to the designated output directory. ```shell clay generate ``` -------------------------------- ### Clay Generator Step Definitions APIDOC Source: https://github.com/morkeleb/clay/blob/master/README.md Details the parameters and purpose of each type of step that can be included in the `steps` array of `generator.json`. These steps define the actions Clay performs during code generation, such as running commands, generating files from templates, or copying files. ```APIDOC Generator Step Types: 1. Run Command Step: runCommand: string (The shell command to execute) npxCommand: boolean (Optional, whether to run the command using npx) 2. Generate Handlebar Template Step: generate: string (Path to the handlebar template) select: string (Optional, JSONPath to filter the model) target: string (Optional, Target path for the generated files) touch: boolean (Optional, Generate only if the file does not exist) 3. Copy Files Step: copy: string (Source path to copy) select: string (Optional, JSONPath to filter the model) target: string (Optional, Target path for the copied files) ``` -------------------------------- ### Clay Generator Dynamic Run Command Step Source: https://github.com/morkeleb/clay/blob/master/README.md This JSON snippet illustrates a 'runCommand' step that executes a shell command dynamically. It uses JSONPath to iterate over model types and injects the type's name into the command string. ```JSON { "runCommand": "echo Generating {{name}}", "select": "$.model.types[*]" } ``` -------------------------------- ### Clay Generator Handlebars Template Generation Step Source: https://github.com/morkeleb/clay/blob/master/README.md This JSON snippet shows a 'generate' step for creating files from a Handlebars template. It specifies the template path, filters the model, and defines the target output path, dynamically naming files based on the model's types. ```JSON { "generate": "templates/java{{name}}.js", "select": "$.model.types[*]", "target": "src/{{name}}.js" } ``` -------------------------------- ### Common String Manipulation Helpers from Lobars (Handlebars) Source: https://github.com/morkeleb/clay/blob/master/README.md Provides a comprehensive set of string manipulation helpers from the `lobars` library, wrapping Lodash functions for use in Handlebars templates. Includes `camelCase`, `capitalize`, `kebabCase`, `snakeCase`, `lowerCase`, `upperCase`, `startCase`, `pad`, `repeat`, `replace`, and `truncate` for various text transformations. ```handlebars {{camelCase "hello world"}} → helloWorld {{capitalize "hello world"}} → Hello world {{kebabCase "Hello World"}} → hello-world {{snakeCase "Hello World"}} → hello_world {{lowerCase "Hello World"}} → hello world {{upperCase "Hello World"}} → HELLO WORLD {{startCase "hello world"}} → Hello World {{pad "abc" 5}} → " abc " {{repeat "ab" 3}} → ababab {{replace "foo bar" "bar" "baz"}} → foo baz {{truncate "Hello World" 5}} → Hello... ``` -------------------------------- ### Utility Helpers from Lobars (Handlebars) Source: https://github.com/morkeleb/clay/blob/master/README.md General utility helpers from the `lobars` library for Handlebars templates, such as `parseInt` for converting strings to integers, and `split` and `words` for breaking strings into arrays or words. ```handlebars {{parseInt "42"}} → 42 {{#each (split "a,b,c" ",")}}[{{this}}]{{/each}} → [a][b][c] {{#each (words "foo bar")}}[{{this}}]{{/each}} → [foo][bar] ``` -------------------------------- ### Clay Generator Step: Generate Files from Handlebar Template Source: https://github.com/morkeleb/clay/blob/master/README.md This configuration defines a step to generate files using a Handlebar template. It allows specifying a `select` JSONPath expression to filter the model data, a `target` path for the output file, and a `touch` option to generate only if the file doesn't already exist. ```JSON { "generate": "templates/java{{name}}.js", "select": "$.model.types[*]", "target": "src/{{name}}.js", "touch": true } ``` -------------------------------- ### Clay Generator File Structure (generator.json) APIDOC Source: https://github.com/morkeleb/clay/blob/master/README.md Describes the main sections of the `generator.json` file: `partials`, `steps`, and `formatters`. This file orchestrates the code generation process by defining a sequence of actions. ```APIDOC generator.json: partials: array of string (Handlebar partials paths) steps: array of object (Sequence of actions to perform) formatters: array of string (Optional list of formatters for generated files) ``` -------------------------------- ### Handlebars Comparison and Logical Operators Source: https://github.com/morkeleb/clay/blob/master/README.md A collection of Handlebars helpers for common comparison (`eq`, `ne`, `lt`, `gt`, `lte`, `gte`) and logical (`and`, `or`) operations. These helpers facilitate complex conditional rendering and data evaluation within templates. ```handlebars {{#if (eq a b)}}...{{/if}} {{#if (ne a b)}}...{{/if}} {{#if (lt a b)}}...{{/if}} {{#if (gt a b)}}...{{/if}} {{#if (lte a b)}}...{{/if}} {{#if (gte a b)}}...{{/if}} {{#if (and a b c)}}...{{/if}} {{#if (or a b c)}}...{{/if}} ``` -------------------------------- ### Comparison and Type Checking Helpers from Lobars (Handlebars) Source: https://github.com/morkeleb/clay/blob/master/README.md Offers a range of comparison and type checking helpers from the `lobars` library, enabling robust conditional logic and data validation in Handlebars. Functions include `eq`, `ne`, `gt`, `gte`, `lt`, `lte` for comparisons, and `isArray`, `isBoolean`, `isEmpty`, `isNumber`, `isString`, `isObject`, `isNull`, `isUndefined`, `includes`, `startsWith`, `endsWith` for type and content checks. ```handlebars {{#if (eq a b)}}Equal{{/if}} {{#if (isArray myVar)}}It's an array!{{/if}} {{#if (includes "foobar" "foo")}}Yes{{/if}} ``` -------------------------------- ### Implement Switch/Case/Default Logic in Handlebars Source: https://github.com/morkeleb/clay/blob/master/README.md Provides a `switch` block helper with `case` and `default` sub-helpers to implement conditional rendering logic similar to switch statements in programming languages. This allows for multiple conditional branches based on a single variable's value. ```handlebars {{#switch type}} {{#case "admin"}} Admin user {{/case}} {{#case "user"}} Regular user {{/case}} {{#default}} Unknown type {{/default}} {{/switch}} ``` -------------------------------- ### Clay Model File Structure (models.json) APIDOC Source: https://github.com/morkeleb/clay/blob/master/README.md Defines the top-level structure and key properties of the `models.json` file, including `name`, `generators`, `mixins`, and the `model` itself. It also notes reserved properties like `mixin` and `include` that facilitate dynamic model composition. ```APIDOC models.json: name: string (The name of the model) generators: array of string (List of generator names/paths to run) mixins: array of string (List of JavaScript functions to apply as mixins) model: object (The core JSON structure of the domain model) Reserved Properties: mixin: array of functions (List of functions to execute on a part of the model) include: string (Path to a file whose content will replace the current part of the model) ``` -------------------------------- ### Conditional Logic with Operators in Handlebars Source: https://github.com/morkeleb/clay/blob/master/README.md Enables advanced conditional logic using the `ifCond` helper, supporting various comparison and logical operators such as `==`, `!=`, `<`, `>`, `<=`, `>=`, `&&`, and `||`. This allows for more complex conditional rendering than standard `if` statements. ```handlebars {{#ifCond value "==" 10}} Value is 10 {{else}} Value is not 10 {{/ifCond}} ``` -------------------------------- ### Convert String to PascalCase in Handlebars Source: https://github.com/morkeleb/clay/blob/master/README.md Converts a given string to PascalCase format using the `pascalCase` helper. This is useful for standardizing naming conventions in template output. ```handlebars {{pascalCase name}} ``` -------------------------------- ### Test JSONPath Selectors with Clay Source: https://github.com/morkeleb/clay/blob/master/README.md The 'test-path' command allows developers to validate JSONPath expressions against a given model. This is particularly useful during generator and template creation to ensure that JSONPath selectors correctly extract the desired data from the model. The command outputs the model objects that match the specified path. ```shell clay test-path $.model.types[*].actions[*].parameters[?\(@.type==\"array\"\)] ``` -------------------------------- ### Watch for Model Changes with Clay Source: https://github.com/morkeleb/clay/blob/master/README.md The 'watch' command continuously monitors the model directory for file changes and automatically re-runs the generators when modifications are detected. This feature is highly beneficial for iterative development, allowing for immediate feedback as you adjust your model or custom generators. It follows the same input structure as the 'generate' command. ```shell clay watch ``` -------------------------------- ### Clean Generated Code with Clay Source: https://github.com/morkeleb/clay/blob/master/README.md The 'clean' command is used to remove all code previously generated by Clay based on the generators specified in the model. It helps in reverting the output directory to a clean state by deleting files that were created during the generation process. Note that it does not undo any command-line executions performed by a generator. ```shell clay clean ``` -------------------------------- ### Pretty-Print JavaScript Object as JSON in Handlebars Source: https://github.com/morkeleb/clay/blob/master/README.md Pretty-prints a JavaScript object as formatted JSON using the `json` helper. This is commonly used within a `
` tag to display structured data legibly in HTML output.

```handlebars
{{{json this}}}
``` -------------------------------- ### Repeat Block N Times in Handlebars Source: https://github.com/morkeleb/clay/blob/master/README.md Repeats a block of content a specified number of times using the `times` helper. The current iteration index (`@index`) is available within the block, useful for generating repetitive elements. ```handlebars {{#times 3}} Index: {{@index}} {{/times}} ``` -------------------------------- ### Singularize Word in Handlebars Source: https://github.com/morkeleb/clay/blob/master/README.md Singularizes a given word based on English grammar rules using the `singularize` helper. This is useful for dynamically adjusting text based on quantity. ```handlebars {{singularize "categories"}} ``` -------------------------------- ### Split String and Extract Word by Index in Handlebars Source: https://github.com/morkeleb/clay/blob/master/README.md Splits a string by a specified delimiter and returns the word at a given index using the `splitAndUseWord` helper. This is useful for parsing and extracting specific parts of a delimited string. ```handlebars {{splitAndUseWord "foo-bar-baz" "-" 1}} ``` -------------------------------- ### Iterate Over Unique Values by JSONPath in Handlebars Source: https://github.com/morkeleb/clay/blob/master/README.md Iterates over unique values selected by a JSONPath expression within a model using the `eachUniqueJSONPath` helper. This allows for precise extraction and iteration over specific unique data points in complex JSON structures. ```handlebars {{#eachUniqueJSONPath model "$.types[*].name"}} {{this}} {{/eachUniqueJSONPath}} ``` -------------------------------- ### Pluralize Word in Handlebars Source: https://github.com/morkeleb/clay/blob/master/README.md Pluralizes a given word based on English grammar rules using the `pluralize` helper. This can be used to dynamically adjust text based on quantity. ```handlebars {{pluralize "category"}} ``` -------------------------------- ### Check if Property Exists in Handlebars Context Source: https://github.com/morkeleb/clay/blob/master/README.md Checks if a property exists in any object within the current Handlebars context using the `propertyExists` helper. This is useful for conditional rendering based on data availability. ```handlebars {{#if (propertyExists this "fieldName")}} Property exists! {{/if}} ``` -------------------------------- ### Iterate Over Unique Values in Handlebars Source: https://github.com/morkeleb/clay/blob/master/README.md Iterates over unique values within an array or object using the `eachUnique` helper. It can also extract unique values based on a specified property, providing flexibility for displaying distinct data points. ```handlebars {{#eachUnique items}} {{this}} {{/eachUnique}} Or, to get unique by a property: {{#eachUnique items "id"}} {{this.name}} {{/eachUnique}} ``` -------------------------------- ### Increment Number by One in Handlebars Source: https://github.com/morkeleb/clay/blob/master/README.md Increments a numeric value by 1 using the `inc` helper. This is particularly useful for generating 1-based indexes in loops or for simple counter operations. ```handlebars {{inc @index}} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.