Skip to content

Commit

Permalink
Merge pull request #29 from nicholaswilde/add-steps-with-comments
Browse files Browse the repository at this point in the history
Add steps with comments
  • Loading branch information
nicholaswilde authored Apr 28, 2022
2 parents 8e3108b + c3971b0 commit 608450e
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 32 deletions.
16 changes: 16 additions & 0 deletions docs/javascripts/mathjax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
window.MathJax = {
tex: {
inlineMath: [["\\(", "\\)"]],
displayMath: [["\\[", "\\]"]],
processEscapes: true,
processEnvironments: true
},
options: {
ignoreHtmlClass: ".*|",
processHtmlClass: "arithmatex"
}
};

document$.subscribe(() => {
MathJax.typesetPromise()
})
62 changes: 35 additions & 27 deletions docs/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,42 @@ can be used in the templates you supply.

### Sections

| Name | Description |
|---------------------------|--------------------------------------------------------------------|
| `cook.headerSection` | The main heading of the generated markdown file |
| `cook.imageSection` | The image section |
| `cook.tableSection` | The table section that consists of the serving size and total time |
| `cook.ingredientsSection` | The ingredients section |
| `cook.cookwareSection` | The cookware section |
| `cook.stepsSection` | The steps section |
| `cook.sourceSection` | The source section if `source` exists in Metadata |
| `cook.commentsSection` | The comments section |
| `cook.metadataSection` | The metadata section. This prints all values in `Metadata` |
| Name | Description |
|------------------------------------------|--------------------------------------------------------------------|
| `cook.headerSection` | The main heading of the generated markdown file |
| `cook.imageSection` | The image section |
| `cook.tableSection` | The table section that consists of the serving size and total time |
| `cook.ingredientsSection` | The ingredients section |
| `cook.cookwareSection` | The cookware section |
| `cook.stepsSection` | The steps section |
| `cook.stepsWithQuotedCommentsSection` | The steps section with comments in [block quotes][8] |
| `cook.stepsWithAdmonishedCommentsHeader` | The steps section with comments in [admonitions][9] |
| `cook.sourceSection` | The source section if `source` exists in Metadata |
| `cook.commentsSection` | The comments section |
| `cook.metadataSection` | The metadata section. This prints all values in `Metadata` |

### Components

| Name | Description |
|--------------------------|---------------------------------------------------------------------------|
| `cook.ingredientsHeader` | The ingredients header |
| `cook.ingredients` | An unordered list of the ingredients |
| `cook.cookwareHeader` | The cookware header |
| `cook.cookware` | An unordered list of cookware |
| `cook.stepsHeader` | The steps header |
| `cook.steps` | A list of steps. Each step has its own sub heading labeled as `Step #` |
| `cook.sourceHeader` | Source header |
| `cook.source` | The `source` as a single unordered list item |
| `cook.metadataHeader` | `Metadata` header |
| `cook.metadata` | An unordered list of the `Metadata`. `ImageName` and `title` are included |
| `cook.commentsHeader` | The comments header |
| `cook.comments` | An unordered list of the comments |
| `.Metadata.title` | The title of the recipe taken fromt the recipe file name. |
| `.Metadata.ImageName` | The new image name if an image file is found |
| Name | Description |
|------------------------------------------|---------------------------------------------------------------------------|
| `cook.ingredientsHeader` | The ingredients header |
| `cook.ingredients` | An unordered list of the ingredients |
| `cook.cookwareHeader` | The cookware header |
| `cook.cookware` | An unordered list of cookware |
| `cook.stepsHeader` | The steps header |
| `cook.steps` | A list of steps. Each step has its own sub heading labeled as `Step #` |
| `cook.stepsWithQuotedCommentsHeader` | The steps with block quotes header |
| `cook.stepsWithQuotedComments` | A list of steps with block quoted comments in between |
| `cook.stepsWithAdmonishedCommentsHeader` | The steps with admonitions headder |
| `cook.stepsWithAdmonishedComments` | A list of steps with comments as admonitions in between |
| `cook.sourceHeader` | Source header |
| `cook.source` | The `source` as a single unordered list item |
| `cook.metadataHeader` | The `Metadata` header |
| `cook.metadata` | An unordered list of the `Metadata`. `ImageName` and `title` are included |
| `cook.commentsHeader` | The comments header |
| `cook.comments` | An unordered list of the comments |
| `.Metadata.title` | The title of the recipe taken fromt the recipe file name. |
| `.Metadata.ImageName` | The new image name if an image file is found |

See [template.go][6] for how each key is defined.

Expand Down Expand Up @@ -317,3 +323,5 @@ delimiters. See [Text and spaces][4].
[5]: https://github.com/Masterminds/sprig
[6]: https://github.com/nicholaswilde/cook-docs/blob/main/pkg/document/template.go
[7]: https://github.com/nicholaswilde/cook-docs/issues/3
[8]: https://github.github.com/gfm/#block-quotes
[9]: https://squidfunk.github.io/mkdocs-material/reference/admonitions/
4 changes: 2 additions & 2 deletions pkg/cook/recipe_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func TestGetImagePath(t *testing.T) {
func TestMergeRecipeData(t *testing.T) {
var recipeInfo RecipeDocumentationInfo
var recipeData = cooklang.Recipe{
make([]cooklang.Step, 0),
make(map[string]string),
Steps: make([]cooklang.Step, 0),
Metadata: make(map[string]string),
}
recipeInfo.RecipeName = "Recipe"
recipeInfo.ImagePath = "testdata/recipe.jpg"
Expand Down
64 changes: 61 additions & 3 deletions pkg/document/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ func getIngredientsTemplate() string {
templateBuilder.WriteString("{{ end }}")

templateBuilder.WriteString(`{{ define "cook.ingredients" }}`)
templateBuilder.WriteString("{{ range .Steps }}{{- range .Ingredients }}\n- {{.Amount.Quantity}} {{.Amount.Unit}} {{.Name}}{{- end }}{{- end }}")
templateBuilder.WriteString("{{ range .Steps }}")
templateBuilder.WriteString("{{- range .Ingredients }}")
templateBuilder.WriteString("\n")
templateBuilder.WriteString("- {{ if .Amount.Quantity }}{{ round .Amount.Quantity 2 }} {{ .Amount.Unit }}{{ else }}some{{ end }}")
templateBuilder.WriteString(" {{ .Name }}")
templateBuilder.WriteString("{{- end }}")
templateBuilder.WriteString("{{- end }}")
templateBuilder.WriteString("{{ end }}")

templateBuilder.WriteString(`{{ define "cook.ingredientsSection" }}`)
Expand All @@ -99,9 +105,10 @@ func getCookwareTemplate() string {
templateBuilder.WriteString("{{ end }}")

templateBuilder.WriteString(`{{ define "cook.cookware" }}`)
templateBuilder.WriteString("{{ range .Steps }}{{- range .Cookware }}\n- {{.Quantity}} {{.Name}}{{- end }}{{- end }}")
templateBuilder.WriteString("{{ range .Steps }}{{- range .Cookware }}")
templateBuilder.WriteString("\n")
templateBuilder.WriteString("- {{.Quantity}} {{.Name}}{{- end }}{{- end }}")
templateBuilder.WriteString("{{ end }}")

templateBuilder.WriteString(`{{ define "cook.cookwareSection" }}`)
templateBuilder.WriteString(`{{ template "cook.cookwareHeader" . }}`)
templateBuilder.WriteString("\n")
Expand Down Expand Up @@ -130,6 +137,55 @@ func getStepsTemplate() string {
return templateBuilder.String()
}

func getStepsWithQuotedCommentsTemplate() string {
templateBuilder := strings.Builder{}

templateBuilder.WriteString(`{{ define "cook.stepsWithQuotedCommentsHeader" }}`)
templateBuilder.WriteString("## :pencil: Instructions")
templateBuilder.WriteString("{{ end }}")

templateBuilder.WriteString(`{{ define "cook.stepsWithQuotedComments" }}`)
templateBuilder.WriteString("{{ range $i, $a := .Steps }}")
templateBuilder.WriteString("\n\n### Step {{add1 $i}}")
templateBuilder.WriteString("\n\n{{ .Directions }}")
templateBuilder.WriteString("\n\n{{ range .Comments }}\n> {{.}}{{- end }}")
templateBuilder.WriteString("{{- end }}")
templateBuilder.WriteString("{{ end }}")

templateBuilder.WriteString(`{{ define "cook.stepsWithQuotedCommentsSection" }}`)
templateBuilder.WriteString(`{{ template "cook.stepsWithQuotedCommentsHeader" . }}`)
templateBuilder.WriteString(`{{ template "cook.stepsWithQuotedComments" . }}`)
templateBuilder.WriteString("{{ end }}")

return templateBuilder.String()
}

func getStepsWithAdmonishedCommentsTemplate() string {
templateBuilder := strings.Builder{}

templateBuilder.WriteString(`{{ define "cook.stepsWithAdmonishedCommentsHeader" }}`)
templateBuilder.WriteString("## :pencil: Instructions")
templateBuilder.WriteString("{{ end }}")

templateBuilder.WriteString(`{{ define "cook.stepsWithAdmonishedComments" }}`)
templateBuilder.WriteString("{{ range $i, $a := .Steps }}")
templateBuilder.WriteString("\n\n### Step {{add1 $i}}")
templateBuilder.WriteString("\n\n{{ .Directions }}")
templateBuilder.WriteString("\n\n{{ range .Comments }}")
templateBuilder.WriteString("\n!!! note")
templateBuilder.WriteString("\n{{ indent 6 . }}")
templateBuilder.WriteString("{{- end }}")
templateBuilder.WriteString("{{- end }}")
templateBuilder.WriteString("{{ end }}")

templateBuilder.WriteString(`{{ define "cook.stepsWithAdmonishedCommentsSection" }}`)
templateBuilder.WriteString(`{{ template "cook.stepsWithAdmonishedCommentsHeader" . }}`)
templateBuilder.WriteString(`{{ template "cook.stepsWithAdmonishedComments" . }}`)
templateBuilder.WriteString("{{ end }}")

return templateBuilder.String()
}

func getSourceTemplate() string {
templateBuilder := strings.Builder{}

Expand Down Expand Up @@ -252,6 +308,8 @@ func getDocumentationTemplates(recipeSearchRoot string, recipePath string, templ
getIngredientsTemplate(),
getCookwareTemplate(),
getStepsTemplate(),
getStepsWithQuotedCommentsTemplate(),
getStepsWithAdmonishedCommentsTemplate(),
getSourceTemplate(),
getMetadataTemplate(),
getCommentsTemplate(),
Expand Down

0 comments on commit 608450e

Please sign in to comment.