Cook Nutrition API

Checks & client profiles

The ck macro library

Import once, then assert. Each macro records a pass/fail check (via record_check) and renders a line.

{% import "ck" as ck %}
{% set t = macros(ingredients) %}
{{ ck.range(t.kcal, client.targets.energy_kcal, "Daily kcal") }}
{{ ck.min(t.protein_g, client.targets.protein_g, "Protein (g)") }}
{{ ck.max(t.sat_fat_g, client.targets.sat_fat_g, "Saturated fat (g)") }}
{% for ex in client.exclusions %}{{ ck.absent(ex) }}{% endfor %}
Macro Asserts
ck.min(value, target, label) value ≥ target.min
ck.max(value, target, label) value ≤ target.max
ck.range(value, target, label) target.min ≤ value ≤ target.max
ck.within(value, target, label) value within target.tol_pct % of target.max
ck.between(value, lo, hi, label) lo ≤ value ≤ hi
ck.absent(ingredient) the excluded ingredient is not present

Exclusions flag exact ingredients; for allergen-class flagging (milk, gluten, …) see the allergens section of the function reference.

Client profiles

A YAML file of targets and exclusions, passed with --client and injected as the top-level client variable:

name: Sara Mendez
exclusions: [peanut, shellfish]
targets:
  energy_kcal:     { min: 1800, max: 2200 }
  protein_g:       { min: 75 }
  sat_fat_g:       { max: 20, tol_pct: 10 }
  fiber_g:         { min: 25 }
  iron_mg:         { min: 18 }
  omega3_servings: { min: 2 }

Example profiles live in the repo under docs/examples/clients/.

Summary line

**Summary:** {{ all_checks() | selectattr("ok") | list | length }} of {{ all_checks() | length }} checks passed.

The demo exits non-zero if failed_checks() is non-empty.