Class: Jekyll::Diagrams::GraphvizBlock
- Defined in:
- lib/jekyll-diagrams/graphviz.rb
Constant Summary collapse
- CONFIGRATIONS =
{ 'K' => 'default_layout', 'G' => 'graph_attributes', 'N' => 'node_attributes', 'E' => 'edge_attributes' }.freeze
Instance Method Summary collapse
Methods inherited from Block
#read_config, #render, #wrap_class
Methods included from Util
#config_for, #diagrams_config, #vendor_path
Methods included from Renderer
#render_with_command, #render_with_stdin, #render_with_stdin_stdout, #render_with_stdout, #render_with_tempfile
Instance Method Details
#build_command(config) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/jekyll-diagrams/graphviz.rb', line 18 def build_command(config) command = 'dot -Tsvg' CONFIGRATIONS.each do |prefix, conf| next unless config.has_key?(conf) attrs = config[conf] attrs = case attrs when String attrs when Array attrs.join(" -#{prefix}") when Hash attrs.map { |k, v| "#{k}=#{v}" }.join(" -#{prefix}") end command << " -#{prefix}#{attrs}" end command end |
#render_svg(code, config) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/jekyll-diagrams/graphviz.rb', line 11 def render_svg(code, config) command = build_command(config) svg = render_with_stdin_stdout(command, code) svg.sub!(/^<\?xml(([^>]|\n)*>\n?){2}/, '') end |