class Jekyll::MscgenBlock

defaults which get stripped out

Public Class Methods

new(tag_name, text, tokens) click to toggle source
Calls superclass method
# File lib/jekyll-mscgen.rb, line 9
def initialize(tag_name, text, tokens)
  super
end

Public Instance Methods

purify(output) click to toggle source

remove basic styling from output

# File lib/jekyll-mscgen.rb, line 14
def purify(output)
  [
    'stroke="black"', 'font-family="Helvetica"', 'font-size="12"',
    /textLength="\d+"/
  ].each do |pattern|
    output.gsub! pattern, ''
  end

  output
end
render(context) click to toggle source
Calls superclass method
# File lib/jekyll-mscgen.rb, line 25
def render(context)
  @text = super
  @text = "msc {\n #{@text} \n}"

  Open3.popen3('mscgen -i- -o- -T svg') do |stdin,out,err|
    begin
      stdin.puts(@text)
      stdin.close
    rescue Error
      puts 'error generating mscgen chart'

    ensure
      errors = err.read.strip
      output = out.read.strip
      if errors != "" and errors != nil
        puts "mscgen error: #{errors}"
        errors = "<div style='color: red; background: \#ffeeee;'>#{CGI.escapeHTML(errors)}</div>"
        if output != nil
          output = CGI.escapeHTML(output)
        end
      end

      output = output.lines.drop(2).join('')
      output = purify(output)

      return "<div class='mscgen-chart'>#{errors}#{output}</div>"
    end
  end
end