omakase/pages/recipe.jai
2025-11-24 23:24:53 +02:00

95 lines
3.2 KiB
Plaintext

get_recipe_page :: (req: Request) -> string {
id := table_find_pointer(*req.query, "id");
if !id then return "<h1>Error: invalid recipe id</h1>";
curRecipe : Recipe;
for state.recipes if it.id == id.* curRecipe = it;
if curRecipe.id == "" then return "<h1>Can't find recipe!</h1>";
builder : String_Builder;
add_navbar(*builder);
print_to_builder(*builder, recipeHero, curRecipe.image);
print_to_builder(*builder, "<div class=\"content-wrapper\">");
print_to_builder(*builder, recipeHeroCard, curRecipe.id, curRecipe.category, curRecipe.name, curRecipe.duration, curRecipe.duration);
print_to_builder(*builder, "</div>");
print_to_builder(*builder, "<div class=\"layout\">");
add_ingredients(curRecipe, *builder);
add_steps(curRecipe, *builder);
print_to_builder(*builder, "</div>");
return builder_to_string(*builder);
}
add_ingredients :: (recipe: Recipe, builder: *String_Builder) {
print_to_builder(builder, "<div>");
print_to_builder(builder, "<div class=\"mono\" style=\"margin-bottom: 1rem; border-bottom: 2px solid var(--ink); padding-bottom: 0.5rem;\">Ingredients</div>");
ingredientHtml : string = #string DONE
<div class="component-row">
<div class="component-name">%</div>
<div class="mono">%</div>
</div>
DONE
slotHtml : string = #string DONE
<div class="component-row">
<div>
<div class="component-name" style="text-decoration: underline; text-decoration-color: var(--gold);">Component slot</div>
<div class="mono" style="font-size: 0.6rem; color: var(--gold);">%</div>
</div>
<div class="mono">1</div>
</div>
DONE
for recipe.components {
b : String_Builder;
if !it.isSlot {
print_to_builder(builder, ingredientHtml, it.ingredient.name, it.ingredient.amount);
} else {
for t : it.slot.tags {
print_to_builder(*b, "[%] ", t);
}
print_to_builder(builder, slotHtml, builder_to_string(*b));
}
}
print_to_builder(builder, "</div>");
}
add_steps :: (recipe: Recipe, builder: *String_Builder) {
stepHtml : string = #string DONE
<div class="step">
<div class="step-num">%</div>
<div class="step-text">%</div>
</div>
DONE
print_to_builder(builder, "<div>");
print_to_builder(builder, "<div class=\"mono\" style=\"margin-bottom: 1rem; border-bottom: 2px solid var(--ink); padding-bottom: 0.5rem;\">Steps</div>");
for it, i : recipe.steps {
print_to_builder(builder, stepHtml, i+1, it);
}
print_to_builder(builder, "</div>");
}
recipeHeroCard : string = #string DONE
<header class="header-card">
<div class="mono" style="margin-bottom: 1rem; color: var(--gold);">% &bull; % &bull; HIGH PROTEIN</div>
<h1 class="recipe-title">%</h1>
<div class="specs">
<div><span class="mono">Time</span><br><span class="spec-val">% minutes</span></div>
<div><span class="mono">Yield</span><br><span class="spec-val">% servings</span></div>
</div>
</header>
DONE
recipeHero : string = #string DONE
<div class="recipe-hero">
<img id="parallax-img" src="%" alt="Steak">
</div>
DONE