Sha256: 51208d156b1833620d51e20bd1c20a8e4af04234f15c4c88bd7430bab47dfb54

Contents?: true

Size: 793 Bytes

Versions: 3

Compression:

Stored size: 793 Bytes

Contents

# frozen_string_literal: true

module LiquidDiagrams
  module Renderers
    class GraphvizRenderer < BasicRenderer
      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, '')
      end

      def build_command
        command = +'dot -Tsvg'

        @config.slice(*MAPPERS.keys).each do |opt, attrs|
          command << Utils.join(attrs, with: " -#{MAPPERS[opt]}") do |attr|
            Array(attr).join('=')
          end
        end

        command
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
liquid-diagrams-0.3.0 lib/liquid_diagrams/renderers/graphviz_renderer.rb
liquid-diagrams-0.2.0 lib/liquid_diagrams/renderers/graphviz_renderer.rb
liquid-diagrams-0.1.0 lib/liquid_diagrams/renderers/graphviz_renderer.rb