-
Notifications
You must be signed in to change notification settings - Fork 6
/
GraphVizGenerator.rb
executable file
·68 lines (57 loc) · 1.73 KB
/
GraphVizGenerator.rb
1
2
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# GraphVizGenerator.rb
# Leonhard
#
# Created by greg on 28/07/10.
# Copyright 2010, 2011 Gregoire Lejeune. All rights reserved.
require 'tempfile'
require 'fileutils'
require 'GVUtils'
class GraphVizGenerator
include GVUtils
attr_accessor :interpretor
def initialize( codeView, errorsView, pdfView, preferences )
@codeView = codeView
@errorsView = errorsView
@pdfView = pdfView
@preferences = preferences
@interpretor = "dot"
@generateThread = nil
end
def save( format = "pdf", file = nil )
t = Tempfile::open( File.basename(__FILE__) )
t.print( @codeView.textStorage.mutableString )
t.close
dotFile = t.path
outFile = dotFile+"."+format
outFile = file unless file.nil?
dotExe = unless @preferences.gvPath.strip.empty?
File.join( @preferences.gvPath, @interpretor )
else
@interpretor
end
xCmd = "#{dotExe} -T#{format} -o#{outFile} #{dotFile}"
output, errors = output_and_errors_from_command( xCmd )
if errors.nil? or errors.strip.empty?
@errorsView.textStorage.mutableString.string = "0 error!"
else
@errorsView.textStorage.mutableString.string = errors.gsub( dotFile, "" )
end
@errorsView.font = NSUnarchiver.unarchiveObjectWithData(@preferences["TextFont"])
@pdfView.document = PDFDocument.alloc.initWithURL( NSURL.fileURLWithPath(outFile) ) if @file.nil?
t.unlink
FileUtils.rm_f( outFile ) if file.nil?
save() unless file.nil?
end
def regenerate(sender)
if @generateThread.nil? == false and @generateThread.alive?
# DO Something ???
end
@generateThread = Thread.new do
begin
save()
rescue => e
NSLog(e.message)
end
end
end
end