forked from AntonioFortunato/voiceofthebody.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstub_docs.rb
executable file
·58 lines (51 loc) · 1.24 KB
/
stub_docs.rb
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
#!/usr/bin/env ruby
require 'YAML'
DOCS_DIR = File.join(Dir.pwd, 'source')
def create_dir(dir)
return unless dir
Dir.mkdir(dir) unless Dir.exists?(dir)
end
def create_md_file(file, directory, children=[])
filename = file.split(' - ')[0]
title = file.split(' - ')[1]
file = File.join(directory, filename)
return if File.exists? file
nav = ''
if children
nav ="nav:\n"
children.each do |child|
child = child.keys[0] if child.is_a? Hash
next if child.match(/index|nav/)
nav +=" - '#{child.split('.')[0].chomp('/')}'\n"
end
end
if title
File.open(File.join(directory, filename), "w") do |f|
f.write <<eos
---
title: "#{title}"
#{nav}
---
# #{title}
eos
end
end
end
def process_contents(tree, parent)
tree.keys.each do |dir|
directory = File.join(parent, dir.chomp('/'))
create_dir directory
tree[dir].each do |dir_content|
if dir_content.is_a? String
children = nil
if dir_content.split(' - ')[0].match(/index\.md/)
children = tree[dir]
end
create_md_file(dir_content, directory, children)
else
process_contents(dir_content, directory)
end
end
end
end
process_contents(YAML.load_file('data/scaffold.yml'), DOCS_DIR)