Skip to content

Commit 6e5364b

Browse files
authored
Merge pull request #27 from cooklang/canonical-metadata
Canonical metadata
2 parents 7c758d2 + 5b70692 commit 6e5364b

File tree

11 files changed

+794
-334
lines changed

11 files changed

+794
-334
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
## Unreleased - ReleaseDate
44

5+
- Add support in `cooklang::metadata` for [canonical
6+
metadata](https://cooklang.org/docs/spec/#canonical-metadata), making it
7+
easier to query these keys and expected values.
8+
- Add warnings for missused canonical metadata keys.
9+
- Improve custom checks for metadata keys. Now they can choose to skip the
10+
included checks too.
11+
- Fix ingredients aliases from aisle configuration not being merged in
12+
`IngredientList`. (#24 @kaylee-kiako)
13+
14+
## 0.14.0 - 2024/12/11
15+
16+
- Add YAML frontmatter for metadata. Deprecate old style metadata keys with the
17+
`>>` syntax. This also comes with changes in the `cooklang::metadata` module.
18+
- Add deprecation and how to fix warnings when using old style metadata.
19+
- Remove `MULTILINE_STEPS`, `COMPONENT_NOTE`, `SECTIONS` and `TEXT_STEPS`
20+
**extensions** as they are now part of the cooklang specification and are
21+
always enabled.
22+
523
## 0.13.3 - 2024/08/12
624
- Replace `ariadne` dependency with `codesnake`. Because of this, errors may
725
have some minor differences.

Cargo.lock

Lines changed: 0 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ thiserror = "1"
1919
url = { version = "2", features = ["serde"] }
2020
pest = { version = "2", optional = true }
2121
pest_derive = { version = "2", optional = true }
22-
emojis = "0.6"
2322
toml = { version = "0.8", optional = true }
2423
once_cell = "1"
2524
enum-map = { version = "2", features = ["serde"] }

playground/index.html

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,10 @@ <h1>cooklang-rs playground</h1>
174174

175175
<select id="parserSelect">
176176
<option value="render" selected>Render</option>
177-
<option value="full" selected>Full parse</option>
177+
<option value="full">Full parse</option>
178178
<option value="events">Events</option>
179179
<option value="ast">AST</option>
180+
<option value="stdmeta">Standard metadata</option>
180181
</select>
181182
<div hidden id="servingscontainer">
182183
<label for="servings">Servings</label>
@@ -219,7 +220,7 @@ <h1>cooklang-rs playground</h1>
219220
</main>
220221

221222
<script type="module">
222-
import init, { State,version } from "./pkg/cooklang_playground.js";
223+
import init, { State, version } from "./pkg/cooklang_playground.js";
223224

224225
async function run() {
225226
await init();
@@ -286,7 +287,13 @@ <h1>cooklang-rs playground</h1>
286287
break;
287288
}
288289
case "render": {
289-
const { value, error } = state.parse_render(input, servings.value.length === 0 ? null : servings.valueAsNumber );
290+
const { value, error } = state.parse_render(input, servings.value.length === 0 ? null : servings.valueAsNumber);
291+
output.innerHTML = value;
292+
errors.innerHTML = error;
293+
break;
294+
}
295+
case "stdmeta": {
296+
const { value, error } = state.std_metadata(input);
290297
output.innerHTML = value;
291298
errors.innerHTML = error;
292299
break;
@@ -329,21 +336,19 @@ <h1>cooklang-rs playground</h1>
329336
servings.addEventListener("change", () => parse());
330337

331338
const extensionsContainer = document.getElementById("extensions-container");
339+
332340
const extensions = [
333-
"COMPONENT_MODIFIERS",
334-
"COMPONENT_ALIAS",
335-
"ADVANCED_UNITS",
336-
"MODES",
337-
"TEMPERATURE",
338-
"RANGE_VALUES",
339-
"TIMER_REQUIRES_TIME",
340-
"INTERMEDIATE_PREPARATIONS",
341-
"SPECIAL_METADATA",
342-
].forEach((e, i) => {
343-
let bits = 1 << i;
344-
if (i == 11) {
345-
bits |= 1 << 1;
346-
}
341+
["COMPONENT_MODIFIERS", 1 << 1],
342+
["COMPONENT_ALIAS", 1 << 3],
343+
["ADVANCED_UNITS", 1 << 5],
344+
["MODES", 1 << 6],
345+
["TEMPERATURE", 1 << 7],
346+
["RANGE_VALUES", 1 << 9],
347+
["TIMER_REQUIRES_TIME", 1 << 10],
348+
["INTERMEDIATE_PREPARATIONS", 1 << 11 | 1 << 1]
349+
];
350+
351+
extensions.forEach(([e, bits]) => {
347352
const elem = document.createElement("input");
348353
elem.setAttribute("type", "checkbox");
349354
elem.setAttribute("id", e);
@@ -414,4 +419,4 @@ <h1>cooklang-rs playground</h1>
414419
</script>
415420
</body>
416421

417-
</html>
422+
</html>

playground/src/lib.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use cooklang::ast::build_ast;
22
use cooklang::error::SourceReport;
3+
use cooklang::metadata::{NameAndUrl, RecipeTime};
34
use cooklang::{parser::PullParser, Extensions};
45
use cooklang::{Converter, CooklangParser, IngredientReferenceTarget, Item};
56
use std::fmt::Write;
@@ -103,6 +104,35 @@ impl State {
103104
};
104105
FallibleResult::new(value, report, input)
105106
}
107+
108+
pub fn std_metadata(&self, input: &str) -> FallibleResult {
109+
let (meta, report) = self.parser.parse_metadata(input).into_tuple();
110+
let value = match meta {
111+
Some(m) => {
112+
#[derive(Debug)]
113+
#[allow(dead_code)]
114+
struct StdMeta<'a> {
115+
tags: Option<Vec<std::borrow::Cow<'a, str>>>,
116+
author: Option<NameAndUrl>,
117+
source: Option<NameAndUrl>,
118+
time: Option<RecipeTime>,
119+
servings: Option<Vec<u32>>,
120+
locale: Option<(&'a str, Option<&'a str>)>,
121+
}
122+
let val = StdMeta {
123+
tags: m.tags(),
124+
author: m.author(),
125+
source: m.source(),
126+
time: m.time(self.parser.converter()),
127+
servings: m.servings(),
128+
locale: m.locale(),
129+
};
130+
format!("{val:#?}")
131+
}
132+
None => "<no output>".to_string(),
133+
};
134+
FallibleResult::new(value, report, input)
135+
}
106136
}
107137

108138
impl State {

0 commit comments

Comments
 (0)