Class: Jekyll::StructurizrBlock
- Inherits:
-
Liquid::Block
- Object
- Liquid::Block
- Jekyll::StructurizrBlock
- Defined in:
- lib/jekyll-structurizr.rb
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens) ⇒ StructurizrBlock
constructor
A new instance of StructurizrBlock.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ StructurizrBlock
Returns a new instance of StructurizrBlock.
6 7 8 9 |
# File 'lib/jekyll-structurizr.rb', line 6 def initialize(tag_name, markup, tokens) super @html = (markup or '').strip end |
Instance Method Details
#render(context) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 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 |
# File 'lib/jekyll-structurizr.rb', line 11 def render(context) site = context.registers[:site] name = Digest::MD5.hexdigest(super) if !File.exists?(File.join(site.dest, "c4/#{name}.svg")) outputdir = File.join(site.source, "c4") dsl = File.join(site.source, "c4/#{name}.dsl") defaultuml = File.join(site.source, "c4/structurizr-SystemContext.puml") uml = File.join(site.source, "c4/#{name}.uml") svg = File.join(site.source, "c4/#{name}.svg") if File.exists?(svg) puts "File #{svg} already exists (#{File.size(svg)} bytes)" else FileUtils.mkdir_p(File.dirname(dsl)) File.open(dsl, 'w') { |f| @text = super # appendC4Beacon=true # if @text.include? "@starstructurizr" # appendC4Beacon = false # puts "stream already contains starstructurizr beacons" # end # if appendC4Beacon # f.write("@starstructurizr\n") # end f.write(super) # if appendC4Beacon # f.write("\n@endstructurizr") # end } puts "Exec : structurizr export -f plantuml/c4plantuml -o #{outputdir} -w #{dsl}" system("structurizr export -f plantuml/structurizr -o #{outputdir} -w #{dsl}") File.rename(defaultuml, uml) puts "File #{uml} created (#{File.size(uml)} bytes)" puts "plantuml -tsvg #{uml}" system("plantuml -tsvg #{uml}") site.static_files << Jekyll::StaticFile.new( site, site.source, 'c4', "#{name}.svg" ) puts "File #{svg} created (#{File.size(svg)} bytes)" end end "<div class='plantuml' style='width:fit-content'><object class='plantuml' data='#{site.baseurl}/c4/#{name}.svg' type='image/svg+xml' #{@html}></object></div>" end |