Module: SyntaxTree::Mermaid

Defined in:
lib/syntax_tree/mermaid.rb

Overview

This module is responsible for rendering mermaid (mermaid.js.org/) flow charts.

Defined Under Namespace

Classes: FlowChart, Link, Node

Class Method Summary collapse

Class Method Details

.escape(label) ⇒ Object

Escape a label to be used in the mermaid syntax. This is used to escape HTML entities such that they render properly within the quotes.



158
159
160
# File 'lib/syntax_tree/mermaid.rb', line 158

def escape(label)
  "\"#{CGI.escapeHTML(label)}\""
end

.flowchartObject

Create a new flowchart. If a block is given, it will be yielded to and the flowchart will be rendered. Otherwise, the flowchart will be returned.



165
166
167
168
169
170
171
172
173
174
# File 'lib/syntax_tree/mermaid.rb', line 165

def flowchart
  flowchart = FlowChart.new

  if block_given?
    yield flowchart
    flowchart.render
  else
    flowchart
  end
end