Skip to content

Commit

Permalink
docs: add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasCir committed Jan 10, 2025
1 parent 016cd49 commit 9c472fa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions loco-new/src/generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,21 +242,27 @@ 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<Initializers>) -> 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<RenderingMethod>) -> bool {
rendering_method.as_ref().map_or(false, |r| {
matches!(r.kind, RenderingMethodOption::Clientside)
})
}

/// 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<RenderingMethod>) -> bool {
rendering_method.as_ref().map_or(false, |r| {
Expand Down
2 changes: 2 additions & 0 deletions loco-new/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ pub struct Settings {
pub module_name: String,
pub db: Option<Db>,
pub background: Option<Background>,
/// Frontend rendering method configuration
pub rendering_method: Option<RenderingMethod>,
/// Copy the asset folder to the new project
pub assets: bool,
pub auth: bool,
pub mailer: bool,
Expand Down

0 comments on commit 9c472fa

Please sign in to comment.