Component Generator
The Component Generator creates reusable UI components that can be shared across different pages and templates in your Azu application.
Usage
azu generate component COMPONENT_NAME [OPTIONS]Description
Components in Azu applications are reusable UI elements that encapsulate both presentation logic and styling. They can be used across multiple pages to maintain consistency and reduce code duplication. Components can include forms, cards, navigation elements, and other UI patterns.
Options
COMPONENT_NAME- Name of the component to generate (required)-d, --description DESCRIPTION- Description of the component-t, --template TEMPLATE- Template to use (default: basic)-f, --force- Overwrite existing files-h, --help- Show help message
Examples
Generate a basic component
This creates:
src/components/user_card.cr- The component classsrc/components/user_card.jinja- The component templatespec/components/user_card_spec.cr- Test file
Generate a component with description
Generate specific component types
Generated Files
Component Class (src/components/COMPONENT_NAME.cr)
src/components/COMPONENT_NAME.cr)Component Template (src/components/COMPONENT_NAME.jinja)
src/components/COMPONENT_NAME.jinja)Test File (spec/components/COMPONENT_NAME_spec.cr)
spec/components/COMPONENT_NAME_spec.cr)Component Patterns
Basic Component Pattern
Component with Data Processing
Form Component Pattern
Navigation Component Pattern
Template Patterns
Basic Component Template
List Component Template
Form Component Template
Navigation Component Template
Using Components
In Pages
Use components in your page classes:
In Templates
Include components in your templates:
In Layouts
Use components in your layout templates:
Best Practices
1. Keep Components Focused
Each component should have a single responsibility:
2. Use Flexible Parameters
Make components configurable through parameters:
3. Handle Missing Data Gracefully
4. Use Semantic HTML
Testing Components
Unit Testing
Integration Testing
Common Component Types
1. Display Components
Show data in a consistent format:
2. Form Components
Reusable form elements:
3. Navigation Components
Site navigation elements:
4. Layout Components
Structural layout elements:
Related Commands
azu generate page- Generate page componentsazu generate endpoint- Generate API endpointsazu generate model- Generate data modelsazu generate service- Generate business logic services
Templates
The component generator supports different templates:
basic- Simple component with basic structurecard- Card display component templateform- Form component templatenavigation- Navigation component templatelist- List display component template
To use a specific template:
Last updated