class
AmberCLI::Documentation::GenerationSystem
- AmberCLI::Documentation::GenerationSystem
- Reference
- Object
Overview
Code Generation System
Amber CLI provides a flexible and configurable code generation system that can create models, controllers, views, and custom components.
Built-in Generators
The CLI includes several built-in generators:
Model Generator
Creates a new model with associated files:
amber generate model User name:String email:String
Generates:
src/models/user.cr- Model classspec/models/user_spec.cr- Model specdb/migrations/[timestamp]_create_users.sql- Migration file
Controller Generator
Creates a new controller:
amber generate controller Posts
Generates:
src/controllers/posts_controller.cr- Controller classspec/controllers/posts_controller_spec.cr- Controller spec
Scaffold Generator
Creates a complete CRUD resource:
amber generate scaffold Post title:String content:Text
Generates model, controller, views, and migration files.
Custom Generators
You can create custom generators by defining generator configuration files in JSON or YAML format. These files specify templates, transformations, and post-generation commands.
Generator Configuration Format
name: "my_custom_generator"
description: "Generates custom components"
template_variables:
author: "Your Name"
license: "MIT"
naming_conventions:
snake_case: "underscore_separated"
pascal_case: "CamelCase"
file_generation_rules:
service:
- template: "service_template"
output_path: "src/services/{{snake_case}}_service.cr"
post_generation_commands:
- "crystal tool format {{output_path}}"
Word Transformations
The generator system includes intelligent word transformations:
- snake_case -
user_account - pascal_case -
UserAccount - plural forms -
users,UserAccounts - singular forms -
user,UserAccount