go-recipe-book/pkg/web/tpl/pages/RecipeDetail_templ.go
Alessio b121b75b30
Some checks failed
Build / build (push) Failing after 1m12s
Build / release (push) Has been skipped
Add templ generated go files
2025-02-19 19:37:37 -08:00

373 lines
19 KiB
Go

// Code generated by templ - DO NOT EDIT.
// templ: version: v0.2.793
package pages
//lint:file-ignore SA4006 This context is only used if a nested component is present.
import "github.com/a-h/templ"
import templruntime "github.com/a-h/templ/runtime"
import (
"fmt"
"strings"
. "recipe_book/pkg/db"
)
func to_food_list(r Recipe) []Food {
ret := make([]Food, len(r.Ingredients))
for i := range r.Ingredients {
ret[i] = r.Ingredients[i].Food
}
return ret
}
func WebComponentScripts(recipe Recipe) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer {
defer func() {
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
if templ_7745c5c3_Var1 == nil {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Err = templ.JSONScript("allIngredientsData", to_food_list(recipe)).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<script>\n\t\tconst all_ingredients = JSON.parse(allIngredientsData.textContent);\n\n\t\t/**\n\t\t * Create and return a <tr> element corresponding to an ingredient in the recipe\n\t\t */\n\n\n\t\t// class IngredientRow extends HTMLElement {\n\t\t// \tconstructor() {\n\t\t// \t\tsuper();\n\t\t// \t\tthis.attachShadow({mode: \"open\"});\n\t\t// \t}\n\t\t// \tstatic get observedAttributes() {\n\t\t// \t\treturn [\"ingredient-id\", \"units\", \"units-amount\"];\n\t\t// \t}\n\t\t// \tget ingredient() {\n\t\t// \t\treturn all_ingredients.find(i => i.id = this.getAttribute(\"ingredient-id\"));\n\t\t// \t}\n\t\t// \tget units_amount() {\n\t\t// \t\treturn parseFloat(this.getAttribute(\"units-amount\"));\n\t\t// \t}\n\t\t// \tget amount() {\n\t\t// \t\tconst ingr = this.ingredient;\n\t\t// \t\tswitch (this.getAttribute(\"units\")) {\n\t\t// \t\t\tcase \"ct\": return this.units_amount;\n\t\t// \t\t\tcase \"g\": return this.units_amount / ingr.mass;\n\t\t// \t\t\tcase \"lbs\": return this.units_amount / ingr.mass * 454;\n\t\t// \t\t\tcase \"oz\": return this.units_amount / ingr.mass * 28;\n\t\t// \t\t\tcase \"mL\": return this.units_amount * ingr.density / ingr.mass;\n\t\t// \t\t\tcase \"cups\": return this.units_amount * ingr.density / ingr.mass * 250;\n\t\t// \t\t\tcase \"tsp\": return this.units_amount * ingr.density / ingr.mass * 5;\n\t\t// \t\t\tcase \"tbsp\": return this.units_amount * ingr.density / ingr.mass * 15\n\t\t// \t\t\tcase \"floz\": return this.units_amount * ingr.density / ingr.mass * 30\n\t\t// \t\t}\n\t\t// \t}\n\t\t// \tconnectedCallback() {\n\t\t// \t\t this.shadowRoot.appendChild(ingredientRowTpl.content.cloneNode(true)); // Initialize the contents\n\t\t// \t\t const ingr = this.ingredient;\n\t\t// \t\t this.shadowRoot.querySelector(\".amount\").textContent = this.getAttribute(\"units-amount\") + \" \" + this.getAttribute(\"units\");\n\t\t// \t\t this.shadowRoot.querySelector(\".name\").textContent = ingr.name;\n\t\t// \t\t this.shadowRoot.querySelector(\".cals\").textContent = ingr.cals * this.amount;\n\t\t// \t\t this.shadowRoot.querySelector(\".carbs\").textContent = ingr.carbs * this.amount;\n\t\t// \t\t this.shadowRoot.querySelector(\".protein\").textContent = ingr.protein * this.amount;\n\t\t// \t\t this.shadowRoot.querySelector(\".fat\").textContent = ingr.fat * this.amount;\n\t\t// \t\t this.shadowRoot.querySelector(\".sugar\").textContent = ingr.sugar * this.amount;\n\t\t// \t}\n\t\t// }\n\t\t// customElements.define(\"ingredient-row\", IngredientRow)\n\n\t\t// class RecipeTable extends HTMLElement {\n\t\t// \tconstructor() {\n\t\t// \t\tsuper();\n\t\t// \t\tthis.attachShadow({mode: \"open\"});\n\t\t// \t}\n\n\t\t// }\n\t</script>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return templ_7745c5c3_Err
})
}
func RecipeDetail(recipe Recipe) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer {
defer func() {
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var2 := templ.GetChildren(ctx)
if templ_7745c5c3_Var2 == nil {
templ_7745c5c3_Var2 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<h1>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(recipe.Name)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/web/tpl/pages/RecipeDetail.templ`, Line: 95, Col: 18}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</h1><dialog id=\"renameRecipeDialog\"><h3>Rename recipe</h3><form hx-post=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var4 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("/recipes/%d", recipe.ID))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/web/tpl/pages/RecipeDetail.templ`, Line: 98, Col: 55}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" hx-ext=\"json-enc\" hx-target=\"body\" hx-push-url=\"true\"><label for=\"name\">New name:</label> <input name=\"name\"> <input type=\"submit\" value=\"Update\"></form><button onclick=\"renameRecipeDialog.close()\">Cancel</button></dialog> <button class=\"new-item-button\" onclick=\"renameRecipeDialog.showModal()\">Rename</button><table class=\"recipe-table\"><thead><th></th><th>Amount</th><th>Ingredient</th><th>Calories</th><th>Carbs</th><th>Protein</th><th>Fat</th><th>Sugar</th></thead> <tbody>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for _, i := range recipe.Ingredients {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<tr><td class=\"delete-button\"></td><td class=\"amount\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var5 string
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(i.DisplayAmount())
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/web/tpl/pages/RecipeDetail.templ`, Line: 122, Col: 43}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td class=\"name\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var6 string
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(i.Food.Name)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/web/tpl/pages/RecipeDetail.templ`, Line: 123, Col: 35}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td class=\"cals\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var7 string
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprint(int(i.Food.Cals * i.Quantity)))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/web/tpl/pages/RecipeDetail.templ`, Line: 124, Col: 65}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td class=\"carbs\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var8 string
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprint(int(i.Food.Carbs * i.Quantity)))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/web/tpl/pages/RecipeDetail.templ`, Line: 125, Col: 67}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td class=\"protein\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var9 string
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprint(int(i.Food.Protein * i.Quantity)))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/web/tpl/pages/RecipeDetail.templ`, Line: 126, Col: 71}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td class=\"fat\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var10 string
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprint(int(i.Food.Fat * i.Quantity)))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/web/tpl/pages/RecipeDetail.templ`, Line: 127, Col: 63}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td class=\"sugar\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var11 string
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprint(int(i.Food.Sugar * i.Quantity)))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/web/tpl/pages/RecipeDetail.templ`, Line: 128, Col: 67}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td></tr>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
computed_food := recipe.ComputeFood()
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<tr class=\"recipe-table__total-row\"><td class=\"delete-button\"></td><td class=\"amount\"></td><td class=\"name\">Total</td><td class=\"cals\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var12 string
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprint(int(computed_food.Cals)))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/web/tpl/pages/RecipeDetail.templ`, Line: 136, Col: 58}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td class=\"carbs\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var13 string
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprint(int(computed_food.Carbs)))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/web/tpl/pages/RecipeDetail.templ`, Line: 137, Col: 60}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td class=\"protein\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var14 string
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprint(int(computed_food.Protein)))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/web/tpl/pages/RecipeDetail.templ`, Line: 138, Col: 64}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td class=\"fat\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var15 string
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprint(int(computed_food.Fat)))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/web/tpl/pages/RecipeDetail.templ`, Line: 139, Col: 56}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td class=\"sugar\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var16 string
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprint(int(computed_food.Sugar)))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/web/tpl/pages/RecipeDetail.templ`, Line: 140, Col: 60}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td></tr></tbody></table>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if recipe.Blurb != "" {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<h2>Blurb</h2>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for _, line := range strings.Split(recipe.Blurb, "\n") {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<p><i>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var17 string
templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(line)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/web/tpl/pages/RecipeDetail.templ`, Line: 148, Col: 15}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</i></p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<h2>Instructions</h2><ol class=\"instructions-list\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for _, instr := range recipe.Instructions {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<li>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for _, line := range strings.Split(instr, "\n") {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var18 string
templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(line)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/web/tpl/pages/RecipeDetail.templ`, Line: 157, Col: 14}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</li>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</ol>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return templ_7745c5c3_Err
})
}
// <ingredient-row ingredient-id={ fmt.Sprint(i.Food.ID) } units={ i.Units.Abbreviation() } units-amount={ fmt.Sprint(i.DisplayAmount()) }></ingredient-row>
//
// function create_ingredient_row(ingredient_id, units, units_amount) {
// const ingredient = all_ingredients.find(i => i.ID = ingredient_id);
// const amount = {
// ct: units_amount;
// g: units_amount / ingredient.mass,
// lbs: units_amount / ingredient.mass * 454,
// oz: units_amount / ingredient.mass * 28,
// mL: units_amount * ingredient.density / ingredient.mass,
// cups: units_amount * ingredient.density / ingredient.mass * 250,
// tsp: units_amount * ingredient.density / ingredient.mass * 5,
// tbsp: units_amount * ingredient.density / ingredient.mass * 15,
// floz: units_amount * ingredient.density / ingredient.mass * 30,
// }[units]
//
// const tr = document.createElement("tr");
// tr.innerHTML = `
// <td class="delete-button"></td>
// <td class="amount">${units_amount + " " + units}</td>
// <td class="name">${ingredient.name}</td>
// <td class="cals">${ingredient.cals * amount}</td>
// <td class="carbs">${ingredient.carbs * amount}</td>
// <td class="protein">${ingredient.protein * amount}</td>
// <td class="fat">${ingredient.fat * amount}</td>
// <td class="sugar">${ingredient.sugar * amount}</td>
// `;
// return tr;
// }
var _ = templruntime.GeneratedTemplate