Skip to content

Commit

Permalink
style: improve code formatting and organization
Browse files Browse the repository at this point in the history
  • Loading branch information
yinho999 committed Feb 1, 2025
1 parent c9bb3e6 commit f87081d
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 25 deletions.
10 changes: 5 additions & 5 deletions loco-gen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ pub use rrgen::{GenResult, RRgen};
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
mod controller;
use colored::Colorize;
use std::{
collections::HashMap,
fs,
path::{Path, PathBuf},
sync::OnceLock,
};

use colored::Colorize;

#[cfg(feature = "with-db")]
mod infer;
#[cfg(feature = "with-db")]
Expand All @@ -34,7 +35,6 @@ pub struct GenerateResults {
}
const DEPLOYMENT_SHUTTLE_RUNTIME_VERSION: &str = "0.51.0";


#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("{0}")]
Expand Down Expand Up @@ -240,8 +240,8 @@ pub enum DeploymentKind {
is_client_side_rendering: bool,
postgres: bool,
sqlite: bool,
background_queue: bool
}
background_queue: bool,
},
}

#[derive(Debug)]
Expand Down Expand Up @@ -395,7 +395,7 @@ pub fn generate(rrgen: &RRgen, component: Component, appinfo: &AppInfo) -> Resul
is_client_side_rendering,
postgres,
sqlite,
background_queue
background_queue,
} => {
let vars = json!({
"pkg_name": appinfo.app_name,
Expand Down
11 changes: 6 additions & 5 deletions loco-gen/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ pub fn get_columns_and_references(
let array_kind = match params.as_slice() {
[array_kind] => Ok(array_kind),
_ => Err(Error::Message(format!(
"type: `{ftype}` requires exactly {arity} parameter{}, but {} were given (`{}`).",
if arity == 1 { "" } else { "s" },
params.len(),
params.join(",")
))),
"type: `{ftype}` requires exactly {arity} parameter{}, but {} \
were given (`{}`).",
if arity == 1 { "" } else { "s" },
params.len(),
params.join(",")
))),
}?;

format!(
Expand Down
7 changes: 4 additions & 3 deletions loco-gen/src/tera_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ pub fn new() -> Tera {
tera
}

const DEFAULT_INPUT_CLASS: &str = "flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm md:text-sm";
const DEFAULT_INPUT_CLASS: &str = "flex h-9 w-full rounded-md border border-input bg-transparent \
px-3 py-1 text-base shadow-sm md:text-sm";
struct FormField;

impl tera::Function for FormField {
Expand Down Expand Up @@ -322,10 +323,10 @@ fn input_description<S: AsRef<str>>(description: S) -> String {

#[cfg(test)]
pub mod tests {
use super::*;
use insta::assert_snapshot;

use super::*;
use crate::get_mappings;
use insta::assert_snapshot;

#[test]
fn can_render_form_field() {
Expand Down
3 changes: 2 additions & 1 deletion loco-gen/tests/db.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::{collections::HashMap, env::current_dir, fs::read_to_string};

use duct::cmd;
use insta::assert_snapshot;
use loco_gen::get_mappings;
use rstest::rstest;
use serial_test::serial;
use std::{collections::HashMap, env::current_dir, fs::read_to_string};

#[rstest]
#[serial]
Expand Down
14 changes: 7 additions & 7 deletions loco-gen/tests/templates/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn can_generate_docker(
app_name: "tester".to_string(),
},
)
.expect("Generation failed");
.expect("Generation failed");

assert_eq!(
collect_messages(&gen_result),
Expand Down Expand Up @@ -93,7 +93,7 @@ fn can_generate_nginx() {
app_name: "tester".to_string(),
},
)
.expect("Generation failed");
.expect("Generation failed");

assert_eq!(
collect_messages(&gen_result),
Expand Down Expand Up @@ -151,7 +151,7 @@ playground = "run --example playground"
app_name: "tester".to_string(),
},
)
.expect("Generation failed");
.expect("Generation failed");

assert_eq!(
collect_messages(&gen_result),
Expand Down Expand Up @@ -210,7 +210,7 @@ fn can_generate_kamal_sqlite_without_background_queue() {
app_name: "tester".to_string(),
},
)
.expect("Generation failed");
.expect("Generation failed");

assert_eq!(
collect_messages(&gen_result),
Expand Down Expand Up @@ -290,7 +290,7 @@ fn can_generate_kamal_sqlite_with_background_queue() {
app_name: "tester".to_string(),
},
)
.expect("Generation failed");
.expect("Generation failed");

assert_eq!(
collect_messages(&gen_result),
Expand Down Expand Up @@ -368,7 +368,7 @@ fn can_generate_kamal_postgres_without_background_queue() {
app_name: "tester".to_string(),
},
)
.expect("Generation failed");
.expect("Generation failed");

assert_eq!(
collect_messages(&gen_result),
Expand Down Expand Up @@ -446,7 +446,7 @@ fn can_generate_kamal_postgres_with_background_queue() {
app_name: "tester".to_string(),
},
)
.expect("Generation failed");
.expect("Generation failed");

assert_eq!(
collect_messages(&gen_result),
Expand Down
3 changes: 2 additions & 1 deletion src/controller/views/engines.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::path::{Path, PathBuf};

use serde::Serialize;

use super::tera_builtins;
use crate::{controller::views::ViewRenderer, Error, Result};
use serde::Serialize;

pub static DEFAULT_ASSET_FOLDER: &str = "assets";

Expand Down
9 changes: 6 additions & 3 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ pub enum ColType {
Unsigned,
UnsignedNull,
UnsignedUniq,
// Tiny fields are not supported due to differences in data types between PostgreSQL and SQLite:
// Tiny fields are not supported due to differences in data types between PostgreSQL and
// SQLite:
// * Postgres: i16
// * Sqlite: i8
// TinyUnsigned,
Expand All @@ -94,7 +95,8 @@ pub enum ColType {
BigUnsigned,
BigUnsignedNull,
BigUnsignedUniq,
// Tiny fields are not supported due to differences in data types between PostgreSQL and SQLite:
// Tiny fields are not supported due to differences in data types between PostgreSQL and
// SQLite:
// * Postgres: i16
// * Sqlite: i8
// TinyInteger,
Expand All @@ -120,7 +122,8 @@ pub enum ColType {
DoubleUniq,
Boolean,
BooleanNull,
// Timestamp fields are not supported due to differences in data types between PostgreSQL and SQLite:
// Timestamp fields are not supported due to differences in data types between PostgreSQL and
// SQLite:
// * Postgres: DateTime
// * Sqlite: DateTimeUtc
// Timestamp,
Expand Down

0 comments on commit f87081d

Please sign in to comment.