Init repo and add all files

This commit is contained in:
clerie 2020-01-03 20:25:01 +01:00
commit b4b35d238d
7 changed files with 221 additions and 0 deletions

8
README.md Normal file
View File

@ -0,0 +1,8 @@
# Try not to starve!
A generator for simple food recipes if you havn't any idea what to eat.
It's just static html, css and js. You can serve it with any webserver and try it out. eg:
```
python3 -m http.server
```

7
bootstrap.min.css vendored Normal file

File diff suppressed because one or more lines are too long

7
bootstrap.min.js vendored Normal file

File diff suppressed because one or more lines are too long

34
index.html Normal file
View File

@ -0,0 +1,34 @@
<!doctype html>
<html lang="de">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="bootstrap.min.css">
<script src="jquery-3.4.1.min.js"></script>
<script src="bootstrap.min.js"></script>
<script src="script.js"></script>
<title>Try not to starve!</title>
</head>
<body>
<div class="container text-center" style="margin-top: 30px; margin-bottom: 30px;">
<div class="row">
<div class="offset-md-3 col-md-6">
<h1>Try not to starve!</h1>
<div class="card">
<div class="card-body">
<div id="recipe"></div>
</div>
<div class="card-footer text-muted">
<button class="btn btn-block btn-primary btn-lg" onclick="generateRecipe();">Neu</button>
</div>
</div>
<div class="alert alert-danger" role="alert" id="error" style="display: none;">
</div>
</div>
</div>
</div>
</body>
</html>

2
jquery-3.4.1.min.js vendored Normal file

File diff suppressed because one or more lines are too long

99
recipe.json Normal file
View File

@ -0,0 +1,99 @@
{
"": [
"$nudeln und $nudelsosse",
"Kartoffeln und $kartoffelsosse",
"Kartoffeln mit $beilage",
"Kartoffelpuffer und $kartoffelpuffersosse",
"Reis und $reissosse",
"$muesli",
"$muesli und $mueslisosse"
],
"nudeln": [
"Nudeln",
"Spaghetti",
"Fusili",
"Bandnudeln"
],
"nudelsosse": [
"$tomatensosse"
],
"tomatensosse": [
"Tomatensoße mit $gemuese",
"Tomatensoße mit $gemuese und $gewuerz"
],
"kaesesosse":[
"$kaese mit $gewuerz"
],
"kaese": [
"Gouda",
"Gorgonzola",
"Mozzarella"
],
"kartoffelsosse": [
"$sosse-herzhaft"
],
"beilage": [
"$gemuese",
"$kaese"
],
"kartoffelpuffersosse": [
"$sosse"
],
"reissosse": [
"$sosse-herzhaft"
],
"sosse": [
"$sosse-herzhaft",
"$sosse-suess"
],
"sosse-herzhaft": [
"$tomatensosse",
"Quark"
],
"sosse-suess": [
"$sosse-suess und $sosse-suess",
"Apfelmus",
"Zimt",
"Zucker",
"Kirschen"
],
"gewuerz": [
"$gewuerz und $gewuerz",
"Pfeffer",
"Paprikapulver",
"Kümmel",
"Zwiebeln"
],
"muesli": [
"$muesli mit $obst",
"Müsli",
"Cornflakes",
"Haferflocken",
"Haferflakes"
],
"mueslisosse": [
"Milch",
"$joghurt",
"Saft"
],
"joghurt": [
"Joghurt",
"$gemuese Johurt"
],
"gemuese": [
"$gemuese und $gemuese",
"Gurke",
"Paprika",
"Tomate",
"Frühlinszwiebeln",
"Lauch",
"Spinat"
],
"obst": [
"$obst und $obst",
"Apfel",
"Kirschen",
"Banane",
"Orangen"
]
}

64
script.js Normal file
View File

@ -0,0 +1,64 @@
var recipe = {};
$(window).on("load", () => {
$.getJSON("recipe.json", (json) => {
console.log(json);
recipe = json;
}).done(() => {
clearError();
generateRecipe();
});
//;
});
function generateRecipe() {
var block = generateBlock("");
if(block !== null) {
$("#recipe").html(block);
clearError();
}
else {
showError("Beim generieren trat ein Fehler auf.");
}
}
function generateBlock(key) {
if(key in recipe) {
var error = false;
// choose a random block out of our recipe
var block = recipe[key][Math.floor(Math.random() * recipe[key].length)];
block = block.split(" ");
// scan all words for vars to replace
block.forEach((item, index) => {
if(item.startsWith("$")) {
// generate a new block to replace the var
var newBlock = generateBlock(item.substr(1));
// replace or brake in case of error
if(newBlock !== null) {
block[index] = newBlock;
}
else {
error = true;
}
}
});
// return or break
if(!error) {
return block.join(" ");
}
else {
return null;
}
}
else {
return null;
}
}
function showError(msg) {
$("#error").html(msg).fadeIn();
}
function clearError() {
$("#error").fadeOut().html("");
}