Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 58 lines (49 sloc) 1.689 kb
7ae7493 @jingweno Pull back man page rake task from https://github.com/github/hub/blob/1.1...
jingweno authored
1 desc "Show man page"
2 task :man => "man:build" do
3 exec "man man/hub.1"
4 end
5
6 desc "Build man pages"
7 task "man:build" => ["man/hub.1", "man/hub.1.html"]
8
95f1a37 @jingweno Replace man page configurations with the ones from README.md
jingweno authored
9 # split readme in sections
10 # and return the specified section
11 def split_readme(file, index)
12 File.read(file).split(/^-{4,}$/)[index].strip
13 end
14
15 def extract_configs(readme_file)
16 configs = split_readme(readme_file, 4)
17 configs.gsub!(/\*\*(.+?)\*\*/, '<\1>') # replace **xx** with <xx>
18 configs.sub!(/\n+.+\Z/, '') # remove last line
19 configs
20 end
21
22 def extract_examples(readme_file)
23 examples = split_readme(readme_file, 3)
7ae7493 @jingweno Pull back man page rake task from https://github.com/github/hub/blob/1.1...
jingweno authored
24 examples.sub!(/^.+?(###)/m, '\1') # strip intro paragraph
25 examples.sub!(/\n+.+\Z/, '') # remove last line
26 examples
95f1a37 @jingweno Replace man page configurations with the ones from README.md
jingweno authored
27 end
7ae7493 @jingweno Pull back man page rake task from https://github.com/github/hub/blob/1.1...
jingweno authored
28
95f1a37 @jingweno Replace man page configurations with the ones from README.md
jingweno authored
29 # inject configs and examples from README file to .ronn source
30 def compiled_source(source, readme)
31 configs = extract_configs(readme)
32 examples = extract_examples(readme)
7ae7493 @jingweno Pull back man page rake task from https://github.com/github/hub/blob/1.1...
jingweno authored
33 compiled = File.read(source)
95f1a37 @jingweno Replace man page configurations with the ones from README.md
jingweno authored
34 compiled.sub!('{{CONFIGS}}', configs)
7ae7493 @jingweno Pull back man page rake task from https://github.com/github/hub/blob/1.1...
jingweno authored
35 compiled.sub!('{{README}}', examples)
36 compiled
95f1a37 @jingweno Replace man page configurations with the ones from README.md
jingweno authored
37 end
7ae7493 @jingweno Pull back man page rake task from https://github.com/github/hub/blob/1.1...
jingweno authored
38
39 # generate man page with ronn
95f1a37 @jingweno Replace man page configurations with the ones from README.md
jingweno authored
40 def compile_ronn(destination, type, contents)
7ae7493 @jingweno Pull back man page rake task from https://github.com/github/hub/blob/1.1...
jingweno authored
41 File.popen("ronn --pipe --#{type} --organization=GITHUB --manual='Hub Manual'", 'w+') { |io|
42 io.write contents
43 io.close_write
44 File.open(destination, 'w') { |f| f << io.read }
45 }
46 abort "ronn --#{type} conversion failed" unless $?.success?
95f1a37 @jingweno Replace man page configurations with the ones from README.md
jingweno authored
47 end
7ae7493 @jingweno Pull back man page rake task from https://github.com/github/hub/blob/1.1...
jingweno authored
48
49 file "man/hub.1" => ["man/hub.1.ronn", "README.md"] do |task|
95f1a37 @jingweno Replace man page configurations with the ones from README.md
jingweno authored
50 contents = compiled_source(*task.prerequisites)
51 compile_ronn(task.name, 'roff', contents)
52 compile_ronn("#{task.name}.html", 'html', contents)
7ae7493 @jingweno Pull back man page rake task from https://github.com/github/hub/blob/1.1...
jingweno authored
53 end
54
55 file "man/hub.1.html" => ["man/hub.1.ronn", "README.md"] do |task|
56 Rake::Task["man/hub.1"].invoke
57 end
Something went wrong with that request. Please try again.