1.5 KiB
1.5 KiB
Units
Each recipe ingredient has a string unit assigned to it. This is great, but a centralized list of all alowed units with some additional properties has several advantages:
- spelling mistakes are not silently ignored, if you make a mistake in the ingredient unit name, comfyrecipes will warn you that it's not on the units list
gram
andg
can refer to the same unit (using aliases)- we can tell comfyrecipes unit conversion rates (for example 1000 gram = 1 kilogram) which it can then use for example for calculating prices
This example will use the final example from Quick Start.
🗎 myrecipes/recipes/pancakes.yaml:
{{#include ../../examples/firstrealrecipe.yaml}}
- myrecipes/
- recipes/
- pancakes.yaml
...
- units.yaml (we will be creating this file)
If you don't want to write the file manually, we can generate it using:
$ comfyrecipes generate-units
This will generate a minimal units.yaml:
🗎 myrecipes/units.yaml:
- name: cup
- name: piece
- name: tablespoon
Now, let's say we would want to call tablespoon
just tbsp
, we can add an alias:
🗎 myrecipes/units.yaml:
- name: cup
- name: piece
- name: tablespoon
aliases:
- tbsp
Now we can rename the tablespoon
unit in the recipe to tbsp
and it will reference the tablespoon
unit.
For a full reference for what a recipe yaml can contain, please see the Units Reference