Files
dancing-teacher-info/src/wikipage.rs
2025-07-24 19:02:10 +02:00

39 lines
1.3 KiB
Rust

use crate::dance_info::DanceInfo;
use mwbot::parsoid::WikinodeIterator;
use mwbot::parsoid::{self, Template, Wikicode, map::IndexMap};
#[derive(thiserror::Error, Debug)]
pub enum InfoCompileError {
#[error("Could not compile wikipage: {0}")]
CompileError(#[from] parsoid::Error),
}
pub fn page_from_info(info: DanceInfo) -> Result<Wikicode, InfoCompileError> {
let mut params = IndexMap::new();
params.insert("name".to_string(), info.name());
params.insert(
"dominant_role".to_string(),
info.dominant_role.as_str().to_string(),
);
params.insert(
"allowed_rank".to_string(),
info.dominant_role_comp.rank.as_str().to_string(),
);
params.insert(
"dominant_rank".to_string(),
info.dominant_role_comp.rank.as_str().to_string(),
);
params.insert(
"dominant_points".to_string(),
info.dominant_role_comp.points.to_string(),
);
if let Some(u) = info.non_dominant_role_comp {
params.insert("non_dominant_rank".to_string(), u.rank.as_str().to_string());
params.insert("non_dominant_points".to_string(), u.points.to_string());
}
let t = Template::new("Template:WSDCBox", &params)?;
let result = Wikicode::new("");
result.append(&t);
Ok(result)
}