cooklang

package module
v0.0.0-...-a60c800 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2023 License: MIT Imports: 5 Imported by: 0

README

cooklang-go    Go Report Card

This project aims to be a reimplementation, and eventually extension, of the original CooklangCLI, written in Go.

The root package provides the parser and the requisite types under the package name cooklang.

I will be maintaing a project structure that allows for module imports from pkg.dev.go to enable Cooklang utilities such as parsing, printing and creation, as a library.

Current State

At present, the parser works and passes all canonical tests listed here.


in progress
  • CLI
    • cook init
    • cook read
    • cook shopping list
    • cook server
todo
  • Extensions (Images, Shopping List, Parse comments)
  • Shopping List Parser

Author

Jayden Dumouchel -- jdumouch@ualberta.ca | rottenfishbone@pm.me

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 Cookware

type Cookware component

func (Cookware) ToString

func (x Cookware) ToString() string

Converts cookware to a string, with its name followed by qty and units if they exist.

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

type Metadata struct {
	Tag  string
	Body string
}

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

func ParseRecipe(name string, data *[]byte) Recipe

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

func ParseRecipeString(name string, data string) Recipe
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).

type Text

type Text string

Text is a string wrapper (to allow for safe inclusion to Chunk interface)

func (Text) ToString

func (x Text) ToString() string

Unwraps Text chunk into a string

type Timer

type Timer component

func (Timer) ToString

func (x Timer) ToString() string

Converts a timer to a string, with its name followed by qty and units if they exist.

Directories

Path Synopsis
cmd
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL