Class: RailsFlowMap::MermaidFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_flow_map/formatters/mermaid_formatter.rb

Instance Method Summary collapse

Instance Method Details

#format(graph) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rails_flow_map/formatters/mermaid_formatter.rb', line 3

def format(graph)
  lines = ["graph TD"]
  
  # Add nodes
  graph.nodes.each do |id, node|
    lines << format_node(node)
  end
  
  lines << ""
  
  # Add edges
  graph.edges.each do |edge|
    lines << format_edge(edge, graph)
  end
  
  # Add styling
  lines << ""
  lines << "%% Styling"
  lines << "classDef model fill:#f9f,stroke:#333,stroke-width:2px;"
  lines << "classDef controller fill:#bbf,stroke:#333,stroke-width:2px;"
  lines << "classDef action fill:#bfb,stroke:#333,stroke-width:2px;"
  
  # Apply styles to nodes
  model_nodes = graph.nodes_by_type(:model).map(&:id).join(",")
  controller_nodes = graph.nodes_by_type(:controller).map(&:id).join(",")
  action_nodes = graph.nodes_by_type(:action).map(&:id).join(",")
  
  lines << "class #{model_nodes} model;" unless model_nodes.empty?
  lines << "class #{controller_nodes} controller;" unless controller_nodes.empty?
  lines << "class #{action_nodes} action;" unless action_nodes.empty?
  
  lines.join("\n")
end