From zef to first request.
One command to install, one keayl new to scaffold. The generator writes a config,
a routes file, a controller, and a view, and keayl server serves them on port 3000.
#1. install with zef
MVC::Keayl is distributed through Raku's package manager,
zef. Don't have Raku yet? Grab it from
rakudo.org; zef ships with
every install.
That installs the module and puts the keayl CLI on your PATH. Verify:
$ keayl version
MVC::Keayl 0.9.0
#2. scaffold an application
keayl new writes a runnable skeleton: the config/ (a layered
application.json, an application.raku that returns the
MVC::Keayl::Application, a routes.raku with a root
route, and encrypted credentials), a HomeController with its view and layout,
static exception pages under public/, an assets/ tree, a starter
spec, a META6.json, and bin/dev, bin/server, and
bin/test scripts.
created blog/.gitignore
created blog/META6.json
created blog/README.md
created blog/app/controllers/HomeController.rakumod
created blog/app/models/.keep
created blog/app/views/home/index.html.haml
created blog/app/views/layouts/application.html.haml
created blog/assets/css/style.css
created blog/assets/favicon.svg
created blog/config/application.json
created blog/config/application.raku
created blog/config/routes.raku
created blog/public/404.html
created blog/public/422.html
created blog/public/500.html
created blog/specs/home-spec.raku
created blog/tmp/.keep
created blog/bin/dev
created blog/bin/server
created blog/bin/test
created blog/config/master.key
created blog/config/credentials.yml.enc#3. draw a route, write an action
A request needs three pieces: a route that names the target, a controller with the action, and a view for it to render.
use MVC::Keayl::Routing;
routes {
root to => 'home#index';
resources 'articles';
}
use MVC::Keayl::Controller;
class ArticlesController is MVC::Keayl::Controller {
method index {
self.assign('articles', Article.all);
}
}
%h1 Articles
%ul
!= partial-each('articles/row', $articles)
%li= $row.title
#4. run it
keayl server loads config/application.raku, builds the Cro endpoint,
and listens. The host defaults to 127.0.0.1 and the port to 3000.
listening on http://127.0.0.1:3000 (development)#the keayl CLI
| Command | What it does |
|---|---|
| keayl new NAME | Scaffold a new application skeleton in a subdirectory. |
| keayl server | Boot the app and serve over HTTP. --host and --port override the defaults. keayl s is the short form. |
| keayl routes | Print the route table: name, verbs, path, and target for every route. |
| keayl console | Open a REPL with the application booted and bound to $*KEAYL-APP. keayl c is the short form. |
| keayl credentials-edit | Decrypt the credentials file, open it in $EDITOR, and re-encrypt on save. --env selects a per-environment file. |
| keayl version | Print the installed version. keayl help lists every command. |
#environments and config
MVC::Keayl::Config reads a JSON file, the same config/application.json
shared with ORM::ActiveRecord, merging a shared section under the
selected environment. The environment comes from KEAYL_ENV, then
RAKU_ENV, defaulting to development.
{
"shared": { "app-name": "Blog" },
"development": {
"database": { "adapter": "sqlite" },
"log-level": "debug"
},
"production": { "log-level": "error" }
}
#where to go next
Routing
Resourceful routes, namespaces, scopes, concerns, constraints, and URL helpers.
Controllers
Actions, filters, strong parameters, render and redirect, and rescue-from.
Views
HAML resolution, layouts, partials, view helpers, and output safety.
Security
CSRF, sessions, signed and encrypted cookies, secrets, and credentials.