From c09fde4e5b003f26fe0893154115ff32420458dd Mon Sep 17 00:00:00 2001 From: Jonas Cirotzki Date: Sun, 5 Jan 2025 15:36:53 +0100 Subject: [PATCH 01/19] refactor: rename asset tests to rendering_method tests --- loco-new/tests/templates/mod.rs | 3 ++- loco-new/tests/templates/{asset.rs => rendering_method.rs} | 0 ...ates__rendering_method__cargo_dependencies_Clientside.snap} | 0 ..._templates__rendering_method__cargo_dependencies_None.snap} | 0 ...ates__rendering_method__cargo_dependencies_Serverside.snap} | 0 5 files changed, 2 insertions(+), 1 deletion(-) rename loco-new/tests/templates/{asset.rs => rendering_method.rs} (100%) rename loco-new/tests/templates/snapshots/{r#mod__templates__asset__cargo_dependencies_Clientside.snap => r#mod__templates__rendering_method__cargo_dependencies_Clientside.snap} (100%) rename loco-new/tests/templates/snapshots/{r#mod__templates__asset__cargo_dependencies_None.snap => r#mod__templates__rendering_method__cargo_dependencies_None.snap} (100%) rename loco-new/tests/templates/snapshots/{r#mod__templates__asset__cargo_dependencies_Serverside.snap => r#mod__templates__rendering_method__cargo_dependencies_Serverside.snap} (100%) diff --git a/loco-new/tests/templates/mod.rs b/loco-new/tests/templates/mod.rs index d2c6f9af6..4644a292f 100644 --- a/loco-new/tests/templates/mod.rs +++ b/loco-new/tests/templates/mod.rs @@ -9,7 +9,7 @@ use loco::{ }; use rand::{rngs::StdRng, SeedableRng}; -mod asset; + mod auth; mod background; mod db; @@ -17,6 +17,7 @@ mod features; mod initializers; mod mailer; mod module_name; +mod rendering_method; pub struct TestGenerator { tree: tree_fs::Tree, diff --git a/loco-new/tests/templates/asset.rs b/loco-new/tests/templates/rendering_method.rs similarity index 100% rename from loco-new/tests/templates/asset.rs rename to loco-new/tests/templates/rendering_method.rs diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__asset__cargo_dependencies_Clientside.snap b/loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_Clientside.snap similarity index 100% rename from loco-new/tests/templates/snapshots/r#mod__templates__asset__cargo_dependencies_Clientside.snap rename to loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_Clientside.snap diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__asset__cargo_dependencies_None.snap b/loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_None.snap similarity index 100% rename from loco-new/tests/templates/snapshots/r#mod__templates__asset__cargo_dependencies_None.snap rename to loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_None.snap diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__asset__cargo_dependencies_Serverside.snap b/loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_Serverside.snap similarity index 100% rename from loco-new/tests/templates/snapshots/r#mod__templates__asset__cargo_dependencies_Serverside.snap rename to loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_Serverside.snap From 341b69f77e033f719cb204f5d2c708056130ba3a Mon Sep 17 00:00:00 2001 From: Jonas Cirotzki Date: Sun, 5 Jan 2025 16:04:42 +0100 Subject: [PATCH 02/19] refactor: rename AssetsOption to RenderingMethodOption --- loco-new/src/bin/main.rs | 2 +- loco-new/src/settings.rs | 10 ++++---- loco-new/src/wizard.rs | 24 ++++++++++---------- loco-new/tests/templates/rendering_method.rs | 22 +++++++++--------- loco-new/tests/wizard/new.rs | 16 ++++++------- 5 files changed, 37 insertions(+), 37 deletions(-) diff --git a/loco-new/src/bin/main.rs b/loco-new/src/bin/main.rs index c9329ac65..5cdcf5152 100644 --- a/loco-new/src/bin/main.rs +++ b/loco-new/src/bin/main.rs @@ -49,7 +49,7 @@ enum Commands { /// Assets serving configuration #[arg(long)] - assets: Option, + assets: Option, /// Create the starter in target git repository #[arg(short, long)] diff --git a/loco-new/src/settings.rs b/loco-new/src/settings.rs index b142b09be..8fa05bbdf 100644 --- a/loco-new/src/settings.rs +++ b/loco-new/src/settings.rs @@ -7,7 +7,7 @@ use rhai::{CustomType, TypeBuilder}; use serde::{Deserialize, Serialize}; use crate::{ - wizard::{self, AssetsOption, BackgroundOption, DBOption}, + wizard::{self, RenderingMethodOption, BackgroundOption, DBOption}, LOCO_VERSION, OS, }; @@ -49,10 +49,10 @@ impl From for Option { } } -impl From for Option { - fn from(asset: AssetsOption) -> Self { +impl From for Option { + fn from(asset: RenderingMethodOption) -> Self { match asset { - AssetsOption::None => None, + RenderingMethodOption::None => None, _ => Some(Asset { kind: asset }), } } @@ -138,7 +138,7 @@ pub struct Background { /// Asset configuration settings. #[derive(Serialize, Deserialize, Clone, Debug, Default, CustomType)] pub struct Asset { - pub kind: AssetsOption, + pub kind: RenderingMethodOption, } #[derive(Serialize, Deserialize, Clone, Debug, Default, CustomType)] diff --git a/loco-new/src/wizard.rs b/loco-new/src/wizard.rs index 16ba8c699..bbb50e7ac 100644 --- a/loco-new/src/wizard.rs +++ b/loco-new/src/wizard.rs @@ -136,12 +136,12 @@ impl BackgroundOption { #[derive( Debug, Clone, Deserialize, Serialize, EnumIter, Display, Default, PartialEq, Eq, ValueEnum, )] -pub enum AssetsOption { +pub enum RenderingMethodOption { #[default] - #[strum(to_string = "Server (configures server-rendered views)")] + #[strum(to_string = "Server (configures server-side rendering)")] #[serde(rename = "server")] Serverside, - #[strum(to_string = "Client (configures assets for frontend serving)")] + #[strum(to_string = "Client (configures client-side rendering)")] #[serde(rename = "client")] Clientside, #[strum(to_string = "None")] @@ -149,7 +149,7 @@ pub enum AssetsOption { None, } -impl AssetsOption { +impl RenderingMethodOption { #[must_use] pub const fn enable(&self) -> bool { !matches!(self, Self::None) @@ -175,14 +175,14 @@ impl AssetsOption { pub struct ArgsPlaceholder { pub db: Option, pub bg: Option, - pub assets: Option, + pub assets: Option, } /// Holds the user's configuration selections. pub struct Selections { pub db: DBOption, pub background: BackgroundOption, - pub asset: AssetsOption, + pub asset: RenderingMethodOption, } impl Selections { @@ -314,22 +314,22 @@ pub fn start(args: &ArgsPlaceholder) -> crate::Result { Template::Lightweight => Ok(Selections { db: DBOption::None, background: BackgroundOption::None, - asset: AssetsOption::None, + asset: RenderingMethodOption::None, }), Template::RestApi => Ok(Selections { db: select_db(args)?, background: select_background(args, None)?, - asset: AssetsOption::None, + asset: RenderingMethodOption::None, }), Template::SaasServerSideRendering => Ok(Selections { db: select_db(args)?, background: select_background(args, None)?, - asset: AssetsOption::Serverside, + asset: RenderingMethodOption::Serverside, }), Template::SaasClientSideRendering => Ok(Selections { db: select_db(args)?, background: select_background(args, None)?, - asset: AssetsOption::Clientside, + asset: RenderingMethodOption::Clientside, }), Template::Advanced => { let db = select_db(args)?; @@ -380,13 +380,13 @@ fn select_background( /// Prompts the user to select an asset configuration if none is provided in the /// arguments. -fn select_asset(args: &ArgsPlaceholder) -> crate::Result { +fn select_asset(args: &ArgsPlaceholder) -> crate::Result { let assetopt = if let Some(assetopt) = args.assets.clone() { assetopt } else { select_option( "❯ Select an asset serving configuration", - &AssetsOption::iter().collect::>(), + &RenderingMethodOption::iter().collect::>(), )? }; Ok(assetopt) diff --git a/loco-new/tests/templates/rendering_method.rs b/loco-new/tests/templates/rendering_method.rs index 2c248fa4d..ec886754f 100644 --- a/loco-new/tests/templates/rendering_method.rs +++ b/loco-new/tests/templates/rendering_method.rs @@ -1,10 +1,10 @@ -use loco::{settings, wizard::AssetsOption}; +use loco::{settings, wizard::RenderingMethodOption}; use rstest::rstest; use super::*; use crate::assertion; -pub fn run_generator(asset: AssetsOption) -> TestGenerator { +pub fn run_generator(asset: RenderingMethodOption) -> TestGenerator { let settings = settings::Settings { asset: asset.into(), ..Default::default() @@ -17,7 +17,7 @@ pub fn run_generator(asset: AssetsOption) -> TestGenerator { fn test_config_file_middleware_when_asset_empty( #[values("config/development.yaml", "config/test.yaml")] config_file: &str, ) { - let generator: TestGenerator = run_generator(AssetsOption::None); + let generator: TestGenerator = run_generator(RenderingMethodOption::None); let content = assertion::yaml::load(generator.path(config_file)); assertion::yaml::assert_path_is_empty(&content, &["server", "middlewares"]); @@ -27,7 +27,7 @@ fn test_config_file_middleware_when_asset_empty( fn test_config_file_middleware_asset_server( #[values("config/development.yaml", "config/test.yaml")] config_file: &str, ) { - let generator: TestGenerator = run_generator(AssetsOption::Serverside); + let generator: TestGenerator = run_generator(RenderingMethodOption::Serverside); let content = assertion::yaml::load(generator.path(config_file)); assertion::yaml::assert_path_is_object(&content, &["server", "middlewares", "static"]); @@ -55,7 +55,7 @@ fallback: assets/static/404.html fn test_config_file_middleware_asset_client( #[values("config/development.yaml", "config/test.yaml")] config_file: &str, ) { - let generator: TestGenerator = run_generator(AssetsOption::Clientside); + let generator: TestGenerator = run_generator(RenderingMethodOption::Clientside); let content = assertion::yaml::load(generator.path(config_file)); assertion::yaml::assert_path_is_object(&content, &["server", "middlewares"]); @@ -80,8 +80,8 @@ static: #[rstest] fn test_cargo_toml( - #[values(AssetsOption::None, AssetsOption::Serverside, AssetsOption::Clientside)] - asset: AssetsOption, + #[values(RenderingMethodOption::None, RenderingMethodOption::Serverside, RenderingMethodOption::Clientside)] + asset: RenderingMethodOption, ) { let generator = run_generator(asset.clone()); let content = assertion::toml::load(generator.path("Cargo.toml")); @@ -94,8 +94,8 @@ fn test_cargo_toml( #[rstest] fn test_github_ci_yaml( - #[values(AssetsOption::None, AssetsOption::Serverside, AssetsOption::Clientside)] - asset: AssetsOption, + #[values(RenderingMethodOption::None, RenderingMethodOption::Serverside, RenderingMethodOption::Clientside)] + asset: RenderingMethodOption, ) { let generator: TestGenerator = run_generator(asset.clone()); let content = @@ -112,10 +112,10 @@ fn test_github_ci_yaml( uses: Swatinem/rust-cache@v2"; match asset { - AssetsOption::Serverside | AssetsOption::None => { + RenderingMethodOption::Serverside | RenderingMethodOption::None => { assertion::string::assert_not_contains(&content, frontend_section); } - AssetsOption::Clientside => { + RenderingMethodOption::Clientside => { assertion::string::assert_contains(&content, frontend_section); } } diff --git a/loco-new/tests/wizard/new.rs b/loco-new/tests/wizard/new.rs index c0f5dda23..1b19121e0 100644 --- a/loco-new/tests/wizard/new.rs +++ b/loco-new/tests/wizard/new.rs @@ -2,7 +2,7 @@ use duct::cmd; use loco::{ generator::{executer::FileSystem, Generator}, settings, - wizard::{self, AssetsOption, BackgroundOption, DBOption}, + wizard::{self, RenderingMethodOption, BackgroundOption, DBOption}, OS, }; use std::{collections::HashMap, path::PathBuf, process::Output, sync::Arc}; @@ -19,7 +19,7 @@ fn test_all_combinations( )] background: BackgroundOption, #[values(AssetsOption::Serverside, AssetsOption::Clientside, AssetsOption::None)] - asset: AssetsOption, + asset: RenderingMethodOption, ) { test_combination(db, background, asset, false); } @@ -31,35 +31,35 @@ fn test_starter_combinations() { test_combination( DBOption::None, BackgroundOption::None, - AssetsOption::None, + RenderingMethodOption::None, true, ); // REST API test_combination( DBOption::Sqlite, BackgroundOption::Async, - AssetsOption::None, + RenderingMethodOption::None, true, ); // SaaS, serverside test_combination( DBOption::Sqlite, BackgroundOption::Async, - AssetsOption::Serverside, + RenderingMethodOption::Serverside, true, ); // SaaS, clientside test_combination( DBOption::Sqlite, BackgroundOption::Async, - AssetsOption::Clientside, + RenderingMethodOption::Clientside, true, ); // test only DB test_combination( DBOption::Sqlite, BackgroundOption::None, - AssetsOption::None, + RenderingMethodOption::None, true, ); } @@ -67,7 +67,7 @@ fn test_starter_combinations() { fn test_combination( db: DBOption, background: BackgroundOption, - asset: AssetsOption, + asset: RenderingMethodOption, test_generator: bool, ) { let test_dir = tree_fs::TreeBuilder::default().drop(true); From be1596062f36570855b1b7869460a5f46d3ca276 Mon Sep 17 00:00:00 2001 From: Jonas Cirotzki Date: Sun, 5 Jan 2025 15:49:55 +0100 Subject: [PATCH 03/19] refactor: rename rendering_method template tests from asset to rendering_method --- loco-new/tests/templates/rendering_method.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/loco-new/tests/templates/rendering_method.rs b/loco-new/tests/templates/rendering_method.rs index ec886754f..0c163a1e5 100644 --- a/loco-new/tests/templates/rendering_method.rs +++ b/loco-new/tests/templates/rendering_method.rs @@ -14,7 +14,7 @@ pub fn run_generator(asset: RenderingMethodOption) -> TestGenerator { } #[rstest] -fn test_config_file_middleware_when_asset_empty( +fn test_config_file_middleware_when_rendering_method_empty( #[values("config/development.yaml", "config/test.yaml")] config_file: &str, ) { let generator: TestGenerator = run_generator(RenderingMethodOption::None); @@ -24,7 +24,7 @@ fn test_config_file_middleware_when_asset_empty( } #[rstest] -fn test_config_file_middleware_asset_server( +fn test_config_file_middleware_when_rendering_method_server_side( #[values("config/development.yaml", "config/test.yaml")] config_file: &str, ) { let generator: TestGenerator = run_generator(RenderingMethodOption::Serverside); @@ -52,7 +52,7 @@ fallback: assets/static/404.html } #[rstest] -fn test_config_file_middleware_asset_client( +fn test_config_file_middleware_when_rendering_method_client_side( #[values("config/development.yaml", "config/test.yaml")] config_file: &str, ) { let generator: TestGenerator = run_generator(RenderingMethodOption::Clientside); From 4908dff5aea5b222981d59e8c2055413627569ad Mon Sep 17 00:00:00 2001 From: Jonas Cirotzki Date: Sun, 5 Jan 2025 15:54:19 +0100 Subject: [PATCH 04/19] refactor: rename remaining occurences of assets vars to rendering_method in template tests --- loco-new/tests/templates/rendering_method.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/loco-new/tests/templates/rendering_method.rs b/loco-new/tests/templates/rendering_method.rs index 0c163a1e5..3454b8f36 100644 --- a/loco-new/tests/templates/rendering_method.rs +++ b/loco-new/tests/templates/rendering_method.rs @@ -4,9 +4,9 @@ use rstest::rstest; use super::*; use crate::assertion; -pub fn run_generator(asset: RenderingMethodOption) -> TestGenerator { +pub fn run_generator(rendering_method: RenderingMethodOption) -> TestGenerator { let settings = settings::Settings { - asset: asset.into(), + asset: rendering_method.into(), ..Default::default() }; @@ -81,13 +81,13 @@ static: #[rstest] fn test_cargo_toml( #[values(RenderingMethodOption::None, RenderingMethodOption::Serverside, RenderingMethodOption::Clientside)] - asset: RenderingMethodOption, + rendering_method: RenderingMethodOption, ) { - let generator = run_generator(asset.clone()); + let generator = run_generator(rendering_method.clone()); let content = assertion::toml::load(generator.path("Cargo.toml")); insta::assert_snapshot!( - format!("cargo_dependencies_{:?}", asset), + format!("cargo_dependencies_{:?}", rendering_method), content.get("dependencies").unwrap() ); } @@ -95,9 +95,9 @@ fn test_cargo_toml( #[rstest] fn test_github_ci_yaml( #[values(RenderingMethodOption::None, RenderingMethodOption::Serverside, RenderingMethodOption::Clientside)] - asset: RenderingMethodOption, + rendering_method: RenderingMethodOption, ) { - let generator: TestGenerator = run_generator(asset.clone()); + let generator: TestGenerator = run_generator(rendering_method.clone()); let content = assertion::string::load(generator.path(".github").join("workflows").join("ci.yaml")); @@ -111,7 +111,7 @@ fn test_github_ci_yaml( - name: Setup Rust cache uses: Swatinem/rust-cache@v2"; - match asset { + match rendering_method { RenderingMethodOption::Serverside | RenderingMethodOption::None => { assertion::string::assert_not_contains(&content, frontend_section); } From 53ef8e77ff98447597bc6cb6e6ea7e306f62d925 Mon Sep 17 00:00:00 2001 From: Jonas Cirotzki Date: Sun, 5 Jan 2025 16:14:28 +0100 Subject: [PATCH 05/19] refactor: rename Asset to RenderingMethod --- loco-new/src/settings.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/loco-new/src/settings.rs b/loco-new/src/settings.rs index 8fa05bbdf..e8a5d40b0 100644 --- a/loco-new/src/settings.rs +++ b/loco-new/src/settings.rs @@ -18,7 +18,7 @@ pub struct Settings { pub module_name: String, pub db: Option, pub background: Option, - pub asset: Option, + pub asset: Option, pub auth: bool, pub mailer: bool, pub clientside: bool, @@ -49,11 +49,11 @@ impl From for Option { } } -impl From for Option { +impl From for Option { fn from(asset: RenderingMethodOption) -> Self { match asset { RenderingMethodOption::None => None, - _ => Some(Asset { kind: asset }), + _ => Some(RenderingMethod { kind: asset }), } } } @@ -135,9 +135,9 @@ pub struct Background { pub kind: BackgroundOption, } -/// Asset configuration settings. +/// Rendering method configuration. #[derive(Serialize, Deserialize, Clone, Debug, Default, CustomType)] -pub struct Asset { +pub struct RenderingMethod { pub kind: RenderingMethodOption, } From f0a81606ac58537411bebcd6afd1820310501468 Mon Sep 17 00:00:00 2001 From: Jonas Cirotzki Date: Sun, 5 Jan 2025 16:20:45 +0100 Subject: [PATCH 06/19] refactor: rename Selections.asset -> rendering_method --- loco-new/src/settings.rs | 6 +++--- loco-new/src/wizard.rs | 16 ++++++++-------- loco-new/tests/wizard/new.rs | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/loco-new/src/settings.rs b/loco-new/src/settings.rs index e8a5d40b0..f1556c12b 100644 --- a/loco-new/src/settings.rs +++ b/loco-new/src/settings.rs @@ -79,9 +79,9 @@ impl Settings { mailer: prompt_selection.db.enable() && prompt_selection.background.enable(), db: prompt_selection.db.clone().into(), background: prompt_selection.background.clone().into(), - asset: prompt_selection.asset.clone().into(), - clientside: prompt_selection.asset.enable(), - initializers: if prompt_selection.asset.enable() { + asset: prompt_selection.rendering_method.clone().into(), + clientside: prompt_selection.rendering_method.enable(), + initializers: if prompt_selection.rendering_method.enable() { Some(Initializers { view_engine: true }) } else { None diff --git a/loco-new/src/wizard.rs b/loco-new/src/wizard.rs index bbb50e7ac..fe4bac171 100644 --- a/loco-new/src/wizard.rs +++ b/loco-new/src/wizard.rs @@ -182,7 +182,7 @@ pub struct ArgsPlaceholder { pub struct Selections { pub db: DBOption, pub background: BackgroundOption, - pub asset: RenderingMethodOption, + pub rendering_method: RenderingMethodOption, } impl Selections { @@ -195,7 +195,7 @@ impl Selections { if let Some(m) = self.background.user_message() { res.push(m); } - if let Some(m) = self.asset.user_message() { + if let Some(m) = self.rendering_method.user_message() { res.push(m); } res @@ -301,7 +301,7 @@ pub fn start(args: &ArgsPlaceholder) -> crate::Result { return Ok(Selections { db, background: bg, - asset: assets, + rendering_method: assets, }); } @@ -314,22 +314,22 @@ pub fn start(args: &ArgsPlaceholder) -> crate::Result { Template::Lightweight => Ok(Selections { db: DBOption::None, background: BackgroundOption::None, - asset: RenderingMethodOption::None, + rendering_method: RenderingMethodOption::None, }), Template::RestApi => Ok(Selections { db: select_db(args)?, background: select_background(args, None)?, - asset: RenderingMethodOption::None, + rendering_method: RenderingMethodOption::None, }), Template::SaasServerSideRendering => Ok(Selections { db: select_db(args)?, background: select_background(args, None)?, - asset: RenderingMethodOption::Serverside, + rendering_method: RenderingMethodOption::Serverside, }), Template::SaasClientSideRendering => Ok(Selections { db: select_db(args)?, background: select_background(args, None)?, - asset: RenderingMethodOption::Clientside, + rendering_method: RenderingMethodOption::Clientside, }), Template::Advanced => { let db = select_db(args)?; @@ -340,7 +340,7 @@ pub fn start(args: &ArgsPlaceholder) -> crate::Result { Ok(Selections { db, background: select_background(args, background_options.as_ref())?, - asset: select_asset(args)?, + rendering_method: select_asset(args)?, }) } } diff --git a/loco-new/tests/wizard/new.rs b/loco-new/tests/wizard/new.rs index 1b19121e0..e624ae58b 100644 --- a/loco-new/tests/wizard/new.rs +++ b/loco-new/tests/wizard/new.rs @@ -77,7 +77,7 @@ fn test_combination( let wizard_selection = wizard::Selections { db: db.clone(), background: background.clone(), - asset, + rendering_method: asset, }; let settings = settings::Settings::from_wizard("test-loco-template", &wizard_selection, OS::default()); From 8c4d874995fbcb9fe8bab5190d95aa03c42285aa Mon Sep 17 00:00:00 2001 From: Jonas Cirotzki Date: Sun, 5 Jan 2025 16:21:46 +0100 Subject: [PATCH 07/19] refactor: rename ArgsPlaceholder.asset -> rendering_method --- loco-new/src/bin/main.rs | 2 +- loco-new/src/wizard.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/loco-new/src/bin/main.rs b/loco-new/src/bin/main.rs index 5cdcf5152..e89243f4d 100644 --- a/loco-new/src/bin/main.rs +++ b/loco-new/src/bin/main.rs @@ -106,7 +106,7 @@ fn main() -> Result<()> { tracing::debug!(dir = %to.display(), "creating application directory"); std::fs::create_dir_all(&to)?; - let args = wizard::ArgsPlaceholder { db, bg, assets }; + let args = wizard::ArgsPlaceholder { db, bg, rendering_method: assets }; let user_selection = wizard::start(&args)?; let generator_tmp_folder = extract_default_template()?; diff --git a/loco-new/src/wizard.rs b/loco-new/src/wizard.rs index fe4bac171..a98b02bdb 100644 --- a/loco-new/src/wizard.rs +++ b/loco-new/src/wizard.rs @@ -175,7 +175,7 @@ impl RenderingMethodOption { pub struct ArgsPlaceholder { pub db: Option, pub bg: Option, - pub assets: Option, + pub rendering_method: Option, } /// Holds the user's configuration selections. @@ -296,7 +296,7 @@ where pub fn start(args: &ArgsPlaceholder) -> crate::Result { // user provided everything via flags so no need to prompt, just return if let (Some(db), Some(bg), Some(assets)) = - (args.db.clone(), args.bg.clone(), args.assets.clone()) + (args.db.clone(), args.bg.clone(), args.rendering_method.clone()) { return Ok(Selections { db, @@ -381,7 +381,7 @@ fn select_background( /// Prompts the user to select an asset configuration if none is provided in the /// arguments. fn select_asset(args: &ArgsPlaceholder) -> crate::Result { - let assetopt = if let Some(assetopt) = args.assets.clone() { + let assetopt = if let Some(assetopt) = args.rendering_method.clone() { assetopt } else { select_option( From 7dce0879af09d4eab06e841a461ae3832c33a831 Mon Sep 17 00:00:00 2001 From: Jonas Cirotzki Date: Sun, 5 Jan 2025 16:36:49 +0100 Subject: [PATCH 08/19] refactor: rename Settings.asset -> rendering_method. Adjust templating as needed. # Conflicts: # loco-new/base_template/config/development.yaml.t # loco-new/base_template/config/test.yaml.t --- loco-new/base_template/.github/workflows/ci.yaml.t | 4 ++-- loco-new/base_template/Cargo.toml.t | 2 +- loco-new/base_template/config/development.yaml.t | 6 +++--- loco-new/base_template/config/test.yaml.t | 7 +++---- loco-new/src/generator/mod.rs | 2 +- loco-new/src/settings.rs | 6 +++--- loco-new/tests/templates/rendering_method.rs | 2 +- 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/loco-new/base_template/.github/workflows/ci.yaml.t b/loco-new/base_template/.github/workflows/ci.yaml.t index cd2cd9fe3..ec3b568f3 100644 --- a/loco-new/base_template/.github/workflows/ci.yaml.t +++ b/loco-new/base_template/.github/workflows/ci.yaml.t @@ -90,8 +90,8 @@ jobs: with: toolchain: ${% raw %}{{ env.RUST_TOOLCHAIN }}{% endraw %} - {%- if settings.asset %} - {%- if settings.asset.kind == "client" %} + {%- if settings.rendering_method %} + {%- if settings.rendering_method.kind == "client" %} - name: Setup node uses: actions/setup-node@v4 with: diff --git a/loco-new/base_template/Cargo.toml.t b/loco-new/base_template/Cargo.toml.t index 4c1044c9a..0d813b243 100644 --- a/loco-new/base_template/Cargo.toml.t +++ b/loco-new/base_template/Cargo.toml.t @@ -47,7 +47,7 @@ uuid = { version = "1.6.0", features = ["v4"] } include_dir = { version = "0.7" } {%- endif %} -{%- if settings.asset %} +{%- if settings.rendering_method %} # view engine i18n fluent-templates = { version = "0.8.0", features = ["tera"] } unic-langid = { version = "0.9.4" } diff --git a/loco-new/base_template/config/development.yaml.t b/loco-new/base_template/config/development.yaml.t index fbd215dea..31324c2fc 100644 --- a/loco-new/base_template/config/development.yaml.t +++ b/loco-new/base_template/config/development.yaml.t @@ -24,8 +24,8 @@ server: host: http://localhost # Out of the box middleware configuration. to disable middleware you can changed the `enable` field to `false` of comment the middleware block middlewares: - {%- if settings.asset %} - {%- if settings.asset.kind == "server" %} + {%- if settings.rendering_method %} + {%- if settings.rendering_method.kind == "server" %} static: enable: true must_exist: true @@ -34,7 +34,7 @@ server: uri: "/static" path: "assets/static" fallback: "assets/static/404.html" - {%- elif settings.asset.kind == "client" %} + {%- elif settings.rendering_method.kind == "client" %} fallback: enable: false static: diff --git a/loco-new/base_template/config/test.yaml.t b/loco-new/base_template/config/test.yaml.t index f9cbb7a9d..8d6213fd4 100644 --- a/loco-new/base_template/config/test.yaml.t +++ b/loco-new/base_template/config/test.yaml.t @@ -22,8 +22,8 @@ server: host: http://localhost # Out of the box middleware configuration. to disable middleware you can changed the `enable` field to `false` of comment the middleware block middlewares: - {%- if settings.asset %} - {%- if settings.asset.kind == "server" %} + {%- if settings.rendering_method %} + {%- if settings.rendering_method.kind == "server" %} static: enable: true must_exist: true @@ -32,8 +32,7 @@ server: uri: "/static" path: "assets/static" fallback: "assets/static/404.html" - {%- elif settings.asset.kind == "client" %} - fallback: + {%- elif settings.rendering_method.kind == "client" %}fallback: enable: false static: enable: true diff --git a/loco-new/src/generator/mod.rs b/loco-new/src/generator/mod.rs index a477ab1b6..7ea31e680 100644 --- a/loco-new/src/generator/mod.rs +++ b/loco-new/src/generator/mod.rs @@ -86,7 +86,7 @@ impl Generator { scope.push("db", self.settings.db.is_some()); scope.push("background", self.settings.background.is_some()); scope.push("initializers", self.settings.initializers.is_some()); - scope.push("asset", self.settings.asset.is_some()); + scope.push("asset", self.settings.rendering_method.is_some()); scope.push("windows", self.settings.os == OS::Windows); engine.run_with_scope(&mut scope, script)?; diff --git a/loco-new/src/settings.rs b/loco-new/src/settings.rs index f1556c12b..a85411ac4 100644 --- a/loco-new/src/settings.rs +++ b/loco-new/src/settings.rs @@ -18,7 +18,7 @@ pub struct Settings { pub module_name: String, pub db: Option, pub background: Option, - pub asset: Option, + pub rendering_method: Option, pub auth: bool, pub mailer: bool, pub clientside: bool, @@ -79,7 +79,7 @@ impl Settings { mailer: prompt_selection.db.enable() && prompt_selection.background.enable(), db: prompt_selection.db.clone().into(), background: prompt_selection.background.clone().into(), - asset: prompt_selection.rendering_method.clone().into(), + rendering_method: prompt_selection.rendering_method.clone().into(), clientside: prompt_selection.rendering_method.enable(), initializers: if prompt_selection.rendering_method.enable() { Some(Initializers { view_engine: true }) @@ -100,7 +100,7 @@ impl Default for Settings { module_name: Default::default(), db: Default::default(), background: Default::default(), - asset: Default::default(), + rendering_method: Default::default(), auth: Default::default(), mailer: Default::default(), clientside: Default::default(), diff --git a/loco-new/tests/templates/rendering_method.rs b/loco-new/tests/templates/rendering_method.rs index 3454b8f36..375cfd9a2 100644 --- a/loco-new/tests/templates/rendering_method.rs +++ b/loco-new/tests/templates/rendering_method.rs @@ -6,7 +6,7 @@ use crate::assertion; pub fn run_generator(rendering_method: RenderingMethodOption) -> TestGenerator { let settings = settings::Settings { - asset: rendering_method.into(), + rendering_method: rendering_method.into(), ..Default::default() }; From 9d9e7d4020a80a68ae0ec51dcbe89060b6b926e0 Mon Sep 17 00:00:00 2001 From: Jonas Cirotzki Date: Sun, 5 Jan 2025 16:39:47 +0100 Subject: [PATCH 09/19] refactor: rename asset scope var to rendering_method --- loco-new/setup.rhai | 2 +- loco-new/src/generator/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/loco-new/setup.rhai b/loco-new/setup.rhai index 7622b222d..43a5148c2 100644 --- a/loco-new/setup.rhai +++ b/loco-new/setup.rhai @@ -125,7 +125,7 @@ if background { // ===================== // Adds asset directory if assets are configured in the app. -if asset { +if rendering_method { gen.copy_dir("assets"); // Static assets directory } diff --git a/loco-new/src/generator/mod.rs b/loco-new/src/generator/mod.rs index 7ea31e680..c6367b019 100644 --- a/loco-new/src/generator/mod.rs +++ b/loco-new/src/generator/mod.rs @@ -86,7 +86,7 @@ impl Generator { scope.push("db", self.settings.db.is_some()); scope.push("background", self.settings.background.is_some()); scope.push("initializers", self.settings.initializers.is_some()); - scope.push("asset", self.settings.rendering_method.is_some()); + scope.push("rendering_method", self.settings.rendering_method.is_some()); scope.push("windows", self.settings.os == OS::Windows); engine.run_with_scope(&mut scope, script)?; From 2b16fba9e97879e40611b2652840b436bfbe5812 Mon Sep 17 00:00:00 2001 From: Jonas Cirotzki Date: Sun, 5 Jan 2025 16:50:45 +0100 Subject: [PATCH 10/19] refactor: rename the remaing asset occurences --- loco-new/src/settings.rs | 6 +++--- loco-new/src/wizard.rs | 35 ++++++++++++++++++----------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/loco-new/src/settings.rs b/loco-new/src/settings.rs index a85411ac4..da1d7f96a 100644 --- a/loco-new/src/settings.rs +++ b/loco-new/src/settings.rs @@ -50,10 +50,10 @@ impl From for Option { } impl From for Option { - fn from(asset: RenderingMethodOption) -> Self { - match asset { + fn from(rendering_method: RenderingMethodOption) -> Self { + match rendering_method { RenderingMethodOption::None => None, - _ => Some(RenderingMethod { kind: asset }), + _ => Some(RenderingMethod { kind: rendering_method }), } } } diff --git a/loco-new/src/wizard.rs b/loco-new/src/wizard.rs index a98b02bdb..f40deec4d 100644 --- a/loco-new/src/wizard.rs +++ b/loco-new/src/wizard.rs @@ -14,9 +14,9 @@ use crate::Error; )] pub enum Template { #[default] - #[strum(to_string = "Saas App with server side rendering")] + #[strum(to_string = "Saas App with server-side rendering")] SaasServerSideRendering, - #[strum(to_string = "Saas App with client side rendering")] + #[strum(to_string = "Saas App with client-side rendering")] SaasClientSideRendering, #[strum(to_string = "Rest API (with DB and user auth)")] RestApi, @@ -32,8 +32,8 @@ pub enum OptionsList { DB, #[serde(rename = "bg")] Background, - #[serde(rename = "assets")] - Assets, + #[serde(rename = "rendering_method")] + RenderingMethod, } #[derive( @@ -159,10 +159,11 @@ impl RenderingMethodOption { pub fn user_message(&self) -> Option { match self { Self::Clientside => Some(format!( - "{}: You've selected `{}` for your asset serving configuration.\n\nNext step, \ - build your frontend:\n $ cd {}\n $ npm install && npm run build\n", - "assets".underline(), - "clientside".yellow(), + "{}: You've selected `{}` as your frontend rendering method.\n\n\ + To build your frontend, please run the following commands:\n\ + $ cd {}\n $ npm install && npm run build\n", + "Rendering method".underline(), + "client-side rendering".yellow(), "frontend/".yellow() )), Self::Serverside | Self::None => None, @@ -295,13 +296,13 @@ where /// when could not show user selection or user chose not continue pub fn start(args: &ArgsPlaceholder) -> crate::Result { // user provided everything via flags so no need to prompt, just return - if let (Some(db), Some(bg), Some(assets)) = + if let (Some(db), Some(bg), Some(rendering_method)) = (args.db.clone(), args.bg.clone(), args.rendering_method.clone()) { return Ok(Selections { db, background: bg, - rendering_method: assets, + rendering_method, }); } @@ -340,7 +341,7 @@ pub fn start(args: &ArgsPlaceholder) -> crate::Result { Ok(Selections { db, background: select_background(args, background_options.as_ref())?, - rendering_method: select_asset(args)?, + rendering_method: select_rendering_method(args)?, }) } } @@ -378,16 +379,16 @@ fn select_background( Ok(bgopt) } -/// Prompts the user to select an asset configuration if none is provided in the +/// Prompts the user to select frontend rendering method if none is provided in the /// arguments. -fn select_asset(args: &ArgsPlaceholder) -> crate::Result { - let assetopt = if let Some(assetopt) = args.rendering_method.clone() { - assetopt +fn select_rendering_method(args: &ArgsPlaceholder) -> crate::Result { + let rendering_method_opt = if let Some(rendering_method_opt) = args.rendering_method.clone() { + rendering_method_opt } else { select_option( - "❯ Select an asset serving configuration", + "❯ Select a frontend rendering method", &RenderingMethodOption::iter().collect::>(), )? }; - Ok(assetopt) + Ok(rendering_method_opt) } From 586d4cd7e11ebcac5984f1f03497a23db69925dc Mon Sep 17 00:00:00 2001 From: Jonas Cirotzki Date: Sun, 5 Jan 2025 16:57:31 +0100 Subject: [PATCH 11/19] refactor: rename the remaing asset occurences in main.rs --- loco-new/src/bin/main.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/loco-new/src/bin/main.rs b/loco-new/src/bin/main.rs index e89243f4d..dae3f7788 100644 --- a/loco-new/src/bin/main.rs +++ b/loco-new/src/bin/main.rs @@ -47,9 +47,9 @@ enum Commands { #[arg(long)] bg: Option, - /// Assets serving configuration + /// Frontend rendering method configuration #[arg(long)] - assets: Option, + rendering_method: Option, /// Create the starter in target git repository #[arg(short, long)] @@ -82,12 +82,12 @@ fn main() -> Result<()> { path, db, bg, - assets, + rendering_method, name, allow_in_git_repo, os, } => { - tracing::debug!(path = ?path, db = ?db, bg=?bg, assets=?assets,name=?name, allow_in_git_repo=allow_in_git_repo, os=?os, "CLI options"); + tracing::debug!(path = ?path, db = ?db, bg=?bg, rendering_method=?rendering_method,name=?name, allow_in_git_repo=allow_in_git_repo, os=?os, "CLI options"); if !allow_in_git_repo && is_a_git_repo(path.as_path()).unwrap_or(false) { tracing::debug!("the target directory is a Git repository"); wizard::warn_if_in_git_repo()?; @@ -106,7 +106,7 @@ fn main() -> Result<()> { tracing::debug!(dir = %to.display(), "creating application directory"); std::fs::create_dir_all(&to)?; - let args = wizard::ArgsPlaceholder { db, bg, rendering_method: assets }; + let args = wizard::ArgsPlaceholder { db, bg, rendering_method }; let user_selection = wizard::start(&args)?; let generator_tmp_folder = extract_default_template()?; From 476ef5cd2dd8cf4fa393b01f80ed648c6113abc8 Mon Sep 17 00:00:00 2001 From: Jonas Cirotzki Date: Sun, 5 Jan 2025 17:04:03 +0100 Subject: [PATCH 12/19] refactor: rename the remaing asset occurences in tests --- ...endering_method__cargo_dependencies_Clientside.snap | 2 +- ...tes__rendering_method__cargo_dependencies_None.snap | 2 +- ...endering_method__cargo_dependencies_Serverside.snap | 2 +- loco-new/tests/wizard/new.rs | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_Clientside.snap b/loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_Clientside.snap index 0b77f22a9..8f046d841 100644 --- a/loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_Clientside.snap +++ b/loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_Clientside.snap @@ -1,5 +1,5 @@ --- -source: tests/templates/asset.rs +source: tests/templates/rendering_method.rs expression: "content.get(\"dependencies\").unwrap()" --- { async-trait = { version = "0.1.74" }, axum = { version = "0.8.1" }, fluent-templates = { features = ["tera"], version = "0.8.0" }, loco-rs = { workspace = true }, regex = { version = "1.11.1" }, serde = { features = ["derive"], version = "1" }, serde_json = { version = "1" }, tokio = { default-features = false, features = ["rt-multi-thread"], version = "1.33.0" }, tracing = { version = "0.1.40" }, tracing-subscriber = { features = ["env-filter", "json"], version = "0.3.17" }, unic-langid = { version = "0.9.4" } } diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_None.snap b/loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_None.snap index 2bc81b44c..4a7518008 100644 --- a/loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_None.snap +++ b/loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_None.snap @@ -1,5 +1,5 @@ --- -source: tests/templates/asset.rs +source: tests/templates/rendering_method.rs expression: "content.get(\"dependencies\").unwrap()" --- { async-trait = { version = "0.1.74" }, axum = { version = "0.8.1" }, loco-rs = { workspace = true }, regex = { version = "1.11.1" }, serde = { features = ["derive"], version = "1" }, serde_json = { version = "1" }, tokio = { default-features = false, features = ["rt-multi-thread"], version = "1.33.0" }, tracing = { version = "0.1.40" }, tracing-subscriber = { features = ["env-filter", "json"], version = "0.3.17" } } diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_Serverside.snap b/loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_Serverside.snap index 0b77f22a9..8f046d841 100644 --- a/loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_Serverside.snap +++ b/loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_Serverside.snap @@ -1,5 +1,5 @@ --- -source: tests/templates/asset.rs +source: tests/templates/rendering_method.rs expression: "content.get(\"dependencies\").unwrap()" --- { async-trait = { version = "0.1.74" }, axum = { version = "0.8.1" }, fluent-templates = { features = ["tera"], version = "0.8.0" }, loco-rs = { workspace = true }, regex = { version = "1.11.1" }, serde = { features = ["derive"], version = "1" }, serde_json = { version = "1" }, tokio = { default-features = false, features = ["rt-multi-thread"], version = "1.33.0" }, tracing = { version = "0.1.40" }, tracing-subscriber = { features = ["env-filter", "json"], version = "0.3.17" }, unic-langid = { version = "0.9.4" } } diff --git a/loco-new/tests/wizard/new.rs b/loco-new/tests/wizard/new.rs index e624ae58b..65640a564 100644 --- a/loco-new/tests/wizard/new.rs +++ b/loco-new/tests/wizard/new.rs @@ -18,10 +18,10 @@ fn test_all_combinations( BackgroundOption::None )] background: BackgroundOption, - #[values(AssetsOption::Serverside, AssetsOption::Clientside, AssetsOption::None)] - asset: RenderingMethodOption, + #[values(RenderingMethodOption::Serverside, RenderingMethodOption::Clientside, RenderingMethodOption::None)] + rendering_method: RenderingMethodOption, ) { - test_combination(db, background, asset, false); + test_combination(db, background, rendering_method, false); } // when running locally set LOCO_DEV_MODE_PATH= @@ -67,7 +67,7 @@ fn test_starter_combinations() { fn test_combination( db: DBOption, background: BackgroundOption, - asset: RenderingMethodOption, + rendering_method: RenderingMethodOption, test_generator: bool, ) { let test_dir = tree_fs::TreeBuilder::default().drop(true); @@ -77,7 +77,7 @@ fn test_combination( let wizard_selection = wizard::Selections { db: db.clone(), background: background.clone(), - rendering_method: asset, + rendering_method, }; let settings = settings::Settings::from_wizard("test-loco-template", &wizard_selection, OS::default()); From c60a5577153da1110161e833d8afb7441fc64007 Mon Sep 17 00:00:00 2001 From: Jonas Cirotzki Date: Fri, 10 Jan 2025 17:36:00 +0100 Subject: [PATCH 13/19] fix: view_engine is not needed for csr --- loco-new/base_template/config/test.yaml.t | 3 ++- loco-new/base_template/src/app.rs.t | 2 +- loco-new/setup.rhai | 2 +- loco-new/src/generator/mod.rs | 19 +++++++++++++++---- loco-new/src/settings.rs | 21 ++++++++++++++------- 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/loco-new/base_template/config/test.yaml.t b/loco-new/base_template/config/test.yaml.t index 8d6213fd4..4cded5c8a 100644 --- a/loco-new/base_template/config/test.yaml.t +++ b/loco-new/base_template/config/test.yaml.t @@ -32,7 +32,8 @@ server: uri: "/static" path: "assets/static" fallback: "assets/static/404.html" - {%- elif settings.rendering_method.kind == "client" %}fallback: + {%- elif settings.rendering_method.kind == "client" %} + fallback: enable: false static: enable: true diff --git a/loco-new/base_template/src/app.rs.t b/loco-new/base_template/src/app.rs.t index 84ac946a1..5d279fa2a 100644 --- a/loco-new/base_template/src/app.rs.t +++ b/loco-new/base_template/src/app.rs.t @@ -26,7 +26,7 @@ use migration::Migrator; #[allow(unused_imports)] use crate::{ controllers ,tasks - {%- if settings.initializers -%} + {%- if settings.initializers.view_engine -%} , initializers {%- endif %} {%- if settings.auth %} diff --git a/loco-new/setup.rhai b/loco-new/setup.rhai index 43a5148c2..81a434b7b 100644 --- a/loco-new/setup.rhai +++ b/loco-new/setup.rhai @@ -84,7 +84,7 @@ if db { // ===================== // Initializers Support // ===================== -if initializers { +if settings.initializers.view_engine { gen.copy_file("src/initializers/view_engine.rs"); // Template for view engine initializer } diff --git a/loco-new/src/generator/mod.rs b/loco-new/src/generator/mod.rs index c6367b019..6dec5545e 100644 --- a/loco-new/src/generator/mod.rs +++ b/loco-new/src/generator/mod.rs @@ -7,8 +7,9 @@ pub mod template; use std::sync::Arc; use include_dir::{include_dir, Dir}; -use rhai::{Engine, Scope}; +use rhai::{export_module, exported_module, Engine, Scope}; +use crate::settings::Initializers; use crate::{settings, OS}; static APP_TEMPLATE: Dir<'_> = include_dir!("base_template"); @@ -68,7 +69,8 @@ impl Generator { ); engine .build_type::() - .build_type::() + .register_type_with_name::>("Option") + .register_static_module("Option", exported_module!(settings_initializers).into()) .register_fn("copy_file", Self::copy_file) .register_fn("create_file", Self::create_file) .register_fn("copy_files", Self::copy_files) @@ -85,7 +87,6 @@ impl Generator { // TODO:: move it as part of the settings? scope.push("db", self.settings.db.is_some()); scope.push("background", self.settings.background.is_some()); - scope.push("initializers", self.settings.initializers.is_some()); scope.push("rendering_method", self.settings.rendering_method.is_some()); scope.push("windows", self.settings.os == OS::Windows); @@ -231,7 +232,17 @@ impl Generator { }) } } - +#[export_module] +mod settings_initializers { + use rhai::plugin::*; + use rhai::{Dynamic, Engine, EvalAltResult}; + use crate::settings::Initializers; + + #[rhai_fn(global, get = "view_engine", pure)] + pub fn view_engine(initializers: &mut Option) -> bool { + initializers.as_ref().map_or(false, |i| i.view_engine) + } +} #[cfg(test)] mod tests { use executer::MockExecuter; diff --git a/loco-new/src/settings.rs b/loco-new/src/settings.rs index da1d7f96a..35eb94124 100644 --- a/loco-new/src/settings.rs +++ b/loco-new/src/settings.rs @@ -7,7 +7,7 @@ use rhai::{CustomType, TypeBuilder}; use serde::{Deserialize, Serialize}; use crate::{ - wizard::{self, RenderingMethodOption, BackgroundOption, DBOption}, + wizard::{self, BackgroundOption, DBOption, RenderingMethodOption}, LOCO_VERSION, OS, }; @@ -53,7 +53,9 @@ impl From for Option { fn from(rendering_method: RenderingMethodOption) -> Self { match rendering_method { RenderingMethodOption::None => None, - _ => Some(RenderingMethod { kind: rendering_method }), + _ => Some(RenderingMethod { + kind: rendering_method, + }), } } } @@ -72,6 +74,15 @@ impl Settings { features }; + // we only need the view engine initializer if we are using serverside rendering + let initializers = if matches!( + prompt_selection.rendering_method, + RenderingMethodOption::Serverside + ) { + Some(Initializers { view_engine: true }) + } else { + None + }; Self { package_name: package_name.to_string(), module_name: package_name.to_snake_case(), @@ -81,11 +92,7 @@ impl Settings { background: prompt_selection.background.clone().into(), rendering_method: prompt_selection.rendering_method.clone().into(), clientside: prompt_selection.rendering_method.enable(), - initializers: if prompt_selection.rendering_method.enable() { - Some(Initializers { view_engine: true }) - } else { - None - }, + initializers, features, loco_version_text: get_loco_version_text(), os, From 6dbc1cd6d8d125f5639225cd2900448f37f7f1a6 Mon Sep 17 00:00:00 2001 From: Jonas Cirotzki Date: Fri, 10 Jan 2025 17:36:53 +0100 Subject: [PATCH 14/19] fix: asset folder is not needed for csr --- loco-new/setup.rhai | 4 ++-- loco-new/src/generator/mod.rs | 21 +++++++++++++++------ loco-new/src/settings.rs | 16 ++++++++++++---- loco-new/src/wizard.rs | 16 +++++++--------- 4 files changed, 36 insertions(+), 21 deletions(-) diff --git a/loco-new/setup.rhai b/loco-new/setup.rhai index 81a434b7b..e5831ad51 100644 --- a/loco-new/setup.rhai +++ b/loco-new/setup.rhai @@ -125,7 +125,7 @@ if background { // ===================== // Adds asset directory if assets are configured in the app. -if rendering_method { +if settings.assets { gen.copy_dir("assets"); // Static assets directory } @@ -134,7 +134,7 @@ if rendering_method { // Client side // ===================== -if settings.clientside { +if settings.rendering_method.client_side { gen.copy_dir("frontend"); gen.create_file("frontend/dist/index.html", "this is a placeholder. please run your frontend build (npm build)"); } diff --git a/loco-new/src/generator/mod.rs b/loco-new/src/generator/mod.rs index 6dec5545e..4e56c5d3e 100644 --- a/loco-new/src/generator/mod.rs +++ b/loco-new/src/generator/mod.rs @@ -9,7 +9,7 @@ use std::sync::Arc; use include_dir::{include_dir, Dir}; use rhai::{export_module, exported_module, Engine, Scope}; -use crate::settings::Initializers; +use crate::settings::{Initializers, RenderingMethod}; use crate::{settings, OS}; static APP_TEMPLATE: Dir<'_> = include_dir!("base_template"); @@ -70,7 +70,8 @@ impl Generator { engine .build_type::() .register_type_with_name::>("Option") - .register_static_module("Option", exported_module!(settings_initializers).into()) + .register_type_with_name::>("Option") + .register_static_module("rhai_settings_extensions", exported_module!(rhai_settings_extensions).into()) .register_fn("copy_file", Self::copy_file) .register_fn("create_file", Self::create_file) .register_fn("copy_files", Self::copy_files) @@ -87,7 +88,6 @@ impl Generator { // TODO:: move it as part of the settings? scope.push("db", self.settings.db.is_some()); scope.push("background", self.settings.background.is_some()); - scope.push("rendering_method", self.settings.rendering_method.is_some()); scope.push("windows", self.settings.os == OS::Windows); engine.run_with_scope(&mut scope, script)?; @@ -233,16 +233,25 @@ impl Generator { } } #[export_module] -mod settings_initializers { +mod rhai_settings_extensions { use rhai::plugin::*; - use rhai::{Dynamic, Engine, EvalAltResult}; + use rhai::Dynamic; use crate::settings::Initializers; - + use crate::wizard::RenderingMethodOption; #[rhai_fn(global, get = "view_engine", pure)] pub fn view_engine(initializers: &mut Option) -> bool { initializers.as_ref().map_or(false, |i| i.view_engine) } + + #[rhai_fn(global, get = "client_side", pure)] + pub fn client_side(rendering_method: &mut Option) -> bool { + rendering_method.as_ref().map_or(false, |r| matches!(r.kind, RenderingMethodOption::Clientside)) + } } + + + + #[cfg(test)] mod tests { use executer::MockExecuter; diff --git a/loco-new/src/settings.rs b/loco-new/src/settings.rs index 35eb94124..669450371 100644 --- a/loco-new/src/settings.rs +++ b/loco-new/src/settings.rs @@ -19,9 +19,9 @@ pub struct Settings { pub db: Option, pub background: Option, pub rendering_method: Option, + pub assets: bool, pub auth: bool, pub mailer: bool, - pub clientside: bool, pub initializers: Option, pub features: Features, pub loco_version_text: String, @@ -74,7 +74,7 @@ impl Settings { features }; - // we only need the view engine initializer if we are using serverside rendering + // we only need the view engine initializer for serverside rendering let initializers = if matches!( prompt_selection.rendering_method, RenderingMethodOption::Serverside @@ -83,15 +83,23 @@ impl Settings { } else { None }; + + + // we only need to copy the asset folder for serverside rendering + let assets = matches!( + prompt_selection.rendering_method, + RenderingMethodOption::Serverside + ); + Self { package_name: package_name.to_string(), module_name: package_name.to_snake_case(), + assets, auth: prompt_selection.db.enable() && prompt_selection.background.enable(), mailer: prompt_selection.db.enable() && prompt_selection.background.enable(), db: prompt_selection.db.clone().into(), background: prompt_selection.background.clone().into(), rendering_method: prompt_selection.rendering_method.clone().into(), - clientside: prompt_selection.rendering_method.enable(), initializers, features, loco_version_text: get_loco_version_text(), @@ -108,9 +116,9 @@ impl Default for Settings { db: Default::default(), background: Default::default(), rendering_method: Default::default(), + assets: Default::default(), auth: Default::default(), mailer: Default::default(), - clientside: Default::default(), initializers: Default::default(), features: Default::default(), loco_version_text: get_loco_version_text(), diff --git a/loco-new/src/wizard.rs b/loco-new/src/wizard.rs index f40deec4d..47868909f 100644 --- a/loco-new/src/wizard.rs +++ b/loco-new/src/wizard.rs @@ -150,18 +150,14 @@ pub enum RenderingMethodOption { } impl RenderingMethodOption { - #[must_use] - pub const fn enable(&self) -> bool { - !matches!(self, Self::None) - } - #[must_use] pub fn user_message(&self) -> Option { match self { Self::Clientside => Some(format!( "{}: You've selected `{}` as your frontend rendering method.\n\n\ To build your frontend, please run the following commands:\n\ - $ cd {}\n $ npm install && npm run build\n", + $ cd {}\n\ + $ npm install && npm run build\n", "Rendering method".underline(), "client-side rendering".yellow(), "frontend/".yellow() @@ -296,9 +292,11 @@ where /// when could not show user selection or user chose not continue pub fn start(args: &ArgsPlaceholder) -> crate::Result { // user provided everything via flags so no need to prompt, just return - if let (Some(db), Some(bg), Some(rendering_method)) = - (args.db.clone(), args.bg.clone(), args.rendering_method.clone()) - { + if let (Some(db), Some(bg), Some(rendering_method)) = ( + args.db.clone(), + args.bg.clone(), + args.rendering_method.clone(), + ) { return Ok(Selections { db, background: bg, From 0d0eb509af84e92b4c991b8fe41c0753b34e7a70 Mon Sep 17 00:00:00 2001 From: Jonas Cirotzki Date: Fri, 10 Jan 2025 17:37:28 +0100 Subject: [PATCH 15/19] fix: cargo dependencies for csr --- loco-new/base_template/Cargo.toml.t | 4 ++- loco-new/src/generator/mod.rs | 25 +++++++++++++------ ...method__cargo_dependencies_Clientside.snap | 3 ++- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/loco-new/base_template/Cargo.toml.t b/loco-new/base_template/Cargo.toml.t index 0d813b243..c872da29b 100644 --- a/loco-new/base_template/Cargo.toml.t +++ b/loco-new/base_template/Cargo.toml.t @@ -47,12 +47,14 @@ uuid = { version = "1.6.0", features = ["v4"] } include_dir = { version = "0.7" } {%- endif %} -{%- if settings.rendering_method %} +{%- if settings.rendering_method.kind %} +{%- if settings.rendering_method.kind == "server" %} # view engine i18n fluent-templates = { version = "0.8.0", features = ["tera"] } unic-langid = { version = "0.9.4" } # /view engine {%- endif %} +{%- endif %} [[bin]] name = "{{settings.module_name}}-cli" diff --git a/loco-new/src/generator/mod.rs b/loco-new/src/generator/mod.rs index 4e56c5d3e..74f73816d 100644 --- a/loco-new/src/generator/mod.rs +++ b/loco-new/src/generator/mod.rs @@ -71,7 +71,10 @@ impl Generator { .build_type::() .register_type_with_name::>("Option") .register_type_with_name::>("Option") - .register_static_module("rhai_settings_extensions", exported_module!(rhai_settings_extensions).into()) + .register_static_module( + "rhai_settings_extensions", + exported_module!(rhai_settings_extensions).into(), + ) .register_fn("copy_file", Self::copy_file) .register_fn("create_file", Self::create_file) .register_fn("copy_files", Self::copy_files) @@ -234,23 +237,29 @@ impl Generator { } #[export_module] mod rhai_settings_extensions { - use rhai::plugin::*; - use rhai::Dynamic; use crate::settings::Initializers; use crate::wizard::RenderingMethodOption; + use rhai::plugin::*; + use rhai::Dynamic; #[rhai_fn(global, get = "view_engine", pure)] pub fn view_engine(initializers: &mut Option) -> bool { initializers.as_ref().map_or(false, |i| i.view_engine) } #[rhai_fn(global, get = "client_side", pure)] - pub fn client_side(rendering_method: &mut Option) -> bool { - rendering_method.as_ref().map_or(false, |r| matches!(r.kind, RenderingMethodOption::Clientside)) + pub fn client_side(rendering_method: &mut Option) -> bool { + rendering_method.as_ref().map_or(false, |r| { + matches!(r.kind, RenderingMethodOption::Clientside) + }) } -} - - + #[rhai_fn(global, get = "server_side", pure)] + pub fn server_side(rendering_method: &mut Option) -> bool { + rendering_method.as_ref().map_or(false, |r| { + matches!(r.kind, RenderingMethodOption::Serverside) + }) + } +} #[cfg(test)] mod tests { diff --git a/loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_Clientside.snap b/loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_Clientside.snap index 8f046d841..9ed659322 100644 --- a/loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_Clientside.snap +++ b/loco-new/tests/templates/snapshots/r#mod__templates__rendering_method__cargo_dependencies_Clientside.snap @@ -1,5 +1,6 @@ --- source: tests/templates/rendering_method.rs expression: "content.get(\"dependencies\").unwrap()" +snapshot_kind: text --- -{ async-trait = { version = "0.1.74" }, axum = { version = "0.8.1" }, fluent-templates = { features = ["tera"], version = "0.8.0" }, loco-rs = { workspace = true }, regex = { version = "1.11.1" }, serde = { features = ["derive"], version = "1" }, serde_json = { version = "1" }, tokio = { default-features = false, features = ["rt-multi-thread"], version = "1.33.0" }, tracing = { version = "0.1.40" }, tracing-subscriber = { features = ["env-filter", "json"], version = "0.3.17" }, unic-langid = { version = "0.9.4" } } +{ async-trait = { version = "0.1.74" }, axum = { version = "0.8.1" }, loco-rs = { workspace = true }, regex = { version = "1.11.1" }, serde = { features = ["derive"], version = "1" }, serde_json = { version = "1" }, tokio = { default-features = false, features = ["rt-multi-thread"], version = "1.33.0" }, tracing = { version = "0.1.40" }, tracing-subscriber = { features = ["env-filter", "json"], version = "0.3.17" } } From 7d60ac0e248e9cca9d05aab55f8d36b6e89fd344 Mon Sep 17 00:00:00 2001 From: Jonas Cirotzki Date: Fri, 10 Jan 2025 17:54:33 +0100 Subject: [PATCH 16/19] fix: use initializers module if there is any --- loco-new/base_template/src/app.rs.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loco-new/base_template/src/app.rs.t b/loco-new/base_template/src/app.rs.t index 5d279fa2a..84ac946a1 100644 --- a/loco-new/base_template/src/app.rs.t +++ b/loco-new/base_template/src/app.rs.t @@ -26,7 +26,7 @@ use migration::Migrator; #[allow(unused_imports)] use crate::{ controllers ,tasks - {%- if settings.initializers.view_engine -%} + {%- if settings.initializers -%} , initializers {%- endif %} {%- if settings.auth %} From af375f3a40656ebc1b24f495abba21f56b5b70c8 Mon Sep 17 00:00:00 2001 From: Jonas Cirotzki Date: Fri, 10 Jan 2025 17:57:12 +0100 Subject: [PATCH 17/19] style: run nightly cargo fmt --- loco-new/src/bin/main.rs | 6 +++++- loco-new/src/generator/mod.rs | 14 ++++++++------ loco-new/src/settings.rs | 5 ++--- loco-new/src/wizard.rs | 11 +++++------ loco-new/tests/assertion/string.rs | 8 ++++---- loco-new/tests/templates/mod.rs | 1 - loco-new/tests/templates/rendering_method.rs | 12 ++++++++++-- loco-new/tests/wizard/new.rs | 11 ++++++++--- 8 files changed, 42 insertions(+), 26 deletions(-) diff --git a/loco-new/src/bin/main.rs b/loco-new/src/bin/main.rs index dae3f7788..cb9afa3cc 100644 --- a/loco-new/src/bin/main.rs +++ b/loco-new/src/bin/main.rs @@ -106,7 +106,11 @@ fn main() -> Result<()> { tracing::debug!(dir = %to.display(), "creating application directory"); std::fs::create_dir_all(&to)?; - let args = wizard::ArgsPlaceholder { db, bg, rendering_method }; + let args = wizard::ArgsPlaceholder { + db, + bg, + rendering_method, + }; let user_selection = wizard::start(&args)?; let generator_tmp_folder = extract_default_template()?; diff --git a/loco-new/src/generator/mod.rs b/loco-new/src/generator/mod.rs index 74f73816d..3b3057d37 100644 --- a/loco-new/src/generator/mod.rs +++ b/loco-new/src/generator/mod.rs @@ -9,8 +9,11 @@ use std::sync::Arc; use include_dir::{include_dir, Dir}; use rhai::{export_module, exported_module, Engine, Scope}; -use crate::settings::{Initializers, RenderingMethod}; -use crate::{settings, OS}; +use crate::{ + settings, + settings::{Initializers, RenderingMethod}, + OS, +}; static APP_TEMPLATE: Dir<'_> = include_dir!("base_template"); @@ -237,10 +240,9 @@ impl Generator { } #[export_module] mod rhai_settings_extensions { - use crate::settings::Initializers; - use crate::wizard::RenderingMethodOption; - use rhai::plugin::*; - use rhai::Dynamic; + use rhai::{plugin::*, Dynamic}; + + use crate::{settings::Initializers, wizard::RenderingMethodOption}; #[rhai_fn(global, get = "view_engine", pure)] pub fn view_engine(initializers: &mut Option) -> bool { initializers.as_ref().map_or(false, |i| i.view_engine) diff --git a/loco-new/src/settings.rs b/loco-new/src/settings.rs index 669450371..05b7b0ae2 100644 --- a/loco-new/src/settings.rs +++ b/loco-new/src/settings.rs @@ -83,14 +83,13 @@ impl Settings { } else { None }; - - + // we only need to copy the asset folder for serverside rendering let assets = matches!( prompt_selection.rendering_method, RenderingMethodOption::Serverside ); - + Self { package_name: package_name.to_string(), module_name: package_name.to_snake_case(), diff --git a/loco-new/src/wizard.rs b/loco-new/src/wizard.rs index 47868909f..7142337ac 100644 --- a/loco-new/src/wizard.rs +++ b/loco-new/src/wizard.rs @@ -154,10 +154,9 @@ impl RenderingMethodOption { pub fn user_message(&self) -> Option { match self { Self::Clientside => Some(format!( - "{}: You've selected `{}` as your frontend rendering method.\n\n\ - To build your frontend, please run the following commands:\n\ - $ cd {}\n\ - $ npm install && npm run build\n", + "{}: You've selected `{}` as your frontend rendering method.\n\nTo build your \ + frontend, please run the following commands:\n$ cd {}\n$ npm install && npm run \ + build\n", "Rendering method".underline(), "client-side rendering".yellow(), "frontend/".yellow() @@ -377,8 +376,8 @@ fn select_background( Ok(bgopt) } -/// Prompts the user to select frontend rendering method if none is provided in the -/// arguments. +/// Prompts the user to select frontend rendering method if none is provided in +/// the arguments. fn select_rendering_method(args: &ArgsPlaceholder) -> crate::Result { let rendering_method_opt = if let Some(rendering_method_opt) = args.rendering_method.clone() { rendering_method_opt diff --git a/loco-new/tests/assertion/string.rs b/loco-new/tests/assertion/string.rs index 8f33a9de4..581792b6c 100644 --- a/loco-new/tests/assertion/string.rs +++ b/loco-new/tests/assertion/string.rs @@ -35,8 +35,8 @@ pub fn assert_contains(content: &str, expected: &str) { assert!( content_sanitized.contains(&expected_sanitized), - "Assertion failed: The content did not contain the expected string. \ - Expected: '{expected_sanitized}', content:\n{content_sanitized}" + "Assertion failed: The content did not contain the expected string. Expected: \ + '{expected_sanitized}', content:\n{content_sanitized}" ); } @@ -46,7 +46,7 @@ pub fn assert_not_contains(content: &str, unexpected: &str) { assert!( !content_sanitized.contains(&unexpected_sanitized), - "Assertion failed: The content unexpectedly contained the string. \ - Unexpected: '{unexpected_sanitized}', content:\n{content_sanitized}" + "Assertion failed: The content unexpectedly contained the string. Unexpected: \ + '{unexpected_sanitized}', content:\n{content_sanitized}" ); } diff --git a/loco-new/tests/templates/mod.rs b/loco-new/tests/templates/mod.rs index 4644a292f..9ac4722e3 100644 --- a/loco-new/tests/templates/mod.rs +++ b/loco-new/tests/templates/mod.rs @@ -9,7 +9,6 @@ use loco::{ }; use rand::{rngs::StdRng, SeedableRng}; - mod auth; mod background; mod db; diff --git a/loco-new/tests/templates/rendering_method.rs b/loco-new/tests/templates/rendering_method.rs index 375cfd9a2..378f1b51b 100644 --- a/loco-new/tests/templates/rendering_method.rs +++ b/loco-new/tests/templates/rendering_method.rs @@ -80,7 +80,11 @@ static: #[rstest] fn test_cargo_toml( - #[values(RenderingMethodOption::None, RenderingMethodOption::Serverside, RenderingMethodOption::Clientside)] + #[values( + RenderingMethodOption::None, + RenderingMethodOption::Serverside, + RenderingMethodOption::Clientside + )] rendering_method: RenderingMethodOption, ) { let generator = run_generator(rendering_method.clone()); @@ -94,7 +98,11 @@ fn test_cargo_toml( #[rstest] fn test_github_ci_yaml( - #[values(RenderingMethodOption::None, RenderingMethodOption::Serverside, RenderingMethodOption::Clientside)] + #[values( + RenderingMethodOption::None, + RenderingMethodOption::Serverside, + RenderingMethodOption::Clientside + )] rendering_method: RenderingMethodOption, ) { let generator: TestGenerator = run_generator(rendering_method.clone()); diff --git a/loco-new/tests/wizard/new.rs b/loco-new/tests/wizard/new.rs index 65640a564..ce05c08bf 100644 --- a/loco-new/tests/wizard/new.rs +++ b/loco-new/tests/wizard/new.rs @@ -1,11 +1,12 @@ +use std::{collections::HashMap, path::PathBuf, process::Output, sync::Arc}; + use duct::cmd; use loco::{ generator::{executer::FileSystem, Generator}, settings, - wizard::{self, RenderingMethodOption, BackgroundOption, DBOption}, + wizard::{self, BackgroundOption, DBOption, RenderingMethodOption}, OS, }; -use std::{collections::HashMap, path::PathBuf, process::Output, sync::Arc}; #[cfg(feature = "test-wizard")] #[rstest::rstest] @@ -18,7 +19,11 @@ fn test_all_combinations( BackgroundOption::None )] background: BackgroundOption, - #[values(RenderingMethodOption::Serverside, RenderingMethodOption::Clientside, RenderingMethodOption::None)] + #[values( + RenderingMethodOption::Serverside, + RenderingMethodOption::Clientside, + RenderingMethodOption::None + )] rendering_method: RenderingMethodOption, ) { test_combination(db, background, rendering_method, false); From 016cd49bc8a860bc560da18a51c8895f33dff47d Mon Sep 17 00:00:00 2001 From: Jonas Cirotzki Date: Fri, 10 Jan 2025 18:03:22 +0100 Subject: [PATCH 18/19] style: fix rhai_settings_extensions imports --- loco-new/src/generator/mod.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/loco-new/src/generator/mod.rs b/loco-new/src/generator/mod.rs index 3b3057d37..452ca6666 100644 --- a/loco-new/src/generator/mod.rs +++ b/loco-new/src/generator/mod.rs @@ -1,17 +1,21 @@ //! This module defines the `Generator` struct, which is responsible for //! executing scripted commands -use std::path::{Path, PathBuf}; pub mod executer; pub mod template; -use std::sync::Arc; + +use std::{ + path::{Path, PathBuf}, + sync::Arc, +}; use include_dir::{include_dir, Dir}; -use rhai::{export_module, exported_module, Engine, Scope}; +use rhai::{export_module, exported_module, plugin::*, Dynamic, Engine, Scope}; use crate::{ settings, settings::{Initializers, RenderingMethod}, + wizard::RenderingMethodOption, OS, }; @@ -240,9 +244,7 @@ impl Generator { } #[export_module] mod rhai_settings_extensions { - use rhai::{plugin::*, Dynamic}; - use crate::{settings::Initializers, wizard::RenderingMethodOption}; #[rhai_fn(global, get = "view_engine", pure)] pub fn view_engine(initializers: &mut Option) -> bool { initializers.as_ref().map_or(false, |i| i.view_engine) From 9c472fa9506d495a2ab34cba64192cb1bbe6a4ca Mon Sep 17 00:00:00 2001 From: Jonas Cirotzki Date: Fri, 10 Jan 2025 18:22:00 +0100 Subject: [PATCH 19/19] docs: add documentation --- loco-new/src/generator/mod.rs | 6 ++++++ loco-new/src/settings.rs | 2 ++ 2 files changed, 8 insertions(+) diff --git a/loco-new/src/generator/mod.rs b/loco-new/src/generator/mod.rs index 452ca6666..805475dfb 100644 --- a/loco-new/src/generator/mod.rs +++ b/loco-new/src/generator/mod.rs @@ -242,14 +242,19 @@ impl Generator { }) } } + +/// This module provides extensions to the Rhai scripting language to access +/// the inner fields of the [Settings] struct in a more ergonomic way. #[export_module] mod rhai_settings_extensions { + /// Gives the script access to `settings.initializers.view_engine`. #[rhai_fn(global, get = "view_engine", pure)] pub fn view_engine(initializers: &mut Option) -> bool { initializers.as_ref().map_or(false, |i| i.view_engine) } + /// Gives the script access to `settings.rendering_method.client_side`. #[rhai_fn(global, get = "client_side", pure)] pub fn client_side(rendering_method: &mut Option) -> bool { rendering_method.as_ref().map_or(false, |r| { @@ -257,6 +262,7 @@ mod rhai_settings_extensions { }) } + /// Gives the script access to `settings.rendering_method.server_side`. #[rhai_fn(global, get = "server_side", pure)] pub fn server_side(rendering_method: &mut Option) -> bool { rendering_method.as_ref().map_or(false, |r| { diff --git a/loco-new/src/settings.rs b/loco-new/src/settings.rs index 05b7b0ae2..aff16f149 100644 --- a/loco-new/src/settings.rs +++ b/loco-new/src/settings.rs @@ -18,7 +18,9 @@ pub struct Settings { pub module_name: String, pub db: Option, pub background: Option, + /// Frontend rendering method configuration pub rendering_method: Option, + /// Copy the asset folder to the new project pub assets: bool, pub auth: bool, pub mailer: bool,