summaryrefslogtreecommitdiffstats
path: root/docs/Rakefile.manual
blob: 03eccb0f147a860c2301f560f5afd06d5aef1c63 (plain)
1
2
3
4
5
6
7
8
9
10
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
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