use crate::assets::{self, Delivery};
use crate::graph::CodeGraph;
pub fn render(graph: &CodeGraph) -> String {
let data = serde_json::to_string(graph).unwrap_or_else(|_| "{}".to_string());
let stat = format!(
"{} nodes \u{00b7} {} edges",
graph.nodes.len(),
graph.edges.len()
);
assets::graph_page(&data, &stat, Delivery::Inline)
}
#[cfg(test)]
mod tests {
use super::render;
use crate::graph::CodeGraph;
#[test]
fn output_is_fully_self_contained() {
let graph = CodeGraph {
version: 2,
root: ".".to_string(),
generated_at: 0,
nodes: Vec::new(),
edges: Vec::new(),
};
let html = render(&graph);
assert!(!html.contains("href=\"./"), "must not link a sibling file:\n{html}");
assert!(!html.contains("src=\"./"), "must not source a sibling file:\n{html}");
assert!(html.contains("<style>"), "CSS must be inlined");
assert!(html.contains("<script>"), "JS must be inlined");
}
}