File: Rakefile.manual

package info (click to toggle)
jq 1.6-2.1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 2,236 kB
  • sloc: ansic: 13,418; yacc: 872; sh: 403; lex: 185; makefile: 158; javascript: 50; python: 20
file content (49 lines) | stat: -rw-r--r-- 1,263 bytes parent folder | download | duplicates (2)
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