use femstache::{Template, TemplateInput};
#[derive(TemplateInput)]
struct DryIngredients {
sugar_g: u32,
flour_g: u32,
baking_powder_g: u32,
salt_g: u32,
}
#[derive(TemplateInput)]
struct WetIngredients {
milk_ml: u32,
butter_g: u32,
vanilla_extract_ml: u32,
}
#[derive(TemplateInput)]
struct Input {
#[femstache(flatten)]
dry: DryIngredients,
#[femstache(flatten)]
wet: WetIngredients,
time_min_min: u32,
time_max_min: u32,
temp_c: u32,
}
const TEMPLATE_STR: &str = r#"Time to bake a vanilla cake!
So, first the dry ingredients! Add {{sugar_g}}g of sugar, {{flour_g}}g of flour,
{{salt_g}}g of salt and {{baking_powder_g}}g of baking powder to a bowl. Mix mix
mix mix mix mix!
Then! The wet ingredients!
To another bowl, add {{milk_ml}}ml of soy milk, {{butter_g}}g of butter and
{{vanilla_extract_ml}}ml of vanilla extract. Mix it! MIX IT. YOU NEED TO MIX IT.
MIX MIX MIX MIX MIX MIX.
Then, we combine the wet and dry ingredients. Mix more! Always mix!
Good job. The cake will be beautiful, just like you! <3
Pour the mixture in a cake pan and put it in the oven for {{time_min_min}} minutes
to {{time_max_min}} minutes at {{temp_c}}°C.
You got yourself a caek! :O!!!!!
CAEK CAEK ZOMG!!!!
"#;
fn main() {
let portions = std::env::args()
.skip(1)
.next()
.map(|p| p.parse())
.transpose()
.unwrap()
.unwrap_or(1);
let tpl = Template::parse(TEMPLATE_STR).unwrap();
let output = femstache::render(
&tpl,
&Input {
dry: DryIngredients {
sugar_g: portions * 300,
flour_g: portions * 313,
baking_powder_g: portions * 10,
salt_g: portions,
},
wet: WetIngredients {
milk_ml: portions * 315,
butter_g: portions * 150,
vanilla_extract_ml: portions * 15,
},
time_min_min: 22,
time_max_min: 28,
temp_c: 180,
},
)
.unwrap();
println!("{output}");
}