Repository navigation
fix(web): show number and boolean custom metadata as pills - #839
wanjinhao1 wants to merge 3 commits into
Conversation
) The recipe and menu pages built custom metadata pills from string values only, so a key whose YAML value read as a number or a boolean was silently dropped while `cook recipe` printed it. Reuse the string/number/boolean conversion the standard fields already use, with floats formatted by format_number as before. Lists and mappings remain cooklang#459.
|
No CI checks have run on this PR yet — likely awaiting first-time-contributor workflow approval. Could a maintainer click "Approve and run" so the workflows execute? Thanks! |
dubadub
left a comment
There was a problem hiding this comment.
Thanks for picking up #838. The direction is right, but a few things need changing before this can merge:
- Numbers render as fractions. Custom values go through
format_number, soprecision: 4.5shows as4 1/2(the new test asserts that). #838 asks for numbers "as4,4.5", and fractions read oddly for things likerating: 4.5orabv: 5.5.format_numbermakes sense for servings, but custom pills should show the plain number. - One helper, not two copies.
value_to_textis a nested fn insidebuild_recipe_template, and the menu path repeats the same str/i64/bool/f64 chain inline. Please move it to module level and use it for both pages' custom pills (and the menu'sget_field, so both pages treat standard fields the same way). - Menu page test. The regression test only covers the recipe page. Please add a
.menucase so the second change is covered too. - Heads-up on a conflict. #853 changes the same menu custom-metadata chain in
src/web/builders.rs(it adds asource.filter). Whichever merges second will need a small rebase.
# Conflicts: # src/web/builders.rs
|
I merged main into this branch to resolve the conflict with #853 (point 4 above): the menu chain keeps both the new |
|
Thanks for the merge and the review. Points 1–3 addressed in 48ea469:
Verified locally: |
|
Thanks for the quick turnaround on points 1–3. The fix itself works: I served a recipe and a menu with
Optional:
What I ran:
🤖 Analysis and recommendations made by Claude (Anthropic's AI assistant), posted on behalf of @LeMyst. |
Problem
The recipe page shows custom front-matter keys as
key: valuepills only when the value is text. A key whose YAML value reads as a number ortrue/falseis left out with no warning, whilecook recipeprints all of them (issue #838). The menu page has the same gap.Fixes #838
Changes
src/web/builders.rs(recipe page): extract the string/number conversion the standard fields already use into a smallvalue_to_texthelper (now also handling booleans) and use it for the custom-metadata pills instead ofvalue.as_str()only. Floats still go throughformat_number, so4.5renders as4 1/2exactly like standard fields.src/web/builders.rs(menu page): the same str/i64/bool/f64 conversion in thefilter_mapthat builds custom pills.Tests
custom_metadata_pills_cover_numbers_and_booleanscoversrating: 4,tested: true,precision: 4.5and the text controlrated: 4/5, asserting both the model data and the rendered HTML.cargo test --lib: 407 passed, 0 failed.cargo fmt --checkclean;cargo clippy --lib --tests -- -D warningsclean.AI assistance
This change was implemented with the help of an AI coding agent operated by the account owner (wanjinhao1), who reviewed and tested the result.