lib/liquid_diagrams/renderers/graphviz_renderer.rb in liquid-diagrams-0.3.0 vs lib/liquid_diagrams/renderers/graphviz_renderer.rb in liquid-diagrams-0.4.0

- old
+ new

@@ -1,33 +1,33 @@ # frozen_string_literal: true module LiquidDiagrams module Renderers class GraphvizRenderer < BasicRenderer - MAPPERS = { + CONFIG_MAPPERS = { 'layout' => 'K', 'graph_attributes' => 'G', 'node_attributes' => 'N', 'edge_attributes' => 'E' }.freeze XML_REGEX = /^<\?xml(([^>]|\n)*>\n?){2}/.freeze def render - output = Rendering.render_with_stdin_stdout(build_command, @content) - output.dup.force_encoding('utf-8').sub(XML_REGEX, '') + Rendering.render_with_stdin_stdout(build_command, @content) + .encode('utf-8').sub(XML_REGEX, '') end - def build_command - command = +'dot -Tsvg' + def executable + 'dot -Tsvg' + end - @config.slice(*MAPPERS.keys).each do |opt, attrs| - command << Utils.join(attrs, with: " -#{MAPPERS[opt]}") do |attr| + 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 - - command + end.join(' ') end end end end