forked from bai/curriculum-project-hub
feat(cph): add outline export command
This commit is contained in:
@@ -130,6 +130,39 @@ pub fn check(root: &Path, engine: &Engine) -> CheckReport {
|
||||
}
|
||||
}
|
||||
|
||||
/// Load and validate the lesson, then project it into an outline.
|
||||
///
|
||||
/// Outline output is derived from the manifest and part metadata, not from the
|
||||
/// rendered lesson body. It therefore runs the same load → structural → schema
|
||||
/// gates as other non-typst builds, but intentionally does not compile any
|
||||
/// target. An invalid lesson is never written in any outline format.
|
||||
pub fn outline(root: &Path) -> (Option<cph_model::OutlineDocument>, CheckReport) {
|
||||
let mut diags = Vec::new();
|
||||
let (lesson, load_diags) = cph_model::load(root);
|
||||
diags.extend(load_diags);
|
||||
|
||||
let Some(lesson) = lesson else {
|
||||
return (
|
||||
None,
|
||||
CheckReport {
|
||||
diagnostics: dedup(diags),
|
||||
lesson_loaded: false,
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
run_structural_and_schema(&lesson, cph_schema::known_kinds(), &mut diags);
|
||||
let report = CheckReport {
|
||||
diagnostics: dedup(diags),
|
||||
lesson_loaded: true,
|
||||
};
|
||||
if report.has_errors() {
|
||||
(None, report)
|
||||
} else {
|
||||
(Some(lesson.outline_document()), report)
|
||||
}
|
||||
}
|
||||
|
||||
/// Build a PDF for `target`.
|
||||
///
|
||||
/// Runs the check phases **(a)–(c)** (load → structural → schema). If those
|
||||
|
||||
@@ -45,6 +45,23 @@ fn good_fixture_has_no_errors() {
|
||||
assert!(!report.has_errors());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn outline_projects_parts_in_manifest_order() {
|
||||
let (outline, report) = cph_check::outline(&mini_fixture());
|
||||
assert_eq!(
|
||||
report.error_count(),
|
||||
0,
|
||||
"outline should validate the fixture"
|
||||
);
|
||||
let outline = outline.expect("valid lesson should produce an outline");
|
||||
assert_eq!(outline.title, "迷你示例课时");
|
||||
assert_eq!(outline.children.len(), 3);
|
||||
assert_eq!(outline.children[0].title, "开场对照导言");
|
||||
assert_eq!(outline.children[1].kind, "section");
|
||||
assert_eq!(outline.children[1].children[0].title, "量纲分析估计");
|
||||
assert_eq!(outline.children[2].title, "自由落体");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_kind_is_an_error() {
|
||||
// Build a throwaway lesson whose part declares kind "frob".
|
||||
|
||||
Reference in New Issue
Block a user