Skip to content

Commit

Permalink
Merge pull request loco-rs#480 from loco-rs/clippy-gen
Browse files Browse the repository at this point in the history
clippy gen
  • Loading branch information
kaplanelad authored Mar 7, 2024
2 parents 02e2fc4 + bb8f2f3 commit a259b99
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 29 deletions.
2 changes: 1 addition & 1 deletion docs-site/content/docs/the-app/multiple-db.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
+++
title = "Multiple Db"
title = "Multiple DB connections"
description = ""
date = 2024-03-01T18:10:00+00:00
updated = 2024-03-01T18:10:00+00:00
Expand Down
12 changes: 5 additions & 7 deletions src/gen/templates/scaffold/html/controller.t
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ pub async fn list(
.order_by(Column::Id, Order::Desc)
.all(&ctx.db)
.await?;
views::{{file_name}}::list(v, item)
views::{{file_name}}::list(&v, &item)
}

pub async fn new(
ViewEngine(v): ViewEngine<TeraView>,
State(ctx): State<AppContext>,
) -> Result<impl IntoResponse> {
views::{{file_name}}::create(v)
views::{{file_name}}::create(&v)
}

pub async fn update(
Expand All @@ -80,7 +79,7 @@ pub async fn edit(
State(ctx): State<AppContext>,
) -> Result<impl IntoResponse> {
let item = load_item(&ctx, id).await?;
views::{{file_name}}::edit_form(v, item)
views::{{file_name}}::edit(&v, &item)
}

pub async fn show(
Expand All @@ -89,11 +88,10 @@ pub async fn show(
State(ctx): State<AppContext>,
) -> Result<impl IntoResponse> {
let item = load_item(&ctx, id).await?;
views::{{file_name}}::show(v, item)
views::{{file_name}}::show(&v, &item)
}

pub async fn add(
ViewEngine(v): ViewEngine<TeraView>,
State(ctx): State<AppContext>,
Form(params): Form<Params>,
) -> Result<Redirect> {
Expand All @@ -102,7 +100,7 @@ pub async fn add(
};
params.update(&mut item);
item.insert(&ctx.db).await?;
// views::post::show(v, item)
// views::post::show(&v, &item)
Ok(Redirect::to("{{file_name | plural}}"))
}
pub fn routes() -> Routes {
Expand Down
36 changes: 28 additions & 8 deletions src/gen/templates/scaffold/html/view.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,38 @@ use loco_rs::prelude::*;

use crate::models::_entities::{{file_name | plural}};

pub fn list(v: impl ViewRenderer, items: Vec<{{file_name | plural}}::Model>) -> Result<impl IntoResponse> {
format::render().view(&v, "{{file_name}}/list.html", serde_json::json!({"items": items}))
/// Render a list view of {{name | plural}}.
///
/// # Errors
///
/// When there is an issue with rendering the view.
pub fn list(v: &impl ViewRenderer, items: &Vec<{{file_name | plural}}::Model>) -> Result<impl IntoResponse> {
format::render().view(v, "{{file_name}}/list.html", serde_json::json!({"items": items}))
}

pub fn show(v: impl ViewRenderer, item: {{file_name | plural}}::Model) -> Result<impl IntoResponse> {
format::render().view(&v, "{{file_name}}/show.html", serde_json::json!({"item": item}))
/// Render a single {{name}} view.
///
/// # Errors
///
/// When there is an issue with rendering the view.
pub fn show(v: &impl ViewRenderer, item: &{{file_name | plural}}::Model) -> Result<impl IntoResponse> {
format::render().view(v, "{{file_name}}/show.html", serde_json::json!({"item": item}))
}

pub fn create(v: impl ViewRenderer) -> Result<impl IntoResponse> {
format::render().view(&v, "{{file_name}}/create.html", serde_json::json!({}))
/// Render a {{name }} create form.
///
/// # Errors
///
/// When there is an issue with rendering the view.
pub fn create(v: &impl ViewRenderer) -> Result<impl IntoResponse> {
format::render().view(v, "{{file_name}}/create.html", serde_json::json!({}))
}

pub fn edit_form(v: impl ViewRenderer, item: {{file_name | plural}}::Model) -> Result<impl IntoResponse> {
format::render().view(&v, "{{file_name}}/edit.html", serde_json::json!({"item": item}))
/// Render a {{name}} edit form.
///
/// # Errors
///
/// When there is an issue with rendering the view.
pub fn edit(v: &impl ViewRenderer, item: &{{file_name | plural}}::Model) -> Result<impl IntoResponse> {
format::render().view(v, "{{file_name}}/edit.html", serde_json::json!({"item": item}))
}
9 changes: 4 additions & 5 deletions src/gen/templates/scaffold/htmx/controller.t
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@ pub async fn list(
.order_by(Column::Id, Order::Desc)
.all(&ctx.db)
.await?;
views::{{file_name}}::list(v, item)
views::{{file_name}}::list(&v, &item)
}

pub async fn new(
ViewEngine(v): ViewEngine<TeraView>,
State(ctx): State<AppContext>,
) -> Result<impl IntoResponse> {
views::{{file_name}}::create(v)
}
Expand All @@ -79,7 +78,7 @@ pub async fn edit(
State(ctx): State<AppContext>,
) -> Result<impl IntoResponse> {
let item = load_item(&ctx, id).await?;
views::{{file_name}}::edit_form(v, item)
views::{{file_name}}::edit(&v, &item)
}

pub async fn show(
Expand All @@ -88,7 +87,7 @@ pub async fn show(
State(ctx): State<AppContext>,
) -> Result<impl IntoResponse> {
let item = load_item(&ctx, id).await?;
views::{{file_name}}::show(v, item)
views::{{file_name}}::show(&v, &item)
}

pub async fn add(
Expand All @@ -101,7 +100,7 @@ pub async fn add(
};
params.update(&mut item);
let item = item.insert(&ctx.db).await?;
views::{{file_name}}::show(v, item)
views::{{file_name}}::show(&v, &item)
}

pub fn routes() -> Routes {
Expand Down
36 changes: 28 additions & 8 deletions src/gen/templates/scaffold/htmx/view.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,38 @@ use loco_rs::prelude::*;

use crate::models::_entities::{{file_name | plural}};

pub fn list(v: impl ViewRenderer, items: Vec<{{file_name | plural}}::Model>) -> Result<impl IntoResponse> {
format::render().view(&v, "{{file_name}}/list.html", serde_json::json!({"items": items}))
/// Render a list view of {{name | plural}}.
///
/// # Errors
///
/// When there is an issue with rendering the view.
pub fn list(v: &impl ViewRenderer, items: &Vec<{{file_name | plural}}::Model>) -> Result<impl IntoResponse> {
format::render().view(v, "{{file_name}}/list.html", serde_json::json!({"items": items}))
}

pub fn show(v: impl ViewRenderer, item: {{file_name | plural}}::Model) -> Result<impl IntoResponse> {
format::render().view(&v, "{{file_name}}/show.html", serde_json::json!({"item": item}))
/// Render a single {{name}} view.
///
/// # Errors
///
/// When there is an issue with rendering the view.
pub fn show(v: &impl ViewRenderer, item: &{{file_name | plural}}::Model) -> Result<impl IntoResponse> {
format::render().view(v, "{{file_name}}/show.html", serde_json::json!({"item": item}))
}

pub fn create(v: impl ViewRenderer) -> Result<impl IntoResponse> {
format::render().view(&v, "{{file_name}}/create.html", serde_json::json!({}))
/// Render a {{name }} create form.
///
/// # Errors
///
/// When there is an issue with rendering the view.
pub fn create(v: &impl ViewRenderer) -> Result<impl IntoResponse> {
format::render().view(v, "{{file_name}}/create.html", serde_json::json!({}))
}

pub fn edit_form(v: impl ViewRenderer, item: {{file_name | plural}}::Model) -> Result<impl IntoResponse> {
format::render().view(&v, "{{file_name}}/edit.html", serde_json::json!({"item": item}))
/// Render a {{name}} edit form.
///
/// # Errors
///
/// When there is an issue with rendering the view.
pub fn edit(v: &impl ViewRenderer, item: &{{file_name | plural}}::Model) -> Result<impl IntoResponse> {
format::render().view(v, "{{file_name}}/edit.html", serde_json::json!({"item": item}))
}

0 comments on commit a259b99

Please sign in to comment.