-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rakefile
61 lines (51 loc) · 1.67 KB
/
Rakefile
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
50
51
52
53
54
55
56
57
58
59
60
61
require 'rake'
require 'yaml'
CONFIG = YAML.load_file 'config/tech-docs.yml'
GITHUB_REPO = CONFIG['github_repo']
INPUT_DIR = 'wiki'
OUTPUT_DIR = 'source/documentation'
SEPARATOR = ';-'
WIKI_FILES = FileList["#{INPUT_DIR}/*"]
OUTPUT_FILES = WIKI_FILES.map {|n| File.join *n.gsub(INPUT_DIR, OUTPUT_DIR).gsub('.md','.html.md.erb').downcase.split(SEPARATOR) }
INDEX_FILE = File.join OUTPUT_DIR, '../', 'index.html.md.erb'
def patch relative_path, patch_filename
full_path = Gem.find_files(relative_path).first
unless full_path.nil?
sh 'patch', full_path, '-i', patch_filename
full_path
end
end
task default: :build
task pages: OUTPUT_FILES
task :patches do
full_path = patch("assets/javascripts/_modules/search.js", "gem-patches/search.js.patch")
unless full_path.nil?
mv full_path, full_path + ".erb"
end
end
task build: [:pages, :patches] do
sh 'middleman', 'build', '--verbose'
end
OUTPUT_FILES.zip(WIKI_FILES).each do |output, input|
directory File.dirname output
file output => [input, File.dirname(output)] do
title = output.pathmap('%f').split('.').first.gsub('-',' ').capitalize
output = (input.pathmap('%n') == 'Home') ? INDEX_FILE : output
File.open(output, 'w') do |o|
rake_output_message "echo ... > #{output}"
contents = File.read input
o.puts '---'
o.puts "title: \"#{title}\""
o.puts "source_url: \"#{File.join 'https://github.com', GITHUB_REPO, 'wiki', input.pathmap('%n')}\""
o.puts 'weight: 0' if output == INDEX_FILE
o.puts '---'
o.puts "# #{title}" unless contents =~ /^#\s\S+/
o.puts contents
end
end
end
task :clean do
rm_rf OUTPUT_DIR
rm_rf INDEX_FILE
rm_rf 'build'
end