feat: improve worksheet
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
use coursebank::assessment::Form;
|
||||
use coursebank::error::{Error, Result};
|
||||
use coursebank::layout::Layout;
|
||||
use coursebank::practice;
|
||||
use coursebank::qti;
|
||||
use coursebank::typst;
|
||||
use coursebank::yaml;
|
||||
@@ -168,9 +169,65 @@ pub(crate) fn export(cli: &Cli, sub: &ExportCommand) -> Result<Outcome> {
|
||||
println!("wrote {}", path.display());
|
||||
Ok(Outcome::Ok)
|
||||
}
|
||||
ExportCommand::Practice {
|
||||
id,
|
||||
form,
|
||||
variant,
|
||||
out,
|
||||
no_answer_space,
|
||||
} => {
|
||||
let record = load_record(&catalog, id)?;
|
||||
let form = pick_form(&record, form)?;
|
||||
let dir = out.clone().unwrap_or(build);
|
||||
for v in pick_practice_variants(variant)? {
|
||||
let opts = practice::Options {
|
||||
form: form.clone(),
|
||||
variant: v,
|
||||
answer_space: !no_answer_space,
|
||||
};
|
||||
let text = practice::render(&catalog, &record, &opts)?;
|
||||
let path = dir.join(format!("{id}-{}{}.qmd", form.id, v.suffix()));
|
||||
yaml::write_text(&path, &text)?;
|
||||
println!("wrote {}", path.display());
|
||||
}
|
||||
if !cli.quiet {
|
||||
println!("\nRender with: quarto render <file>.qmd");
|
||||
}
|
||||
Ok(Outcome::Ok)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolves the `--variant` flags for `export practice`, defaulting to both.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `names` - the raw flag values, possibly empty.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// The documents to write, deduplicated and in canonical order (worksheet first).
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns [`Error::Usage`] naming the valid tokens.
|
||||
fn pick_practice_variants(names: &[String]) -> Result<Vec<practice::Variant>> {
|
||||
if names.is_empty() {
|
||||
return Ok(practice::Variant::ALL.to_vec());
|
||||
}
|
||||
let mut wanted = Vec::new();
|
||||
for name in names {
|
||||
let variant = practice::Variant::parse(name)?;
|
||||
if !wanted.contains(&variant) {
|
||||
wanted.push(variant);
|
||||
}
|
||||
}
|
||||
Ok(practice::Variant::ALL
|
||||
.into_iter()
|
||||
.filter(|v| wanted.contains(v))
|
||||
.collect())
|
||||
}
|
||||
|
||||
/// Resolves the `--variant` flags, defaulting to every document.
|
||||
///
|
||||
/// # Arguments
|
||||
|
||||
Reference in New Issue
Block a user