class Jekyll::PlantUMLBlock

Attributes

config[R]

Public Instance Methods

render(context) click to toggle source
# File doc/plugins/plantuml.rb, line 19
def render(context)
  site = context.registers[:site]
  self.config = site.config['plantuml']

  tmproot = File.expand_path(tmp_folder)
  folder = "/images/plantuml/"
  create_tmp_folder(tmproot, folder)

  code = @nodelist.join + background_color
  filename = Digest::MD5.hexdigest(code) + ".png"
  filepath = tmproot + folder + filename
  if !File.exist?(filepath)
    plantuml_jar = File.expand_path(plantuml_jar_path)
    cmd = "java -Djava.awt.headless=true -jar " + plantuml_jar + dot_cmd + " -pipe > " + filepath
    result, status = Open3.capture2e(cmd, :stdin_data=>code)
    Jekyll.logger.debug(filepath + " -->\t" + status.inspect() + "\t" + result)
  end

  site.static_files << Jekyll::StaticFile.new(site, tmproot, folder, filename)

  "<img src='" + "#{ site.baseurl }/" + folder + filename + "'>"
end

Private Instance Methods

background_color() click to toggle source
# File doc/plugins/plantuml.rb, line 48
def background_color
  config['background_color'].nil? ? '' : " skinparam backgroundColor " + config['background_color']
end
config=(cfg) click to toggle source
# File doc/plugins/plantuml.rb, line 44
def config=(cfg)
  @config = cfg || Jekyll.logger.abort_with("Missing 'plantuml' configurations.")
end
create_tmp_folder(tmproot, folder) click to toggle source
# File doc/plugins/plantuml.rb, line 73
def create_tmp_folder(tmproot, folder)
  folderpath = tmproot + folder
  if !File.exist?(folderpath)
    FileUtils::mkdir_p folderpath
    Jekyll.logger.info("Create PlantUML image folder: " + folderpath)
  end
end
dot_cmd() click to toggle source
# File doc/plugins/plantuml.rb, line 60
def dot_cmd
  @dot_cmd ||= begin
    dotpath = File.expand_path(config['dot_exe'] || '__NULL__')
    if File.exist?(dotpath)
      # Jekyll.logger.info("PlantUML: Use graphviz dot: " + dotpath)
      " -graphvizdot " + dotpath
    else
      # Jekyll.logger.info("PlantUML: Assume graphviz dot is in PATH.")
      ''
    end
  end
end
plantuml_jar_path() click to toggle source
# File doc/plugins/plantuml.rb, line 52
def plantuml_jar_path
  config['plantuml_jar'] || Jekyll.logger.abort_with("Missing configuration 'plantuml.plantuml_jar'.")
end
tmp_folder() click to toggle source
# File doc/plugins/plantuml.rb, line 56
def tmp_folder
  config['tmp_folder'] || Jekyll.logger.abort_with("Missing configuration 'plantuml.tmp_folder'.")
end