Class: Snapbot::Diagram::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/snapbot/diagram/renderer.rb

Overview

Render some DOT via Graphviz dot command line

Constant Summary collapse

INSTALL_GRAPHVIZ_URL =
"https://graphviz.org/download/#executable-packages"
DEFAULT_OUTPUT_FILENAME =
"tmp/models.svg"

Instance Method Summary collapse

Constructor Details

#initialize(dot) ⇒ Renderer

Returns a new instance of Renderer.



10
11
12
# File 'lib/snapbot/diagram/renderer.rb', line 10

def initialize(dot)
  @dot = dot
end

Instance Method Details

#save(path = DEFAULT_OUTPUT_FILENAME) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/snapbot/diagram/renderer.rb', line 14

def save(path = DEFAULT_OUTPUT_FILENAME)
  ensure_graphviz
  FileUtils.rm(path, force: true)
  FileUtils.mkdir_p(File.dirname(path))

  IO.popen("dot -Tsvg -o #{path}", "w") do |pipe|
    pipe.puts(@dot)
  end

  warn "Written to #{path}"
  path
end