require 'ronn' require 'tempfile' require 'yaml' def load_manual YAML::load(File.open("content/3.manual/manual.yml")) end task :manpage do Tempfile.open "manpage" do |f| manual = load_manual f.puts manual['manpage_intro'] f.puts manual['body'] manual['sections'].each do |section| f.puts "## #{section['title'].upcase}\n" f.puts section['body'] f.puts "" (section['entries'] || []).each do |entry| f.puts "### #{entry['title']}\n" f.puts entry['body'] f.puts "" (entry['examples'] || []).each do |example| f.puts " jq '#{example['program']}'" f.puts " #{example['input']}" f.puts " => #{example['output'].join(", ")}" f.puts end end f.puts "" end f.puts manual['manpage_epilogue'] f.close puts Ronn::Document.new(f.path).convert('roff').gsub(/<\/?code>/,"") end end task :mantests do load_manual['sections'].each do |section| (section['entries'] || []).each do |entry| (entry['examples'] || []).each do |example| puts example['program'].gsub("\n", " ") puts example['input'] example['output'].each do |s| puts s end puts end end end end