class Md2key::Diagram
Public Class Methods
generate_image_file(code)
click to toggle source
SEQUENCE_CONFIG_PATH = File.expand_path('../../assets/mermaid_sequence.config', __dir__) GANTT_CONFIG_PATH = File.expand_path('../../assets/mermaid_gantt.config', __dir__)
# File lib/md2key/diagram.rb, line 8 def generate_image_file(code) ensure_mermaid_availability file = Tempfile.new("diagram-#{code.extension}") file.write(code.source) file.close output_dir = File.dirname(file.path) image_path = "" IO.popen("mermaid #{file.path} | grep 'saved png' | awk -F':' '\{print $2\}'", 'r+') do |info| image_path = info.read.strip file.unlink end return image_path end
Private Class Methods
ensure_mermaid_availability()
click to toggle source
# File lib/md2key/diagram.rb, line 27 def ensure_mermaid_availability return if system('which -s mermaid') abort "`mermaid` is not available. Try `npm install -g phantomjs mermaid`." end