Sha256: 2542510ef5ae73819a8ce1d8803c20d3f9fd94abec1da5d4f65ceda7adfc9981

Contents?: true

Size: 748 Bytes

Versions: 1

Compression:

Stored size: 748 Bytes

Contents

# frozen_string_literal: true

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

      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

      def build_command(config)
        command = +'smcat'

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

        command
      end
    end
  end
end

Liquid::Template.register_tag(:smcat, Jekyll::Diagrams::SMCatBlock)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jekyll-diagrams-0.9.3 lib/jekyll-diagrams/smcat.rb