Skip to content

Fix app template generation: settings API and layout constant#19

Open
crimson-knight wants to merge 6 commits intomainfrom
feature/v2-generators
Open

Fix app template generation: settings API and layout constant#19
crimson-knight wants to merge 6 commits intomainfrom
feature/v2-generators

Conversation

@crimson-knight
Copy link
Member

Summary

  • Fix Amber::Server.settings.nameAmber.settings.name in both ECR and Slang index templates
  • Add LAYOUT = "application.#{template}" to generated ApplicationController so the render macro uses the correct layout file extension

How it was discovered

While testing Amber V2 app generation with crystal-alpha (the Crystal incremental compiler), a freshly generated ECR app failed to compile with two errors:

  1. undefined method 'settings' for Amber::Server.class — The V2 API exposes settings on the Amber module directly (Amber.settings), not on Amber::Server
  2. Slang template: src/views/layouts/application.slang doesn't exist — The Amber framework's render macro hardcodes LAYOUT = "application.slang". ECR apps need the controller to override this constant to match their template engine

What changed

src/amber_cli/commands/new.cr:

  • create_application_controller now sets LAYOUT = "application.#{template}" so the layout file extension matches whichever template engine was selected (-t ecr or -t slang)
  • Both Slang and ECR index view templates updated to use Amber.settings.name

Test plan

  • Generate new ECR app with amber new test_app
  • shards install completes
  • crystal build src/test_app.cr compiles successfully
  • Server starts and responds on port 3000
  • Slang template path also updated (same settings API fix)

🤖 Generated with Claude Code

crimson-knight and others added 6 commits February 14, 2026 16:16
…isting generators

New generators added to `amber generate`:
- `job` - Generates Amber::Jobs::Job subclass with JSON::Serializable,
  perform method, queue/retry overrides, and registration. Supports
  --queue and --max-retries options.
- `mailer` - Generates Amber::Mailer::Base subclass with fluent API
  (to/from/subject/deliver), ECR templates, and html_body/text_body
  methods. Supports --actions option for multiple mailer actions.
- `schema` - Generates Amber::Schema::Definition subclass with field
  definitions, type mapping, and format validators. Supports the
  name:type:required field syntax for marking required fields.
- `channel` - Generates Amber::WebSockets::Channel subclass with
  handle_joined/handle_leave/handle_message methods, plus a companion
  ClientSocket struct with channel registration.

Updated existing generators for V2 patterns:
- Controller: defaults to ECR templates, generates specs using
  Amber::Testing::RequestHelpers and Assertions
- Scaffold: generates a companion Schema class for create/update
  validation, uses schema-based params in controller, generates
  views with V2 form helpers (form_for, text_field, label, etc.)
- Mailer: now generates Amber::Mailer::Base instead of Quartz::Mailer
- Auth: generates ECR views with V2 form helpers by default
- API: includes schema validation in generated controllers
- Default template extension changed from slang to ecr

Updated `amber new` application template:
- Adds V2 directories: schemas/, jobs/, mailers/, channels/, sockets/
  in both src/ and spec/
- Generates spec/spec_helper.cr with Amber::Testing setup
- Generates config/routes.cr with full pipeline configuration
  (Error, Logger, Session, Flash, CSRF pipes)
- Generates environment config files (development, test, production)
- Generates .gitignore, db/seeds.cr, public assets (CSS, JS, robots.txt)
- Generates .keep files for all empty directories
- Main entry file requires all V2 component directories

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ng tests

Implements a complete Language Server Protocol server for Amber Framework
projects that provides real-time convention diagnostics. The LSP communicates
via stdio using standard Content-Length framed JSON-RPC messages, exactly as
editors and tools like Claude Code expect.

Core infrastructure:
- LSP server with initialize/shutdown/exit lifecycle
- Document store for tracking open files
- Project context detection via shard.yml amber dependency
- YAML-based configuration with per-rule enable/disable and severity overrides
- Analyzer pipeline connecting rules to the LSP protocol

15 convention rules across 10 categories:
- Controllers: naming, inheritance, filter syntax, action return type
- Jobs: perform method, JSON::Serializable
- Channels: handle_message method
- Pipes: call_next requirement
- Mailers: required methods
- Schemas: field type validation
- File naming: snake_case, directory structure
- Routing: controller action existence
- Specs: spec file existence
- Sockets: channel route validation

End-to-end validation:
- Full LSP lifecycle test (didOpen -> didSave -> didClose -> shutdown -> exit)
- Multi-rule diagnostic test verifying 4 simultaneous violations
- Non-Amber project isolation test (no false positives)
- Job rules integration test
- Configuration override test (.amber-lsp.yml)
- Binary stdio integration tests spawning the compiled amber-lsp binary

Also fixes rule_registry pattern matching to support absolute file paths,
enabling rules with directory-based applies_to patterns (e.g., src/controllers/*)
to match files opened via file:// URIs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds an `amber setup:lsp` command that configures the Amber LSP server
for Claude Code integration. The command resolves or builds the amber-lsp
binary, then creates .lsp.json, .claude-plugin/plugin.json, and
.amber-lsp.yml in the target project directory.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds custom rule engine for project-specific YAML-based rules (regex
patterns, glob-based file matching, configurable severity). Includes
agent E2E integration test and updates README with LSP documentation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
All CI workflows, release pipeline, and build script now build both
amber and amber-lsp binaries. Release tarballs include both. Homebrew
tap dispatch points to crimson-knight/homebrew-amber-cli. README
updated with dual-binary install instructions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The `new` command generated apps that failed to compile due to two issues:

1. Templates referenced `Amber::Server.settings.name` but the V2 API is
   `Amber.settings.name` (settings is on the Amber module, not Server class)

2. The render macro's LAYOUT constant defaults to "application.slang" in
   the Amber framework. ECR apps need ApplicationController to override
   this with "application.ecr" (or whichever engine was selected).

Discovered while testing Amber V2 app generation with crystal-alpha
(Crystal incremental compiler).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments