Class: Jekyll::PlantumlBlock

Inherits:
Liquid::Block
  • Object
show all
Defined in:
lib/jekyll-plantuml.rb

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ PlantumlBlock

Returns a new instance of PlantumlBlock.



28
29
30
31
# File 'lib/jekyll-plantuml.rb', line 28

def initialize(tag_name, markup, tokens)
  super
  @html = (markup or '').strip
end

Instance Method Details

#render(context) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/jekyll-plantuml.rb', line 33

def render(context)
  site = context.registers[:site]
  name = Digest::MD5.hexdigest(super)
  if !File.exists?(File.join(site.dest, "uml/#{name}.svg"))
    uml = File.join(site.source, "uml/#{name}.uml")
    svg = File.join(site.source, "uml/#{name}.svg")
    if File.exists?(svg)
      puts "File #{svg} already exists (#{File.size(svg)} bytes)"
    else
      FileUtils.mkdir_p(File.dirname(uml))
      File.open(uml, 'w') { |f|
        f.write("@startuml\n")
        f.write(super)
        f.write("\n@enduml")
      }
      system("plantuml -tsvg #{uml}")
      site.static_files << Jekyll::StaticFile.new(
        site, site.source, 'uml', "#{name}.svg"
      )
      puts "File #{svg} created (#{File.size(svg)} bytes)"
    end
  end
  "<p><img src='#{site.baseurl}/uml/#{name}.svg' #{@html}
    alt='PlantUML SVG diagram' class='plantuml'/></p>"
end