Module: Markdoc::Pseudocode
- Defined in:
- lib/markdoc/pseudocode.rb
Defined Under Namespace
Classes: ActionLiteral, ExpressionLiteral, IfLiteral, Register, SentenceLiteral
Class Method Summary collapse
Class Method Details
.draw(code, format = :svg) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/markdoc/pseudocode.rb', line 109 def self.draw(code, format = :svg) parser = PseudocodeParser.new tree = parser.parse(code) if tree.nil? puts parser.failure_reason raise "Can't generate graphviz code" else digest = Digest::MD5.hexdigest code graphviz = nil Tempfile.open([digest, '.gv']) do |file| file.write "digraph G {\n" tree.out(file) file.write "}\n" graphviz = file.path end return IO.read(graphviz) if format == :graphviz image = Tempfile.new([digest, ".#{format}"]) image.close if system("dot -n -T#{format} -o#{image.path} #{graphviz}") IO.read image else raise "Can't generate flowchart" end end end |