Class: Jekyll::Diagrams::SMCatRenderer

Inherits:
BasicRenderer show all
Defined in:
lib/jekyll-diagrams/smcat/renderer.rb

Constant Summary collapse

XML_REGEX =
/^<\?xml(([^>]|\n)*>\n?){2}/.freeze
CONFIGURATIONS =
%w[direction engine input-type].freeze

Instance Method Summary collapse

Methods inherited from BasicRenderer

#initialize, render, #render

Methods included from Rendering

render_with_command, render_with_stdin_stdout, render_with_tempfile

Constructor Details

This class inherits a constructor from Jekyll::Diagrams::BasicRenderer

Instance Method Details

#build_command(config) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/jekyll-diagrams/smcat/renderer.rb', line 19

def build_command(config)
  command = +'smcat'

  CONFIGURATIONS.each do |conf|
    command << " --#{conf} #{config[conf]}" if config.key?(conf)
  end

  command
end

#render_svg(code, config) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/jekyll-diagrams/smcat/renderer.rb', line 9

def render_svg(code, config)
  command = build_command(config)

  svg = render_with_tempfile(command, code) do |input, output|
    "#{input} --output-to #{output}"
  end

  svg.sub!(XML_REGEX, '')
end