Created
November 29, 2017 18:39
-
-
Save caius/f770a6a03a163b44fa6d97a233a0b3b2 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
require "pathname" | |
require "kramdown" | |
plan = Pathname.new("../plan.md").expand_path(__dir__) | |
output_dir = Pathname.new("../output").expand_path(__dir__) | |
output_dir.rmtree if output_dir.exist? | |
output_dir.mkdir | |
raw_plan = plan.read | |
md_output = [] | |
graph = [] | |
graph_counter = 1 | |
raw_plan.split("\n").each do |line| | |
if (line =~ /^```dot/) .. (line =~ /```\z/) | |
# Don't save markers | |
next if line.start_with?("```") | |
graph << line | |
next | |
end | |
# Just finished grabbing a graph | |
unless graph.empty? | |
graph_dot = output_dir.join("graph_#{graph_counter}.dot") | |
graph_png = graph_dot.sub_ext(".png") | |
graph_dot.open("w+") do |g| | |
g.puts graph | |
end | |
# Generate graph | |
%x[dot -Tpng #{graph_dot} > #{graph_png}] | |
graph_dot.delete | |
# Insert image tag for it into master doc | |
md_output << " " | |
md_output << "" | |
# Reset for next graph | |
graph_counter += 1 | |
graph = [] | |
next | |
end | |
# Just a normal line | |
md_output << line | |
end | |
output_dir.join("migration_plan.md").open("w+") do |plan| | |
plan.puts md_output | |
end | |
puts "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment