Sha256: 1faf81ed7b5386ef85391dd08aa5dac2ac33f9c7595028d2d43743df2dd3a49f

Contents?: true

Size: 1005 Bytes

Versions: 1

Compression:

Stored size: 1005 Bytes

Contents

require 'open3'
require 'tempfile'

module Jekyll
  module Diagrams
    class BlockdiagBlock < Block
      CONFIGURATIONS = %w(config font fontmap size).freeze

      def render_svg(code, config)
        command = build_command(config)
        
        render_with_tempfile(command, code) do |command, input, output|
          "#{command} #{input} -o #{output}"
        end
      end

      def read_config(context)
        Util.config_for(context, 'blockdiag').merge(
          Util.config_for(context, block_name)
        )
      end

      def build_command(config)
        command = "#{block_name} -T svg --nodoctype"
        command << ' --antialias' if config.has_key?('antialias')

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

        command
      end
    end
  end
end

%i(blockdiag seqdiag actdiag nwdiag rackdiag packetdiag).each do |tag|
  Liquid::Template.register_tag(tag, Jekyll::Diagrams::BlockdiagBlock)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jekyll-diagrams-0.7.1 lib/jekyll-diagrams/blockdiag.rb