Class: Jekyll::MscgenTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::MscgenTag
- Defined in:
- lib/jekyll-mscgen.rb
Overview
defaults which get stripped out
Instance Method Summary collapse
-
#initialize(tag_name, text, tokens) ⇒ MscgenTag
constructor
A new instance of MscgenTag.
-
#purify(output) ⇒ Object
remove basic styling from output.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, text, tokens) ⇒ MscgenTag
Returns a new instance of MscgenTag.
9 10 11 |
# File 'lib/jekyll-mscgen.rb', line 9 def initialize(tag_name, text, tokens) super end |
Instance Method Details
#purify(output) ⇒ Object
remove basic styling from output
14 15 16 17 18 19 20 21 22 23 |
# 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) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/jekyll-mscgen.rb', line 25 def render(context) @text = @nodelist.join('') @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 |