Class: Jekyll::Diagrams::GraphvizRenderer
- Inherits:
-
Object
- Object
- Jekyll::Diagrams::GraphvizRenderer
- Defined in:
- lib/jekyll/diagrams/graphviz.rb
Constant Summary collapse
- DEFAULTS =
{ 'engine' => 'dot', 'options' => '-Tsvg' }
Instance Method Summary collapse
-
#initialize(config) ⇒ GraphvizRenderer
constructor
A new instance of GraphvizRenderer.
- #render(code, engine = DEFAULTS['engine']) ⇒ Object
Constructor Details
#initialize(config) ⇒ GraphvizRenderer
Returns a new instance of GraphvizRenderer.
44 45 46 |
# File 'lib/jekyll/diagrams/graphviz.rb', line 44 def initialize(config) @config = DEFAULTS.merge(config) end |
Instance Method Details
#render(code, engine = DEFAULTS['engine']) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/jekyll/diagrams/graphviz.rb', line 48 def render(code, engine = DEFAULTS['engine']) cmd = "#{@config['engine']} #{@config['options']}" svg, status = Open3.capture2( cmd, stdin_data: code, binmode: true ) if !status.success? raise "Non-zero exit status '#{cmd}': #{status}" end svg.force_encoding 'UTF-8' (svg) wrap_div(svg) end |