Struct Forge

Source
pub struct Forge<S: ToString, T: Serialize> { /* private fields */ }

Implementations§

Source§

impl<S: ToString, T: Serialize> Forge<S, T>

Source

pub fn new(config: ForgeConfig) -> Result<Self, ForgeError>

Examples found in repository?
examples/common/utils.rs (line 15)
8pub fn create_forge(preview: bool) -> Forge<Templates, Value> {
9    let config = ForgeConfig {
10        components_dir_path: PathBuf::from("examples/components/"),
11        components_dir_options: DirectorySourceOptions::default(),
12        preview,
13    };
14
15    let mut forge: Forge<Templates, Value> = Forge::new(config).unwrap();
16
17    let template = Templates::EmailValidation(Default::default());
18    if let Templates::EmailValidation(data) = &template {
19        forge
20            .add_template(ForgeTemplate::new(
21                template.clone(),
22                PathBuf::from_str("examples/templates/email_validation.hbs").unwrap(),
23                serde_json::to_value(data.clone()).unwrap(),
24            ))
25            .unwrap();
26    }
27
28    let template = Templates::PasswordReset(Default::default());
29    if let Templates::PasswordReset(data) = &template {
30        forge
31            .add_template(ForgeTemplate::new(
32                template.clone(),
33                PathBuf::from_str("examples/templates/password_reset.hbs").unwrap(),
34                serde_json::to_value(data.clone()).unwrap(),
35            ))
36            .unwrap();
37    }
38
39    forge
40}
Source

pub fn add_template( &mut self, template: ForgeTemplate<S, T>, ) -> Result<(), ForgeError>

Examples found in repository?
examples/common/utils.rs (lines 20-24)
8pub fn create_forge(preview: bool) -> Forge<Templates, Value> {
9    let config = ForgeConfig {
10        components_dir_path: PathBuf::from("examples/components/"),
11        components_dir_options: DirectorySourceOptions::default(),
12        preview,
13    };
14
15    let mut forge: Forge<Templates, Value> = Forge::new(config).unwrap();
16
17    let template = Templates::EmailValidation(Default::default());
18    if let Templates::EmailValidation(data) = &template {
19        forge
20            .add_template(ForgeTemplate::new(
21                template.clone(),
22                PathBuf::from_str("examples/templates/email_validation.hbs").unwrap(),
23                serde_json::to_value(data.clone()).unwrap(),
24            ))
25            .unwrap();
26    }
27
28    let template = Templates::PasswordReset(Default::default());
29    if let Templates::PasswordReset(data) = &template {
30        forge
31            .add_template(ForgeTemplate::new(
32                template.clone(),
33                PathBuf::from_str("examples/templates/password_reset.hbs").unwrap(),
34                serde_json::to_value(data.clone()).unwrap(),
35            ))
36            .unwrap();
37    }
38
39    forge
40}
Source

pub fn get_templates(&self) -> Vec<String>

Source

pub fn get_handlebars(&mut self) -> &mut Handlebars<'static>

Source

pub fn render( &self, template_name: impl ToString, data: &T, ) -> Result<String, ForgeError>

Examples found in repository?
examples/advanced.rs (line 13)
8fn main() {
9    let forge = create_forge(false);
10
11    let email = Templates::EmailValidation(Default::default());
12    if let Templates::EmailValidation(data) = &email {
13        dbg!(forge.render(&email, &serde_json::to_value(data).unwrap()));
14    }
15}
Source

pub fn render_with_default( &self, template_name: impl ToString, ) -> Result<String, ForgeError>

Auto Trait Implementations§

§

impl<S, T> Freeze for Forge<S, T>

§

impl<S, T> !RefUnwindSafe for Forge<S, T>

§

impl<S, T> Send for Forge<S, T>
where T: Send, S: Send,

§

impl<S, T> Sync for Forge<S, T>
where T: Sync, S: Sync,

§

impl<S, T> Unpin for Forge<S, T>
where T: Unpin, S: Unpin,

§

impl<S, T> !UnwindSafe for Forge<S, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.