Meal is a templating language for the Homecooked ASGI framework. It is similar to Jinja2 and other templating languages, except all terminals are replaced with emojis.
To get started with Meal and Chef, read the Meal Docs and try out the Chef Creator.
In Meal, if it's not a variable, string or number, it's an emoji. Meal is a very powerful templating language, allowing for control structures, loops, and more.
In the below program, we will do some basic math and print the result.
π§π΄ a π 5 π΄
π΄ b π 10 π΄
π₯’ a π¦ b π₯’π§
This program will output 15 to the screen.
Meal supports control flow structures such as if-else statements and loops.
In the below program, we will check if a is greater than b and print the result if it is. While it is not, we will increase the value of a
π§π΄ a π 5 π΄
π΄ b π 10 π΄
π΄ π― a π° b π₯
π΄ a π a π¦ 1 π΄
π₯π΄ π₯’ a π₯’ π§
This program will output 10 to the screen, as a is incremented 5 times before it is equal to b.
In the next program, we demonstrate a for loop. We will loop through a range of numbers and print the result.
π§ π΄ aπ π 1π2π5π21π123ππ΄
π΄ π num π a π₯
π΄ π num π₯§ 2 π₯
num = π₯’ num π₯’
π₯
π₯ num π₯§ 21 π₯
num is now 21, see π₯’ num π₯’ π₯π΄ π₯π΄ π§
This program will iterate through the list [1, 2, 5, 21, 123]. When the value of 'num' is equal to 2 and 21, the program will output to the screen.
In more readable psuedocode, the program is equivalent to:
a = [1,2,5,21,123]
for num in a:
if num == 2:
print(num)
else if num == 21:
print(num)
As Meal is made to be used with web servers, and we often want to render dynamic information from the webserver, Meal supports providing a 'render context' to the Meal template. When returning a TemplateResponse, the context to provide to Meal is the second argument, and consists of a dict mapping variable names to values.
In the below program, we will render a template with a context. Suppose we provide the following context:
context = {'name': 'Meal Docs', 'author': 'Homecooked', 'value': 5}
And the following template:
π§ The name is: π₯’nameπ₯’
The author is: π₯’authorπ₯’
Value: π₯’max(value π§ 10π2)π₯’ π§
π§π₯’nameπ₯’π§ will be replaced by 'Meal Docs', π§π₯’authorπ₯’π§will be replaced by 'Homecooked', and the output for value will be the max of 'value - 10' and 2.
That is all currently for the Meal Docs! To get a better undertsanding of Meal, try out the Chef Creator and take a look at the official grammar for Meal.