help-recutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[help-recutils] looping constructs for templating


From: David J Patrick
Subject: [help-recutils] looping constructs for templating
Date: Sun, 15 May 2011 20:03:32 -0400
User-agent: Mutt/1.5.20 (2009-06-14)

Hi
I'm in the process of working up an application for recutils, where I
(ambitiously) want to track and cross-reference suppliers, ingredients,
recipes and products. The desired outputs include, inventory lists, recipe
cards, product labels etc. I'm combining them because they are all
interrelated, with products potentially made of recipes, which are made
from ingredients which come from suppliers.

the initial "schema" (still missing many definition and constraints) is as 
follows;

====================================================
# Supplier, Ingredient, Recipe, Products recfile outline

%rec: supplier
%doc: our source of ingredients and products
%mandatory: name
# code
# contact
# category
# phone1
# phone2
# email
# website
# image_url
# address
# geo
# delivery_min
# delivery_date
# delivery_freq
# delivery_note
# note

type: supplier
name: Linuxcaffe
contact: David J Patrick
category: self
phone: 416-534-2116
email: address@hidden
website: linuxcaffe.ca
address: 326 Harbord St

type: supplier
name: No Frills
contact: Mike Nagero
category: retail
note: requires vehicle

%rec: ingredient
%Mandatory: name supplier
#  name
#  code
#  cost
#  unit
#  on_hand
#  minimum
#  shelf
#  shelf_life
#  supplier
#  note

type: ingredient 
name: NF Club Pack hot chocolate mix
supplier: No Frills

type: ingredient 
name: cinnamon powder
supplier: No Frills

type: ingredient 
name: ginger powder
supplier: Strictly Bulk

type: ingredient 
name: cayenne powder
supplier: Strictly Bulk

%rec: recipe
%mandatory: name ingredient step portions
# code
# desc
# source
# image_url
# time
# ingredient_amount
# ingredient_unit
# ingredient
# ingredient_amount
# ingredient_unit
# step
# step
# note

type: recipe
name: Linuxcaffe Hot Chocolate v1.0
code: HD-CHOC
source: djp
desc: Thick, sweet and spicy, 
+ this Mayan style hot chocolate is a winter-time favorite.
ingredient:  NF Club Pack hot chocolate mix
ingredient_amount: 1
ingredient_unit: can
ingredient: cinnamon powder
ingredient_amount: 3
ingredient_unit: tbs
ingredient: ginger powder
ingredient_amount: 1
ingredient_unit: tsp
ingredient: nutmeg powder
ingredient_amount: .5
ingredient_unit: tsp
ingredient: cayenne powder
ingredient_amount: .25
ingredient_unit: tsp
ingredient: milk
ingredient_amount: 10
ingredient_unit: floz
step: remove label from NF hot chocolate can
step: add spices
step: mix well using potato masher, 
+ then shaking and rolling
step: put 2 tbs mix in steampot 
+ with 10oz milk
step: mix well with fork
step: steam till hot, mixing last of floating powder
step: serve with mini-marshmallows and cocoa powder

# products
# name
# desc
# image_url
# supplier
# recipe
# code
# cost
# price
# shelf
# shelf_life
# minimum
# note

==============================================================

and with the command
recsel -t recipe doc/products.recfile.otl | recfmt -f doc/recipe.tmpl|uniq

and the template
{{name}} recipe
{{desc}}

-{{ingredient_amount[1]}} {{ingredient_unit[1]}} {{ingredient[1]}}
-{{ingredient_amount[2]}} {{ingredient_unit[2]}} {{ingredient[2]}}
-{{ingredient_amount[3]}} {{ingredient_unit[3]}} {{ingredient[3]}}
-{{ingredient_amount[4]}} {{ingredient_unit[4]}} {{ingredient[4]}}
-{{ingredient_amount[5]}} {{ingredient_unit[5]}} {{ingredient[5]}}
-{{ingredient_amount[6]}} {{ingredient_unit[6]}} {{ingredient[6]}}
-{{ingredient_amount[7]}} {{ingredient_unit[7]}} {{ingredient[7]}}
-
-{{step[1]}}
-{{step[2]}}
-{{step[3]}}
-{{step[4]}}
-{{step[5]}}
-{{step[6]}}
-{{step[7]}}
{{note}}

I can generate a reasonable facsimile of a recipe

Linuxcaffe Hot Chocolate v1.0 recipe
Thick, sweet and spicy, 
this Mayan style hot chocolate is a winter-time favorite.

-3 tbs cinnamon powder
-1 tsp ginger powder
-.5 tsp nutmeg powder
-.25 tsp cayenne powder
-10 floz milk
-  
-add spices
-mix well using potato masher, 
then shaking and rolling
-put 2 tbs mix in steampot 
with 10oz milk
-mix well with fork
-steam till hot, mixing last of floating powder
-serve with mini-marshmallows and cocoa powder
-


but obviously, this is less than ideal.

What has been suggested to me (by someone who really knows databases and
such) is that recfmt and the associated templates are missing looping
constructs that would allow templated output of multiply occurring fields
without resorting to external scripted kludges or using uniq..

Any ideas on how I might address this, or how recfmt might be modified to
handle it ?

thanks a lot,
djp



reply via email to

[Prev in Thread] Current Thread [Next in Thread]