-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoc.go
More file actions
146 lines (146 loc) · 4.22 KB
/
doc.go
File metadata and controls
146 lines (146 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Package cooklang provides a parser and tools for working with Cooklang recipe files.
//
// Cooklang is a markup language for cooking recipes that makes it easy to manage recipes
// as plain text files while providing rich semantic information about ingredients,
// cookware, timers, and instructions.
//
// # Basic Usage
//
// Parse a recipe file:
//
// recipe, err := cooklang.ParseFile("lasagna.cook")
// if err != nil {
// log.Fatal(err)
// }
// fmt.Printf("Recipe: %s (serves %.0f)\n", recipe.Title, recipe.Servings)
//
// # Working with Ingredients
//
// Extract and consolidate ingredients for shopping lists:
//
// ingredients := recipe.GetIngredients()
// consolidated, err := ingredients.ConsolidateByName("")
// if err != nil {
// log.Fatal(err)
// }
//
// for _, ing := range consolidated.Ingredients {
// fmt.Printf("- %s: %.1f %s\n", ing.Name, ing.Quantity, ing.Unit)
// }
//
// # Unit Conversion
//
// Convert ingredients between measurement systems:
//
// // Convert to metric
// shoppingList, err := recipe.GetMetricShoppingList()
//
// // Convert to US customary
// shoppingList, err := recipe.GetUSShoppingList()
//
// // Convert individual ingredients
// ingredient := &cooklang.Ingredient{Name: "flour", Quantity: 2, Unit: "cup"}
// converted, err := ingredient.ConvertTo("g")
//
// # Shopping Lists
//
// Create shopping lists from multiple recipes:
//
// recipe1, _ := cooklang.ParseFile("pasta.cook")
// recipe2, _ := cooklang.ParseFile("salad.cook")
// recipe3, _ := cooklang.ParseFile("dessert.cook")
//
// shoppingList, err := cooklang.CreateShoppingList(recipe1, recipe2, recipe3)
// if err != nil {
// log.Fatal(err)
// }
//
// // Scale for meal prep
// doubled := shoppingList.Scale(2.0)
//
// // Print the list
// for ingredient, amount := range doubled.ToMap() {
// fmt.Printf("☐ %s: %s\n", ingredient, amount)
// }
//
// # Metadata Management
//
// Edit recipe frontmatter metadata:
//
// editor, err := cooklang.NewFrontmatterEditor("recipe.cook")
// if err != nil {
// log.Fatal(err)
// }
//
// editor.SetMetadata("title", "Improved Lasagna")
// editor.SetMetadata("servings", "8")
// editor.SetMetadata("tags", "italian, pasta, main course")
// editor.SetMetadata("difficulty", "medium")
//
// if err := editor.Save(); err != nil {
// log.Fatal(err)
// }
//
// # Rendering Recipes
//
// Render recipes in different formats:
//
// import "github.com/hilli/cooklang/renderers"
//
// recipe, _ := cooklang.ParseFile("recipe.cook")
//
// // Render as Markdown
// markdown := recipe.RenderWith(renderers.MarkdownRenderer{})
// fmt.Println(markdown)
//
// // Render as HTML
// html := recipe.RenderWith(renderers.HTMLRenderer{})
//
// // Set a custom renderer
// recipe.SetRenderer(renderers.CooklangRenderer{})
// cooklangText := recipe.Render()
//
// # Recipe Structure
//
// Recipes are organized as linked lists of steps, where each step contains a linked list
// of components (ingredients, instructions, timers, cookware). This structure allows for
// efficient traversal and manipulation:
//
// // Walk through all steps
// currentStep := recipe.FirstStep
// stepNum := 1
// for currentStep != nil {
// fmt.Printf("Step %d:\n", stepNum)
//
// // Walk through components in this step
// component := currentStep.FirstComponent
// for component != nil {
// switch c := component.(type) {
// case *cooklang.Ingredient:
// fmt.Printf(" Add %s (%.1f %s)\n", c.Name, c.Quantity, c.Unit)
// case *cooklang.Instruction:
// fmt.Printf(" %s\n", c.Text)
// case *cooklang.Timer:
// fmt.Printf(" Wait for %s %s\n", c.Duration, c.Unit)
// case *cooklang.Cookware:
// fmt.Printf(" Using: %s\n", c.Name)
// }
// component = component.GetNext()
// }
//
// currentStep = currentStep.NextStep
// stepNum++
// }
//
// # Cooklang Syntax
//
// The parser supports standard Cooklang syntax:
//
// - Ingredients: @flour{500%g}, @salt{}, @milk{2%cups}(room temperature)
// - Cookware: #pot{}, #bowl{2}, #oven{}(preheated)
// - Timers: ~{10%minutes}, ~boil{15%min}
// - Comments: -- This is a comment
// - Metadata: YAML frontmatter between --- delimiters
//
// See https://cooklang.org for full specification details.
package cooklang