tramli_plugins/docs/
mod.rs1use tramli::{FlowDefinition, FlowState};
2
3pub struct DocumentationPlugin;
5
6impl DocumentationPlugin {
7 pub fn to_markdown<S: FlowState>(definition: &FlowDefinition<S>) -> String {
8 let mut lines = Vec::new();
9 lines.push(format!("# Flow Catalog: {}", definition.name));
10 lines.push(String::new());
11 lines.push("## States".to_string());
12 lines.push(String::new());
13 for state in S::all_states() {
14 let mut suffix = String::new();
15 if state.is_initial() { suffix.push_str(" (initial)"); }
16 if state.is_terminal() { suffix.push_str(" (terminal)"); }
17 lines.push(format!("- `{:?}`{}", state, suffix));
18 }
19 lines.push(String::new());
20 lines.push("## Transitions".to_string());
21 lines.push(String::new());
22 for t in &definition.transitions {
23 let via = if let Some(ref p) = t.processor {
24 p.name().to_string()
25 } else if let Some(ref g) = t.guard {
26 g.name().to_string()
27 } else if let Some(ref b) = t.branch {
28 b.name().to_string()
29 } else {
30 format!("{:?}", t.transition_type)
31 };
32 lines.push(format!("- `{:?} -> {:?}` via `{}`", t.from, t.to, via));
33 }
34 lines.join("\n")
35 }
36}