ocre-cli 0.2.0

Command-line tool for Ocre: create, generate, migrate, run and deploy apps.
//! <%= human %> pages (HTML). Generated by `<%= command %>`.
//! Each action renders templates/<%= module %>/<action>.html inside layout.html.

use askama::Template;
use axum::{Router, response::Html, routing::get};
use ocre::{Ctx, Result, render};
<% if auth %>

use crate::auth::CurrentUser;
<% endif %>

pub fn routes() -> Router<Ctx> {
    Router::new()
<% for action in actions %>
        .route("<%= action.path %>", get(<%= action.name %>))
<% endfor %>
}

/// Paths of the <%= human | lower %> pages, for links (`{{ paths::<%= actions[0].name %>() }}` in a
/// template) and redirects (`Redirect::to(paths::<%= actions[0].name %>())`).
#[allow(dead_code)]
pub mod paths {
<% for action in actions %>
    pub fn <%= action.name %>() -> &'static str {
        "<%= action.path %>"
    }
<% if not loop.last %>

<% endif %>
<% endfor %>
}
<% for action in actions %>

#[derive(Template)]
#[template(path = "<%= module %>/<%= action.name %>.html")]
struct <%= action.pascal %>View;

<% if auth %>
/// Signed-in users only: visitors are redirected to /login.
async fn <%= action.name %>(CurrentUser(_user): CurrentUser) -> Result<Html<String>> {
<% else %>
async fn <%= action.name %>() -> Result<Html<String>> {
<% endif %>
    render(&<%= action.pascal %>View)
}
<% endfor %>