Cooklang Reports
A WIP Rust library for generating reports from Cooklang recipes using Jinja2-style templates.
Features
- Parse Cooklang recipes
- Scale recipe quantities
- Access recipe metadata and ingredients
- Template-based report generation
- Custom filters for formatting
- YAML datastore integration for recipe metadata
- Support for nested data access
Installation (soon)
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage
Basic Template Rendering
use indoc;
use render_template;
let recipe = r#"
Mix @eggs{3%large} with @milk{250%ml}, add @flour{125%g} to make batter.
Add @sugar{1.5%tbsp} and @salt{1/4%tsp} for flavor.
"#;
let template = indoc! ;
// Test default scaling (1x)
let result = render_template.unwrap;
let expected = indoc! ;
assert_eq!;
Using Datastore
use indoc;
use Path;
use render_template_with_config;
use Config;
let recipe = r#"
Mix @eggs{3%large} with @milk{250%ml}, add @flour{125%g} to make batter.
Add @sugar{1.5%tbsp} and @salt{1/4%tsp} for flavor.
"#;
let datastore_path = new;
let template = indoc! ;
let config = builder.datastore_path.build;
let result = render_template_with_config.unwrap;
let expected = indoc! ;
assert_eq!;
Template Features
Available Variables
ingredients: List of recipe ingredients with their quantities and unitsscale: Current recipe scale factorrecipe_template: Full recipe template object with additional methods
Built-in Functions
db(key_path): Access data from the YAML datastore- Format:
directory.file.key.subkey - Example:
db('eggs.meta.storage.shelf life')
- Format:
Built-in Filters
quantity: Format ingredient quantities with proper spacing- Example:
{{ ingredient.quantity | quantity }}
- Example:
Project Structure
src/
├── lib.rs # Main library code
├── filters/ # Template filters
│ ├── mod.rs
│ └── quantity.rs
└── functions/ # Template functions
├── mod.rs
└── datastore.rs
Datastore Format
The datastore is a directory of YAML files organized by ingredient:
datastore/
├── eggs/
│ ├── meta.yml
│ └── shopping.yml
├── milk/
│ ├── meta.yml
│ └── shopping.yml
└── flour/
├── meta.yml
└── shopping.yml
Example YAML file (eggs/meta.yml):
density: 1.03
storage:
shelf life: 30
fridge life: 60
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MPL 2.0 License - see the LICENSE file for details.