Created
July 13, 2016 00:00
-
-
Save mrk21/001f13f3f394edd19f21999e9da258c3 to your computer and use it in GitHub Desktop.
Make UML diagrams from a PlantUML script embedded in Markdown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'pp' | |
| require 'fileutils' | |
| file = ARGV[0] | |
| dirname = File.basename(file,'.*') | |
| FileUtils.mkdir_p dirname | |
| source = File.read(file) | |
| i = 1 | |
| source.gsub(/(?<=<!---).+?(?=--->)/m) do |m| | |
| name = "#{dirname}/#{i}.txt" | |
| outpath = nil | |
| code = m.split("\n")[1..-1] | |
| code[0].gsub!(/@startuml\{([^{]+)\}/) do | |
| outname = "#{i}_#{$1}" | |
| outpath = "#{dirname}/#{outname}" | |
| "@startuml{#{outname}}" | |
| end | |
| code = code.join("\n") | |
| code = code.gsub(/\\>/,'>') | |
| old_code = File.read(name) rescue nil | |
| if old_code.nil? || code != old_code then | |
| File.write(name, code) | |
| system "plantuml #{name} && open #{outpath}" | |
| end | |
| i+=1 | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment