use std::sync::Arc;
use crate::core::registry::{BuildError, FeatureBuilder};
use crate::stdlib::backends::latex::{LatexPreambleDef, preamble};
use crate::stdlib::backends::latex_rendered::contract::{CELLS_CHUNK, CORE_CHUNK};
pub const PIECE: &str = "flm.latex.def.flmx.cells.styles";
pub fn piece() -> LatexPreambleDef {
LatexPreambleDef::new(
"flmx.cells.styles",
include_str!("sty/cells.sty"),
"the cell styles the cells feature ships",
)
.requires([CORE_CHUNK, CELLS_CHUNK])
.delivering([super::STYLE])
}
pub(super) fn register(b: &mut FeatureBuilder<'_>) -> Result<(), BuildError> {
b.peer_slot::<LatexPreambleDef>(preamble::SLOT, Arc::new(piece()))
}
#[cfg(test)]
mod tests {
use super::*;
use crate::model::names::Name;
#[test]
fn the_piece_names_itself_and_requires_the_cells_chunk() {
let piece = piece();
assert_eq!(piece.id.as_str(), PIECE);
assert!(piece.requires.iter().any(|id| id.as_str() == CELLS_CHUNK));
assert_eq!(piece.delivers, [Name::from(super::super::STYLE)]);
assert!(piece.content.starts_with(&format!("% {PIECE} -- ")), "{}", piece.content);
for name in ["green", "blue", "yellow", "red"] {
let line = format!("\\flmxDefineCellStyle{{{name}}}{{bg=");
assert!(piece.content.contains(&line), "{name}");
}
}
}