Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Chunk ¶
type Chunk interface { ToString() string // contains filtered or unexported methods }
Chunks are the building blocks of recipe steps. They are a union of Text, Ingredient, Timer and Cookware.
type Ingredient ¶
type Ingredient component
func (Ingredient) ToString ¶
func (x Ingredient) ToString() string
Converts an ingredient to a string, with its name followed by qty and units if they exist.
type Metadata ¶
Metadata is arbitrary information about a recipe, consisting simply of a tag and a body.
While some implementations only allow metadata at the start, the spec defines it in equal precedence to a `Step`.
It may be prudent to further parse metadata before displaying.
type Recipe ¶
type Recipe struct { Name string Metadata []Metadata Ingredients []Ingredient Cookware []Cookware Timer []Timer Steps []Step }
Recipes consist primarily of Metadata and Steps. Steps are stored sequentially and offer a continuous construction of the parsed `.cook` file.
Additionally, the Ingredients, Cookware and Timer members provide a manifest for each of the respective item classes.
Recipes can be easily parsed from a string using the function `ParseRecipe`.
func ParseRecipe ¶
Parses a byte array containing a recipe following the cooklang specifications and returns as a `Recipe` struct
Example ¶
recipeText := `Preheat #deep fryer{} to 190°C. Slice @potatoes{3} into 1/4" strips. Optionally, blanch in boiling @water{2%cups}. Drop into deep fryer for ~{7%mins}. Remove from fryer and sprinkle @pink salt{} Enjoy with @ketchup, or mix in @mayonnaise{equal parts} for fancy sauce.` data := []byte(recipeText) recipe := ParseRecipe("Fries", &data) fmt.Println(recipe.Ingredients)
Output: [{potatoes 3 3 } {water 2 2 cups} {pink salt -Inf } {ketchup -Inf } {mayonnaise equal parts -Inf }]
func ParseRecipeString ¶
Example ¶
recipeText := `Preheat #deep fryer{} to 190°C. Slice @potatoes{3} into 1/4" strips. Optionally, blanch in boiling @water{2%cups}. Drop into deep fryer for ~{7%mins}. Remove from fryer and sprinkle @pink salt{} Enjoy with @ketchup, or mix in @mayonnaise{equal parts} for fancy sauce.` recipe := ParseRecipeString("Fries", recipeText) fmt.Println(recipe.Ingredients)
Output: [{potatoes 3 3 } {water 2 2 cups} {pink salt -Inf } {ketchup -Inf } {mayonnaise equal parts -Inf }]
type Step ¶
type Step []Chunk
A Step is one part of a recipe, consisting of a set of chunks which can be read in order to build a human readable recipe.
Ingredients, Cookware and Timer are kept as structs to allow for post processing (such as text formatting).