Catalog / Hanami Framework Cheatsheet
Hanami Framework Cheatsheet
A quick reference guide to the Hanami framework, covering essential commands, configurations, and concepts for building robust web applications.
Project Setup & Core Concepts
Project Initialization
Creating a new Hanami project:
This command generates a basic Hanami project structure. |
Starting the development server:
Launches the Hanami development server, usually on |
Project Structure Overview:
|
Application Architecture
Slice |
A modular component encapsulating specific functionality within an application. |
Actions |
Handle incoming HTTP requests and orchestrate the response. Similar to controllers in other frameworks. |
Views |
Responsible for rendering the response. They prepare data for templates. |
Repositories |
Interact with the database. Provide an abstraction layer for data access. |
Entities |
Represent domain objects. They encapsulate data and business logic. |
Routing & Controllers (Actions)
Defining Routes
Basic Route Definition: Inside
This maps a GET request to |
Route Shorthands:
|
Resources:
Automatically generates routes for common CRUD operations. |
Creating Actions
Action Class Structure:
|
Exposing Data to Views: Instance variables set in the |
Handling Parameters: Request parameters are accessible through the |
Views & Templates
View Components
Basic View Structure:
|
Templates: Located in Access data exposed by the view using instance variables or the |
Partials: Create reusable template snippets.
|
Template Engines
ERB |
Embedded Ruby, the default template engine. |
Slim |
A fast and lightweight template engine with a clean syntax. |
Haml |
Another popular template engine with a concise syntax. |
Models & Repositories
Defining Entities
Entity Structure:
Entities represent domain objects. They encapsulate data and business logic. |
Attributes: Attributes are defined through database schema. Example: |
Repositories
Repository Structure:
|
Common Operations:
|
Querying:
|