7.3. Using recipes

You can use a Pantry XML file that contains recipes just as you would use any Pantry file. As we discussed earlier when we talked about creating foods, I would recommend adding the contents of a Pantry XML file to a Pantry native file, because Pantry works with native files much faster than it works with XML files.

Example 7.6. Using a Pantry XML file

$ pantry --name "Easy Corn Bread" --print traits-units-nuts \
> pantry.xml
Easy Corn Bread
Group: Baked Products
1 serving (73g)
   serving
Nutrient                  Amount         %G     %TOT  
-------------------------------------------------------
Calories                  197  kcal       10     100   
Total Fat                 8    g          12     100   
Saturated Fat             1    g          5      100   
Cholesterol               26   mg         9      100   
Sodium                    233  mg         10     100   
Total Carbohydrate        28   g          9      100   
Dietary Fiber             1    g          5      100   
Sugars                    7    g          NA     100   
Protein                   4    g          8      100   
Vitamin A                 100  IU         2      100   
Vitamin C                 0    mg         0      100   
Calcium                   113  mg         11     100   
Iron                      1    mg         8      100   

Example 7.7. Adding a recipe to a Pantry native file

$ pantry --name "Easy Corn Bread" --add master pantry.xml
$ pantry --name "Easy Corn Bread" --print names master
Easy Corn Bread

Now that you know how to create recipes, you will find that there are several additional reports that will come in handy when you are using the --print option. You can use all the reports you have already learned about; they work identically with both regular foods and with recipes. The most handy additional report is the recipe report. It gives you a plain-text representation of a recipe, along with some additional handy information such as the weight of each ingredient:

Example 7.8. The recipe report

$ pantry --name "Easy Corn Bread" --print recipe master
Easy Corn Bread
One square pan (658g)

1 1/4 cup (5.511oz, 156g) Wheat flour, white, all-purpose, enriched, unbleached
3/4 cup (3.228oz, 92g) Cornmeal, whole-grain, yellow
1/4 cup (1.764oz, 50g) Sugars, granulated
2 tsp (0.325oz, 9g) Leavening agents, baking powder, double-acting, straight phosphate
1/2 tsp (0.106oz, 3g) Salt, table
1 cup (8.607oz, 244g) Milk, reduced fat, fluid, 2% milkfat, with added vitamin A
1/4 cup (1.922oz, 54g) Oil, canola and soybean
1 large (1.764oz, 50g) Egg, whole, raw, fresh

 Heat oven to 400 degrees F. Grease 8 or 9-inch pan. combine dry ingredients. Stir in milk, oil, and egg, mixing just until dry ingredients are moistened. Pour batter into prepared pan. Bake 20 to 25 minutes or until light golden brown and wooden pick inserted in center comes out clean. Serve warm. 
 

You can get the same information by using --print names-yield-blank-ingredients-blank-directions, but --print recipe is a bit shorter to type. You can use the other reports, such as ingredients, if you're only interested in a subset of the information. Of course, you can combine the recipe report with other Pantry reports. You can also use handy utilities such as fold, which should already be installed if you are using a GNU operating system.[19] This gives you nice printer-ready output that you can feed to lp:

Example 7.9. Using the recipe report with other cool stuff

$ pantry --name "Easy Corn Bread" --print recipe-blank-traits- \
> nuts master | fold --spaces --width=68
Easy Corn Bread
One square pan (658g)

1 1/4 cup (5.511oz, 156g) Wheat flour, white, all-purpose, 
enriched, unbleached
3/4 cup (3.228oz, 92g) Cornmeal, whole-grain, yellow
1/4 cup (1.764oz, 50g) Sugars, granulated
2 tsp (0.325oz, 9g) Leavening agents, baking powder, double-acting, 
straight phosphate
1/2 tsp (0.106oz, 3g) Salt, table
1 cup (8.607oz, 244g) Milk, reduced fat, fluid, 2% milkfat, with 
added vitamin A
1/4 cup (1.922oz, 54g) Oil, canola and soybean
1 large (1.764oz, 50g) Egg, whole, raw, fresh

 Heat oven to 400 degrees F. Grease 8 or 9-inch pan. combine dry 
ingredients. Stir in milk, oil, and egg, mixing just until dry 
ingredients are moistened. Pour batter into prepared pan. Bake 20 
to 25 minutes or until light golden brown and wooden pick inserted 
in center comes out clean. Serve warm. 
 
Easy Corn Bread
Group: Baked Products
1 serving (73g)
Nutrient                  Amount         %G     %TOT  
-------------------------------------------------------
Calories                  197  kcal       10     100   
Total Fat                 8    g          12     100   
Saturated Fat             1    g          5      100   
Cholesterol               26   mg         9      100   
Sodium                    233  mg         10     100   
Total Carbohydrate        28   g          9      100   
Dietary Fiber             1    g          5      100   
Sugars                    7    g          NA     100   
Protein                   4    g          8      100   
Vitamin A                 100  IU         2      100   
Vitamin C                 0    mg         0      100   
Calcium                   113  mg         11     100   
Iron                      1    mg         8      100   

Now that you know how to create both foods and recipes, you can create them both in the same Pantry XML file.



[19] Non-GNU UNIX systems will likely have a fold utility installed, but it might not have handy options such as --spaces. Windows won't have fold at all.