class PlantUmlConverterPlugin::PlantUmlConverter

Public Class Methods

new(config = {}) click to toggle source
# File lib/converters/plantuml-converter.rb, line 51
def initialize(config = {})
  @config = config['plantuml']
end

Public Instance Methods

convert(content) click to toggle source
# File lib/converters/plantuml-converter.rb, line 55
def convert(content)
  dest_uri = URI("#{@config['server_uri']}/svg/")
  
  begin
    iuml = filter_iuml(content)
    svg_res = Net::HTTP.post(dest_uri, iuml, 'Content-Type' => 'text/plain')

    unless (svg_res.kind_of? Net::HTTPSuccess)
      diag_name = content.lines.first.sub('@startuml ','').sub("\n", '')
      error_msg = svg_res['X-PlantUML-Diagram-Error']
      error_line = svg_res['X-PlantUML-Diagram-Error-Line']
      Jekyll.logger.error "Failed to render .iuml [#{diag_name}]: #{error_msg} at line #{error_line}"
      return ''
    end

    svg_res.body
  rescue => err
    diag_name = content.lines.first.sub('@startuml ','').sub("\n", '')
    Jekyll.logger.error "Failed to convert IUML document: #{diag_name} - #{err.message}"
    return ''
  end
end
filter_iuml(iuml) click to toggle source

Clean up markup as needed (matches)

Add "!theme spacelab" if no theme present and set background color
Add an @enduml that only seems to be needed for server rendering
# File lib/converters/plantuml-converter.rb, line 81
def filter_iuml(iuml)
  iuml_arr = iuml.split("\n")
  unless (iuml.include? '!theme')
    iuml_arr = iuml_arr.insert(1, '!theme spacelab')
  end
  unless (iuml.include? 'skinparam backgroundColor')
    iuml_arr = iuml_arr.insert(2, 'skinparam backgroundColor #333')
  end
  unless (iuml.include? '@enduml')
    iuml_arr = iuml_arr.push("@enduml")
  end
  iuml_arr.join("\n")
end
matches(ext) click to toggle source
# File lib/converters/plantuml-converter.rb, line 43
def matches(ext)
  ext =~ /^\.iuml$/i
end
output_ext(ext) click to toggle source
# File lib/converters/plantuml-converter.rb, line 47
def output_ext(ext)
  '.svg'
end