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
103 104 105 106 107 108 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 |
# File 'lib/markdoc/pseudocode.rb', line 103 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 if format == :graphviz return IO.read(graphviz) end 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 |