Sha256: b0f16f8d11739b31674a2d6672021a44e6f553dda0e50e07759c4b8d7be188e4
Contents?: true
Size: 1015 Bytes
Versions: 1
Compression:
Stored size: 1015 Bytes
Contents
module Jekyll module Diagrams class GraphvizBlock < Block CONFIGRATIONS = { 'K' => 'default_layout', 'G' => 'graph_attribute', 'N' => 'node_attribute', 'E' => 'edge_attribute' }.freeze def render_svg(code, config) command = build_command(config) svg = render_with_stdin_stdout(command, code) svg.sub!(/^<\?xml(([^>]|\n)*>\n?){2}/, '') end 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 end end end Liquid::Template.register_tag(:graphviz, Jekyll::Diagrams::GraphvizBlock)
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jekyll-diagrams-0.8.0 | lib/jekyll-diagrams/graphviz.rb |