logo

Grimgrains

Unnamed repository; edit this file 'description' to name the repository.
commit: 7d5dc7d7911ab3932a0f31965e5639581508b426
parent 683497013af05bc1565e212ac98dfcc8b6099c65
Author: neauoire <aliceffekt@gmail.com>
Date:   Fri, 20 Dec 2019 10:26:10 -0500

Working on migrating the db

Diffstat:

Mscripts/templates/home.js41+++++++++++++++++++++++++++++++++++++++--
Asite/somefile.txt1+
Asrc/build.sh6++++++
Asrc/builder.c10++++++++++
Asrc/ingredient.c26++++++++++++++++++++++++++
Asrc/ingredients.c26++++++++++++++++++++++++++
Asrc/main0
Asrc/main.c16++++++++++++++++
Asrc/recipe.c75+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/recipes.c37+++++++++++++++++++++++++++++++++++++
10 files changed, 236 insertions(+), 2 deletions(-)

diff --git a/scripts/templates/home.js b/scripts/templates/home.js @@ -8,6 +8,8 @@ function HomeTemplate (id, rect) { this.answer = function (q) { const ingredients = find_ingredients(q.tables.recipes) + translate(q.tables.recipes) + ingredients.coffee = 1 const sorted_ingredients = sort_ingredients(ingredients) @@ -16,8 +18,8 @@ function HomeTemplate (id, rect) { <h1>Ingredients <a class='jump' id='jump-ingredients' href='javascript:Š("recipes")'>recipes</a></h1> ${make_ingredients(sorted_ingredients, q.tables.ingredients)} <h1 id='recipes_header'>Recipes <a class='jump' id='jump-recipes' href='javascript:Š("ingredients")'>ingredients</a></h1> - ${make_recipes(q.tables.recipes)} - ` + ${make_recipes(q.tables.recipes)}` + return { title: 'GrimGrains — Home', view: { @@ -80,6 +82,41 @@ function HomeTemplate (id, rect) { return Object.keys(ingredients).length } + + + + + function translate (recipes) { + + let txt = '' + + for(const name of Object.keys(recipes)){ + + const recipe = recipes[name] + const snake_name = name.toLowerCase().replace(/ /g,'_').trim() + + txt += `Recipe ${snake_name} = create_recipe("${name.toLowerCase()}", "${recipe.TAGS[0]}", "${recipe.SERV}", ${recipe.DATE.replace(/-/g,'')}, ${recipe.TIME});\n` + + for(const part in recipe.INST){ + if(!recipe.INGR[part]){ console.warn(snake_name,part) } + txt += `RecipePart ${snake_name+'_'+part.toLowerCase().replace(/ /g,'_').trim()} = create_part("${part.toLowerCase()}");\n` + } + txt += '\n\n' + console.log(recipe) + } + + + + console.log(txt) + } + + + + + + + + function make_recipes (recipes) { let html = '' diff --git a/site/somefile.txt b/site/somefile.txt @@ -0,0 +1 @@ +hello! diff --git a/src/build.sh b/src/build.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +cc -std=c99 -DDEBUG -Wall -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -lm -Og -fsanitize=address -fsanitize=undefined main.c -o main + +./main+ \ No newline at end of file diff --git a/src/builder.c b/src/builder.c @@ -0,0 +1,9 @@ + +/* +FILE *myfile = fopen("../site/somefile.txt", "w"); + +fprintf(myfile, "hello!\n"); + +fclose(myfile); + +*/+ \ No newline at end of file diff --git a/src/ingredient.c b/src/ingredient.c @@ -0,0 +1,25 @@ + +typedef struct { + int id; + char *name; + char *description; +} Ingredient; + +typedef struct { + Ingredient *ingredient; + char *quantity; +} Serving; + +Ingredient create_ingredient(char *name, char *description) { + Ingredient a; + a.name = name; + a.description = description; + return a; +} + +Serving create_serving(Ingredient *ingredient, char *quantity) { + Serving a; + a.ingredient = ingredient; + a.quantity = quantity; + return a; +}+ \ No newline at end of file diff --git a/src/ingredients.c b/src/ingredients.c @@ -0,0 +1,25 @@ + +Ingredient black_sesame_seeds = create_ingredient("black_sesame_seeds","descr"); +Ingredient coconut_oil = create_ingredient("coconut_oil","descr"); +Ingredient brown_rice_syrup = create_ingredient("brown_rice_syrup","descr"); +Ingredient puffed_rice = create_ingredient("puffed_rice","descr"); +Ingredient kinako = create_ingredient("kinako","descr"); +Ingredient salt = create_ingredient("salt","descr"); + +Ingredient soy_sauce = create_ingredient("soy_sauce","descr"); +Ingredient japanese_rice_vinegar = create_ingredient("japanese_rice_vinegar","descr"); +Ingredient chili_pepper_flakes = create_ingredient("chili_pepper_flakes","descr"); +Ingredient peanut_butter = create_ingredient("peanut_butter","descr"); +Ingredient maple_syrup = create_ingredient("maple_syrup","descr"); +Ingredient sesame_oil = create_ingredient("sesame_oil","descr"); +Ingredient garlic = create_ingredient("garlic","descr"); +Ingredient ginger_root = create_ingredient("ginger_root","descr"); +Ingredient arrowroot_starch = create_ingredient("arrowroot_starch","descr"); + +Ingredient brown_lentils = create_ingredient("brown_lentils","descr"); +Ingredient vegetable_bouillon = create_ingredient("vegetable_bouillon","descr"); +Ingredient carrots = create_ingredient("carrots","descr"); +Ingredient daikon = create_ingredient("daikon","descr"); +Ingredient chives = create_ingredient("chives","descr"); + +// Ingredient *ingredients[] = {&pepper};+ \ No newline at end of file diff --git a/src/main b/src/main Binary files differ. diff --git a/src/main.c b/src/main.c @@ -0,0 +1,15 @@ +#include "stdio.h" + +#include "ingredient.c" +#include "recipe.c" + +int main(void) { + + #include "ingredients.c" + #include "recipes.c" + #include "builder.c" + + print_recipe(&sweet_sour_lentils); + + return (0); +}+ \ No newline at end of file diff --git a/src/recipe.c b/src/recipe.c @@ -0,0 +1,75 @@ + +typedef struct { + char *name; + int instructions_len; + char *instructions[10]; + int servings_len; + Serving servings[10]; +} RecipePart; + +typedef struct { + char *name; + char *type; + char *portions; + char *description; + int date; + int time; + int parts_len; + RecipePart *parts[10]; +} Recipe; + +Recipe create_recipe(char *name, char *type, char *portions, int date, int time) { + Recipe a; + a.name = name; + a.type = type; + a.portions = portions; + a.date = date; + a.time = time; + a.parts_len = 0; + return a; +} + +RecipePart create_part(char *name) { + RecipePart a; + a.name = name; + a.instructions_len = 0; + a.servings_len = 0; + return a; +} + +void add_description(Recipe *r, char *description){ + r->description = description; +} + +void add_instruction(RecipePart *p, char *instruction){ + p->instructions[p->instructions_len] = instruction; + p->instructions_len++; +} + +void add_serving(RecipePart *p, Ingredient *i, char *quantity){ + p->servings[p->servings_len] = create_serving(i,quantity); + p->servings_len++; +} + +void add_part(Recipe *r, RecipePart *p){ + r->parts[r->parts_len] = p; + r->parts_len++; +} + +void print_recipe(Recipe *recipe) { + printf("name:%s(%s), portions:%s date:%d time:%d\n",recipe->name,recipe->type,recipe->portions,recipe->date,recipe->time); + printf("===========\nParts:\n"); + for(int i = 0; i < recipe->parts_len; ++i) { + printf("-- %s(%d ingredients %d instructions)\n", recipe->parts[i]->name, recipe->parts[i]->servings_len, recipe->parts[i]->instructions_len); + for(int i2 = 0; i2 < recipe->parts[i]->instructions_len; ++i2) { + printf("---- %s\n", recipe->parts[i]->instructions[i2]); + } + for(int i2 = 0; i2 < recipe->parts[i]->servings_len; ++i2) { + printf("------ %s\n", recipe->parts[i]->servings[i2].ingredient->name); + } + } + // printf("===========\nIngredients:\n"); + // for(int i = 0; i < recipe.servings_len; ++i) { + // printf("%s %s\n", recipe.servings[i].ingredient->name,recipe.servings[i].quantity); + // } +} diff --git a/src/recipes.c b/src/recipes.c @@ -0,0 +1,36 @@ + +Recipe sweet_sour_lentils = create_recipe("sweet and sour lentils","dinner","2 servings",20190602,30); +add_description(&sweet_sour_lentils, "In my galley I have a few recipes that I consider staples, that I'm always in the mood to eat. I usually rotate these throughout the week, adding maybe a new recipe or two to change things up. This sweet and sour lentils recipe is one of these, a favourite of ours."); +RecipePart sweet_sour_lentils_sauce = create_part("sauce"); +add_instruction(&sweet_sour_lentils_sauce, "Mix all liquid ingredients together in a bowl, add {_1 tbsp_} of {{peanut butter}} and stir until dissolved."); +add_instruction(&sweet_sour_lentils_sauce, "Stir in {_1 tbsp_} of {{arrowroot starch}} (to help thicken sauce)."); +add_instruction(&sweet_sour_lentils_sauce, "Add {_2 tsp_} of {{chili pepper flakes}}, {_3_} minced {{garlic cloves}} and roughly {_1 inch_} of minced {{ginger root}}."); +add_serving(&sweet_sour_lentils_sauce, &soy_sauce, "2 tbsp"); +add_serving(&sweet_sour_lentils_sauce, &japanese_rice_vinegar, "2 tbsp"); +add_serving(&sweet_sour_lentils_sauce, &chili_pepper_flakes, "2 tsp"); +add_serving(&sweet_sour_lentils_sauce, &peanut_butter, "1 tbsp"); +add_serving(&sweet_sour_lentils_sauce, &maple_syrup, "2 tbsp"); +add_serving(&sweet_sour_lentils_sauce, &sesame_oil, "1 tsp"); +add_serving(&sweet_sour_lentils_sauce, &garlic, "3 cloves, minced"); +add_serving(&sweet_sour_lentils_sauce, &ginger_root, "1 root minced"); +add_serving(&sweet_sour_lentils_sauce, &arrowroot_starch, "1 tbsp"); +add_part(&sweet_sour_lentils, &sweet_sour_lentils_sauce); +RecipePart sweet_sour_lentils_main = create_part("main"); +add_instruction(&sweet_sour_lentils_main, "Rinse lentils. Transfer rinsed lentils to a pot and add {_1 1/2 cups_} of {{vegetable bouillon}}."); +add_instruction(&sweet_sour_lentils_main, "Bring water to a rapid simmer, then reduce heat to medium."); +add_instruction(&sweet_sour_lentils_main, "Simmer uncovered. After {#10 minutes#} add {_1_} cubed {{carrot}} and {_2 inches_} of cubed {{daikon}}."); +add_instruction(&sweet_sour_lentils_main, "Let mixture simmer for an additional {#10-20 minutes#}, add extra water as needed."); +add_instruction(&sweet_sour_lentils_main, "If lentils are tender, they are ready. Strain lentils and return to pot with {_1/4 tsp_} of {{salt}}."); +add_instruction(&sweet_sour_lentils_main, "Pour sauce onto lentils, mix well. Serve into two bowls with some {{chives}}. Eat wrapped in salad or cabbage leaves, or with {{crackers}}."); +add_serving(&sweet_sour_lentils_main, &brown_lentils, "1/2 cup"); +add_serving(&sweet_sour_lentils_main, &vegetable_bouillon, "1 1/2 cups"); +add_serving(&sweet_sour_lentils_main, &carrots, "1, cubed"); +add_serving(&sweet_sour_lentils_main, &daikon, "2 cubed"); +add_serving(&sweet_sour_lentils_main, &chives, "3 stalks"); +add_serving(&sweet_sour_lentils_main, &salt, "1/4 tsp"); +add_part(&sweet_sour_lentils, &sweet_sour_lentils_main); + + + + +Recipe *recipes[] = {&sweet_sour_lentils};+ \ No newline at end of file