Class: LiquidDiagrams::Renderers::GraphvizRenderer

Inherits:
BasicRenderer
  • Object
show all
Defined in:
lib/liquid_diagrams/renderers/graphviz_renderer.rb

Constant Summary collapse

CONFIG_MAPPERS =
{
  'layout' => 'K',
  'graph_attributes' => 'G',
  'node_attributes' => 'N',
  'edge_attributes' => 'E'
}.freeze
XML_REGEX =
/^<\?xml(([^>]|\n)*>\n?){2}/.freeze

Constants inherited from BasicRenderer

BasicRenderer::FLAGS, BasicRenderer::FLAGS_PREFIX, BasicRenderer::OPTIONS, BasicRenderer::OPTIONS_PREFIX, BasicRenderer::OPTIONS_SEPARATOR

Instance Method Summary collapse

Methods inherited from BasicRenderer

#build_command, #initialize, render

Methods included from LiquidDiagrams::Rendering

render_with_command, render_with_stdin_stdout, render_with_tempfile

Constructor Details

This class inherits a constructor from LiquidDiagrams::BasicRenderer

Instance Method Details

#argumentsObject



24
25
26
27
28
29
30
# File 'lib/liquid_diagrams/renderers/graphviz_renderer.rb', line 24

def arguments
  @config.slice(*CONFIG_MAPPERS.keys).map do |opt, attrs|
    Utils.join(attrs, with: " -#{CONFIG_MAPPERS[opt]}") do |attr|
      Array(attr).join('=')
    end
  end.join(' ')
end

#executableObject



20
21
22
# File 'lib/liquid_diagrams/renderers/graphviz_renderer.rb', line 20

def executable
  'dot -Tsvg'
end

#renderObject



15
16
17
18
# File 'lib/liquid_diagrams/renderers/graphviz_renderer.rb', line 15

def render
  Rendering.render_with_stdin_stdout(build_command, @content)
           .encode('utf-8').sub(XML_REGEX, '')
end