add docs and examples

This commit is contained in:
Emi Vasilek 2023-11-28 12:29:49 +00:00
parent 67cb69000b
commit 3e46ae89b0
18 changed files with 407 additions and 0 deletions

View file

@ -0,0 +1,51 @@
# 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` and `g` 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](quickstart.md).
`🗎 myrecipes/recipes/pancakes.yaml:`
```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:
```sh
$ comfyrecipes generate-units
```
This will generate a minimal units.yaml:
`🗎 myrecipes/units.yaml:`
```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:`
```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](../reference/units.md)