typst table creation
This commit is contained in:
48
komp-app/src/typst.rs
Normal file
48
komp-app/src/typst.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
pub use common::typst_contract::{TypstContract, TypstContractError};
|
||||
use common::proto::komp_ac::document_data::TypstTemplateVersion;
|
||||
|
||||
/// Parses the first meaningful declaration from stored Typst source for the
|
||||
/// admin mapping workflow. It must be the literal `komp_ac_fields` tuple;
|
||||
/// only whitespace and comments may precede it. The server independently runs
|
||||
/// the same shared parser before accepting a submitted mapping.
|
||||
pub fn parse_contract(source: &str) -> Result<TypstContract, TypstContractError> {
|
||||
common::typst_contract::parse(source)
|
||||
}
|
||||
|
||||
/// Parses the source carried by an immutable template-version response. Admin
|
||||
/// workflows should retain `version.id` separately and send it back when they
|
||||
/// submit the reviewed table mapping.
|
||||
pub fn parse_template_version(
|
||||
version: &TypstTemplateVersion,
|
||||
) -> Result<TypstContract, TypstContractError> {
|
||||
parse_contract(&version.source_code)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{parse_contract, parse_template_version};
|
||||
use common::proto::komp_ac::document_data::TypstTemplateVersion;
|
||||
|
||||
#[test]
|
||||
fn exposes_typst_fields_to_client_workflows() {
|
||||
let contract = parse_contract(
|
||||
r#"#let komp_ac_fields = ("invoice.number", "items[].quantity")"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
contract.field_paths,
|
||||
["invoice.number", "items[].quantity"]
|
||||
);
|
||||
|
||||
let version = TypstTemplateVersion {
|
||||
id: 42,
|
||||
source_code: r#"#let komp_ac_fields = ("invoice.number",)"#.to_string(),
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(
|
||||
parse_template_version(&version).unwrap().field_paths,
|
||||
["invoice.number"]
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user