Documentation
¶
Overview ¶
Package cooklang provides a parser for .cook defined recipes as defined in https://cooklang.org/docs/spec/
Index ¶
Examples ¶
Constants ¶
const ( ItemTypeText ItemType = "text" ItemTypeComment ItemType = "comment" ItemTypeCookware ItemType = "cookware" ItemTypeIngredient ItemType = "ingredient" ItemTypeTimer ItemType = "timer" CommentTypeLine CommentType = 1 CommentTypeBlock CommentType = 2 CommentTypeEndLine CommentType = 3 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Comment ¶ added in v0.2.0
type Comment struct {
Type CommentType
Value string
}
Comment represents comment text
type CommentType ¶ added in v0.2.0
type CommentType int
CommentType defines what type is the comment
type Cookware ¶
type Cookware struct {
IsNumeric bool // true if the amount is numeric
Name string // cookware name
Quantity float64 // quantity of the cookware
QuantityRaw string // quantity of the cookware as raw text
}
Cookware represents a cookware item
type CookwareV2 ¶ added in v0.2.0
type Ingredient ¶
type Ingredient struct {
Name string // name of the ingredient
Amount IngredientAmount // optional ingredient amount (default: 1)
}
Ingredient represents a recipe ingredient
type IngredientAmount ¶
type IngredientAmount struct {
IsNumeric bool // true if the amount is numeric
Quantity float64 // quantity of the ingredient
QuantityRaw string // quantity of the ingredient as raw text
Unit string // optional ingredient unit
}
IngredientAmount represents the amount required of an ingredient
type IngredientV2 ¶ added in v0.2.0
type ParseV2Config ¶ added in v0.2.0
type ParseV2Config struct {
IgnoreTypes []ItemType
}
type ParserV2 ¶ added in v0.2.0
type ParserV2 struct {
// contains filtered or unexported fields
}
func NewParserV2 ¶ added in v0.2.0
func NewParserV2(config *ParseV2Config) *ParserV2
func (*ParserV2) ParseStream ¶ added in v0.2.0
ParseStream parses a cooklang recipe text stream and returns the recipe or an error
type Recipe ¶
type Recipe struct {
Steps []Step // list of steps for the recipe
Metadata Metadata // metadata of the recipe
}
Recipe contains a cooklang defined recipe
func ParseStream ¶
ParseStream parses a cooklang recipe text stream and returns the recipe or an error
func ParseString ¶
ParseString parses a cooklang recipe string and returns the recipe or an error
Example ¶
recipe := `>> servings: 6
Make 6 pizza balls using @tipo zero flour{820%g}, @water{533%ml}, @salt{24.6%g} and @fresh yeast{1.6%g}. Put in a #fridge for ~{2%days}.
Set #oven to max temperature and heat #pizza stone{} for about ~{40%minutes}.
Make some tomato sauce with @chopped tomato{3%cans} and @garlic{3%cloves} and @dried oregano{3%tbsp}. Put on a #pan and leave for ~{15%minutes} occasionally stirring.
Make pizzas putting some tomato sauce with #spoon on top of flattened dough. Add @fresh basil{18%leaves}, @parma ham{3%packs} and @mozzarella{3%packs}.
Put in an #oven for ~{4%minutes}.`
r, _ := cooklang.ParseString(recipe)
j, _ := json.MarshalIndent(r, "", " ")
fmt.Println(string(j))
Output: { "Steps": [ { "Directions": "Make 6 pizza balls using tipo zero flour, water, salt and fresh yeast. Put in a fridge for 2 days.", "Timers": [ { "Name": "", "Duration": 2, "Unit": "days" } ], "Ingredients": [ { "Name": "tipo zero flour", "Amount": { "IsNumeric": true, "Quantity": 820, "QuantityRaw": "820", "Unit": "g" } }, { "Name": "water", "Amount": { "IsNumeric": true, "Quantity": 533, "QuantityRaw": "533", "Unit": "ml" } }, { "Name": "salt", "Amount": { "IsNumeric": true, "Quantity": 24.6, "QuantityRaw": "24.6", "Unit": "g" } }, { "Name": "fresh yeast", "Amount": { "IsNumeric": true, "Quantity": 1.6, "QuantityRaw": "1.6", "Unit": "g" } } ], "Cookware": [ { "IsNumeric": false, "Name": "fridge", "Quantity": 1, "QuantityRaw": "" } ], "Comments": null }, { "Directions": "Set oven to max temperature and heat pizza stone for about 40 minutes.", "Timers": [ { "Name": "", "Duration": 40, "Unit": "minutes" } ], "Ingredients": [], "Cookware": [ { "IsNumeric": false, "Name": "oven", "Quantity": 1, "QuantityRaw": "" }, { "IsNumeric": false, "Name": "pizza stone", "Quantity": 1, "QuantityRaw": "" } ], "Comments": null }, { "Directions": "Make some tomato sauce with chopped tomato and garlic and dried oregano. Put on a pan and leave for 15 minutes occasionally stirring.", "Timers": [ { "Name": "", "Duration": 15, "Unit": "minutes" } ], "Ingredients": [ { "Name": "chopped tomato", "Amount": { "IsNumeric": true, "Quantity": 3, "QuantityRaw": "3", "Unit": "cans" } }, { "Name": "garlic", "Amount": { "IsNumeric": true, "Quantity": 3, "QuantityRaw": "3", "Unit": "cloves" } }, { "Name": "dried oregano", "Amount": { "IsNumeric": true, "Quantity": 3, "QuantityRaw": "3", "Unit": "tbsp" } } ], "Cookware": [ { "IsNumeric": false, "Name": "pan", "Quantity": 1, "QuantityRaw": "" } ], "Comments": null }, { "Directions": "Make pizzas putting some tomato sauce with spoon on top of flattened dough. Add fresh basil, parma ham and mozzarella.", "Timers": [], "Ingredients": [ { "Name": "fresh basil", "Amount": { "IsNumeric": true, "Quantity": 18, "QuantityRaw": "18", "Unit": "leaves" } }, { "Name": "parma ham", "Amount": { "IsNumeric": true, "Quantity": 3, "QuantityRaw": "3", "Unit": "packs" } }, { "Name": "mozzarella", "Amount": { "IsNumeric": true, "Quantity": 3, "QuantityRaw": "3", "Unit": "packs" } } ], "Cookware": [ { "IsNumeric": false, "Name": "spoon", "Quantity": 1, "QuantityRaw": "" } ], "Comments": null }, { "Directions": "Put in an oven for 4 minutes.", "Timers": [ { "Name": "", "Duration": 4, "Unit": "minutes" } ], "Ingredients": [], "Cookware": [ { "IsNumeric": false, "Name": "oven", "Quantity": 1, "QuantityRaw": "" } ], "Comments": null } ], "Metadata": { "servings": "6" } }
Example (ToString) ¶
recipeIn := `>> servings: 6
Make 6 pizza balls using @tipo zero flour{820%g}, @water{533%ml}, @salt{24.6%g} and @fresh yeast{1.6%g}. Put in a #fridge for ~{2%days}.
Set #oven to max temperature and heat #pizza stone{} for about ~{40%minutes}.
Make some tomato sauce with @chopped tomato{3%cans} and @garlic{3%cloves} and @dried oregano{3%tbsp}. Put on a #pan and leave for ~{15%minutes} occasionally stirring.
Make pizzas putting some tomato sauce with #spoon on top of flattened dough. Add @fresh basil{18%leaves}, @parma ham{3%packs} and @mozzarella{3%packs}.
Put in an #oven for ~{4%minutes}.`
r, _ := cooklang.ParseString(recipeIn)
fmt.Print(r)
Output: >> servings: 6 Make 6 pizza balls using tipo zero flour, water, salt and fresh yeast. Put in a fridge for 2 days. Set oven to max temperature and heat pizza stone for about 40 minutes. Make some tomato sauce with chopped tomato and garlic and dried oregano. Put on a pan and leave for 15 minutes occasionally stirring. Make pizzas putting some tomato sauce with spoon on top of flattened dough. Add fresh basil, parma ham and mozzarella. Put in an oven for 4 minutes.
type RecipeV2 ¶ added in v0.2.0
type RecipeV2 struct {
Steps []StepV2 `json:"steps"` // list of steps for the recipe
Metadata Metadata `json:"metadata"` // metadata of the recipe
}
RecipeV2 contains a cooklang defined recipe
type Step ¶
type Step struct {
Directions string // step directions as plain text
Timers []Timer // list of timers in the step
Ingredients []Ingredient // list of ingredients used in the step
Cookware []Cookware // list of cookware used in the step
Comments []string // list of comments
}
Step represents a recipe step
type Text ¶ added in v0.2.0
type Text struct {
Value string
}