Skip to content

feat: a menu can use another menu as one of its meals - #609

Merged
LeMyst merged 1 commit into
cooklang:mainfrom
LeMyst:feat/menu-in-menu
Oct 10, 2026
Merged

LeMyst merged 1 commit into
cooklang:mainfrom
LeMyst:feat/menu-in-menu

Conversation

@LeMyst

@LeMyst LeMyst commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Part of #385 (step 3 of the proposal: a whole menu as a day's meal).

A menu can use another menu as one of its meals, the way it uses a recipe:

Brunch: \
- @./Brunches/Sunday.menu{4%servings} \
- @orange juice{1%l}

What happened before

On upstream main, a menu Week.menu referencing @./Brunches/Sunday.menu{4%servings} (a menu with servings: 2) and @./Brunches/Sunday{2}:

Before Now
Parser, resolve_reference A reference like any other; cooklang-find finds the .menu with or without the extension unchanged
cook shopping-list Week.menu Follows it: its free-hand ingredients and recipes, cycles reported once unchanged (now tested)
cook doctor validate Accepts it unchanged (now tested)
add_menu + shopping list Nested as a recipe whose references are followed — right totals. A cycle A → B → A counted A's contents twice on the web list (each nested entry is followed in a request of its own, so the core cycle guard starts afresh at B) the reference back to the menu being added is dropped when it is stored: counted once, as the CLI does
GET /api/menus/Week.menu "path": "./Brunches/Sunday.menu.cook" and "./Brunches/Sunday.cook" "path": "./Brunches/Sunday.menu", "menu": true (left out for recipes)
Menu page Linked /recipe/Brunches/Sunday.menu or /recipe/Brunches/Sunday (a recipe of the same name would win); label Brunches › Sunday.menu; in cook build web, recipe/Brunches/Sunday.menu.html, which does not exist /recipe/Brunches/Sunday.menu, menu/Brunches/Sunday.html in a static site; label without .menu and a Menu tag
Editor's Add recipe (menu mode) Recipes only Menus too (never the menu being edited); inserts @./Weekly Plan.menu{}. Recipe reference in a recipe still offers recipes only

Scaling is the recipes' rule: {2} multiplies, {4%servings} scales against the referenced menu's servings, and the menu page links it with ?servings= like a recipe.

Design

  • RecipeInfo (util::menu_scale) learns is_menu; the menu page, the menu API and add_menu already resolve every reference through it.
  • reference_path / reference_label in web::templates build the link and label, so menu.html no longer spells them twice.
  • I first rewrote add_menu to flatten a nested menu's recipes into the list, then checked the old behaviour and found the totals already right through the core expansion; that rewrite is not in this PR. Only the cycle filter is.
  • Not touched: menu pages link @../X references to /recipe/../X (separate bug, needs its own issue).

Screenshots

Menu page Add recipe in a menu
page picker

Tests

  • tests/menu_in_menu_test.rs (isolated config): the menu API (menu, path, scale, recipes unchanged), the page links, the shopping list totals for a menu used twice (with and without .menu), an A → B → A cycle counted once, cook shopping-list, cook doctor validate.
  • Unit: reference_path / reference_label for recipes, menus, static sites.
  • Playwright: menu-editor.spec.ts — the picker offers other menus in a menu and inserts .menu; never in a recipe.
  • cargo fmt, cargo clippy --all-targets (and --no-default-features: only the warnings already on main), cargo test clean. Full chromium run: all pass except shopping-list-live (passes with --workers=1) and recipe-scaling › should send the scale when adding to shopping list, which is flaky on main too (fails 1 run in 3 against a build without this change: the route is registered after the scale navigation).

🤖 Generated with Claude Code

https://claude.ai/code/session_01RXA3hAKY9Q8hLCZGeokLPK

@dubadub

dubadub commented Oct 3, 2026

Copy link
Copy Markdown
Member

That's just brilliant! Recursive all the way!

`- @./Brunches/Sunday.menu{}` in a menu names a whole menu the way a
meal names a recipe (cooklang#385). The shopping list, `cook shopping-list` and
`cook doctor` already followed such a reference; the rest of the server
treated it as a recipe:

- The menu page links it to the menu's page (`/recipe/<path>.menu`, and
  `menu/<path>.html` in a static site, where the `.menu.html` it linked
  to does not exist), labels it without `.menu`, and tags it Menu.
- `GET /api/menus/{path}` reported `path: "./Brunches/Sunday.menu.cook"`;
  it now gives the `.menu` file and adds `"menu": true` (left out for
  recipes, so existing responses are unchanged).
- `add_menu` drops a nested menu's reference back to the menu being
  added: the shopping list follows each nested entry in a request of its
  own, so a cycle A -> B -> A counted A's contents twice there, unlike
  `cook shopping-list`.
- The editor's Add recipe, in a menu, offers menus as well as recipes
  (never the menu being edited); a recipe's Recipe reference still
  offers recipes only.

Part of cooklang#385.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RXA3hAKY9Q8hLCZGeokLPK
@LeMyst
LeMyst force-pushed the feat/menu-in-menu branch from df14542 to ee42888 Compare October 10, 2026 10:45
@LeMyst
LeMyst marked this pull request as ready for review October 10, 2026 11:10
@LeMyst
LeMyst merged commit d99192b into cooklang:main Oct 10, 2026
6 checks passed
dubadub pushed a commit that referenced this pull request Nov 24, 2026
A menu added to the shopping list keeps its meals as entries of their
own, and a menu used as one of them (`B` in `A`) is expanded from there,
on its own. Only a reference straight back to `A` was dropped, so with
three menus in a ring, `A` → `B` → `C` → `A`, B's expansion went on
through `C` into `A` and counted A's recipes a second time. The CLI
already counted them once.

A recipe expanded from a menu entry now names that menu (`within` in
core's `ExtractOptions`, `menu` in a `POST /api/shopping_list` entry),
and the menu heads the chain of ancestors the cycle check walks: the
reference back to `A` is refused, however long the ring. The shopping
list page sends it, and so does the server when it rebuilds the stored
list to compact ticks. An entry without it is expanded as before.

Since menus could be meals of each other, d99192b (#609).


Claude-Session: https://claude.ai/code/session_01MmrM91dHzvQoaerCcR9wra

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants