Page Generator

The Page Generator creates page components that handle the presentation layer of your Azu web application, including HTML templates and page-specific logic.

Usage

azu generate page PAGE_NAME [OPTIONS]

Description

Pages in Azu applications represent the view layer of your web application. They combine HTML templates with Crystal code to render dynamic content and handle user interactions. Pages can include forms, data display, and client-side functionality.

Options

  • PAGE_NAME - Name of the page to generate (required)

  • -d, --description DESCRIPTION - Description of the page

  • -t, --template TEMPLATE - Template to use (default: basic)

  • -f, --force - Overwrite existing files

  • -h, --help - Show help message

Examples

Generate a basic page

This creates:

  • src/pages/welcome_page.cr - The page class

  • src/pages/welcome_page.jinja - The HTML template

  • spec/pages/welcome_page_spec.cr - Test file

Generate a page with description

Generate specific page types

Generated Files

Page Class (src/pages/PAGE_NAME.cr)

HTML Template (src/pages/PAGE_NAME.jinja)

Test File (spec/pages/PAGE_NAME_spec.cr)

Page Patterns

Basic Page Pattern

Page with Data Loading

Page with Form Handling

Page with Authentication

Template Patterns

Basic Template

Template with Data Display

Template with Forms

Template with Navigation

Using Pages

Route Registration

Register pages in your application routes:

Page with Parameters

Page with Flash Messages

Best Practices

1. Keep Pages Focused

Each page should have a single responsibility:

2. Use Instance Variables for Template Data

3. Handle Errors Gracefully

4. Use Layouts and Partials

Testing Pages

Unit Testing

Integration Testing

Common Page Types

1. List Pages

Display collections of data:

2. Show Pages

Display individual records:

3. Form Pages

Handle user input:

4. Dashboard Pages

Display user-specific information:

  • azu generate endpoint - Generate API endpoints

  • azu generate model - Generate data models

  • azu generate contract - Generate validation contracts

  • azu generate service - Generate business logic services

Templates

The page generator supports different templates:

  • basic - Simple page with basic structure

  • blog - Blog post page template

  • form - Form handling page template

  • dashboard - Dashboard page template

  • list - List display page template

To use a specific template:

Last updated