Package: gorps
gorpsConversion tool around a yml cooking recipe format.The idea: The format is simple enough so that an editor can be used
instead of a GUI and this script is intended to be a "minipandoc"
for recipes.A typical recipe looks like:title: Beans with Bacon a la Bud Spencer
description: Chuck Norris? Never heard about her!
instruction: |
  Finely dice the onions and briefly sauté in hot oil together
  with the bacon.
  ...
amount: 1
amount_unit: Pan
preparation_time: 900
cooking_time: 600
source: https://www.kabeleins.ch/sosiehtsaus/essen-trinken/rezepte/bohnen-mit-speck-nach-bud-spencer
link: https://www.kabeleins.ch/sosiehtsaus/essen-trinken/rezepte/bohnen-mit-speck-nach-bud-spencer
ingredients:
- name: Finely diced bacon
  amount: 125
  unit: g
- name: Clove of garlic
  amount: 1
- name: Salami or Cabanossi
  amount: 150
  unit: g
- name: ...
notes: |
  Bud gives a damn about cream, but if you prever, serve with cream!
tags:
  category:
  - Main courseAnamountof an ingredient can beA number:- name: Clove of garlic
  amount: 1A fraction:- name: Clove of garlic
  amount: 1/3A range:- name: Clove of garlic
  amount:
    min: 2/3
    max: 1Ingredients can be grouped:ingredients:
  - name: Trimming
    ingredients:
      - name: ...
        amount: ...
        unit: ...It is also possible to include an image:image:
  fmt: image/jpeg
  data: !!binary |
    /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aWhere the binary data is the base64 encoded binary data of the image.An image/tmp/1x1.pngcan be inserted into a recipe usinggorpsset-image--pic=/tmp/1x1.pngexamples/recipes/more-beans.ymlThis will include the following in the yml file:image:
  fmt: image/png
  data: !!binary |
    ...where...is the base64 encoded content of the image file.
The image file can be encoded / decoded as follows:# Encode:base64image.png>image.b64.txt# Decode:base64-dimage.b64.txt>image.pngAn image also can be extracted from a recipe:gorpsextract-image-o/tmp/1x1.pngexamples/recipes/more-beans.ymlSupported Formats:Import:AboveymlformatGourmetxmlExport:The aboveymlformatMarkdownsvgxml(via templates, e.g. XSL-FO xml output)openrecipessqlite and xml (not
installed by default)htmlgraph LR
  yml --> gorps{gorps} --> md & yml & svg & xml & html & or_xml[openrecipes xml] & or_sql[openrecipes sql]
  xml --> fop{fop} --> pdf
  html --> weasyprint{weasyprint} --> pdfInstallRequirement: python >= 3.9.pipinstallgorps# or first clone / cd, then:pipinstall.With support foropenrecipes:pipinstall--install-option="--extras-require=openrecipes"gorps# or first clone / cd, then:pipinstall.[openrecipes]Usage - ExamplessvgTo export the folderexamples/recipes/` using a templateexamples/svg/template.svg:gorpsexport--template=examples/svg/template.svg-o/tmp/out.svgexamples/recipes/xmlIn this advanced example, we compose the recipes fromexamples/recipesto a menu card.The templateexamples/menu-card/xml-fo/template.fo.xmlis used. This specific template expects to be used together with the--group-byoption (recipes should be grouped by category).
Also, we are specifying, that we only want to include the groupsStarters,Main coursesandDessert(--groupoptions).
With the--variableoption we pass to the template some other
required parameters, like logos for categories, fonts and more.
The example also shows, how to filter the source recipes by title
(--titleoptions).gorpsexport\--templateexamples/menu-card/xml-fo/template.fo.xml\--group-by'tags["category"]'\--groupStarters\--group"Main courses"\--groupDessert\--variable-fileexamples/menu-card/xml-fo/variables.json\--title"Beans with Bacon a la Bud Spencer"\--title"More Beans"\-o/tmp/menucard.fo.xml\examples/recipes/The resultingfo.xmlcan then be further processed byApache fopto a pdf:cp-rexamples/menucard/img/tmp
fop/tmp/menucard.fo.xml/tmp/menucard.pdfNote: The resulting xml file will refer to the fontsLinux LibertineandLinux Biolinumwhich are part of theLibertine Open Fonts Project.ℹ️ If you want to use custom fonts, you can specify a font config like
this:fop-cfonts.cfg/tmp/menucard.fo.xml/tmp/menucard.pdfwherefonts.cfglooks like:<?xml version="1.0"?><fopversion="1.0"><renderers><renderermime="application/pdf"><fonts><directory>/path/to/fonts</directory><auto-detect/></fonts></renderer></renderers></fop>The template syntax is inspired byvue.js:
Currently, the following directives are implemented:Text
Interpolation<span>Title: {{ recipe.title }}</span>v-if(Conditionally render an element based on the truthy-ness of the expression value)<divv-if="recipe.ingredients">{{ recipe.title }}</div>v-for(Render the element block multiple times based on the source data)<divv-for="recipe in recipes">{{ recipe.title }}</div>Tuple unpacking is also possible:<divv-for="group, recipes in groups.items()">{{ group }}: {{ recipes[0].title }}</div>v-bind(Dynamically bind one or more attributes to an element)<!-- bind an attribute --><av-bind:href="recipe.link">Link</a><!-- bind a dict of attributes --><divv-bind="{ 'id': '1', 'class': 'X'}"></div><template>onv-ifandv-forhtmlMenu cardThis is a slight variant of the xml fo example from above.
This time, we use html as output format and make use of the--grouped-titlesoption, to manually group recipes by their titles.
Also,--filter-ingredientis used, to remove "obvious" ingredients
from the ingredient list.gorpsexport\--templateexamples/menu-card/html/menucard.template.html\-Vtitle="Beans & Beans"\--filter-ingredientSalt\--filter-ingredientPepper\--grouped-titlesexamples/menu-card/html/grouped_titles.json\-o/tmp/menucard.html\examples/recipes/The resulting html can be further processed to a pdf by
e.g.weasyprint:cp-rexamples/menucard/imgexamples/menucard/html/style.css/tmp
weasyprint/tmp/menucard.html/tmp/menucard.pdfNote: see the comment about fonts from the xml fo example.webHere, we export a recipe to html, using the same template syntax as
for xml:gorpsexport\--templateexamples/html/template.html\-o/tmp/beans.html\examples/recipes/beans.ymlopenrecipesThere are two possibilities: either direct export to the sqlite
database file or export to an.openrecipexml file.sqlTo sync to an openrecipes db on an android phone, first pull the db
via adb:adbroot
adbpull/data/user/0/org.jschwab.openrecipes/files/database.db/tmp/Then export all recipes to the sqlite db:gorpsexport--fmtopenrecipes-o/tmp/database.dbexamples/recipesFinally, replace the db on the phone with the extended version:adbpush/tmp/database.db/data/user/0/org.jschwab.openrecipes/files/database.db
adbkill-server# terminate adbopenrecipe xmlgorpsexport--fmtopenrecipes-xml-o/tmp/out/examples/recipesmarkdownTo export the folderexamples/recipes/to
individual.mdfiles in/tmp/out/:gorpsexport--fmtmarkdown-o/tmp/out/examples/recipes/