forked from OpenNebula/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_index.rb
66 lines (56 loc) · 1.73 KB
/
generate_index.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
59
60
61
62
63
64
65
66
#!/usr/bin/env ruby
require "pp"
require "erb"
def path_to_url(path)
path.gsub(%r{^source/},"").
gsub(%r{\.rst},".html")
end
def get_toc(file)
guides = []
File.read(file).scan(/^\s*(.*?)\s*<(.*)>\s*$/).each do |name, relative_path|
path = File.join(File.dirname(file), relative_path + ".rst")
guide = {
:name => name,
:path => path,
:url => path_to_url(path)
}
if relative_path.include?("/")
guide[:children] = get_toc(path)
end
guides << guide
end
guides
end
toc = get_toc('source/index.rst')
nrow = -1
toc_template = %q{
<h3><i class="fa fa-book"></i> <%= manual[:name] %></h3>
<div class="ofp-boxes">
<% manual[:children].each do |box| %>
<% nbox = nboxes.next %>
<% nrow += 1 if nbox == 1 %>
<div class="ofp-box ofp-box-<%= nbox %> ofp-box-row-<%= nrow %>">
<a href="<%= box[:url] %>">
<%= box[:name] %>
</a>
<ul>
<% box[:children].each do |guide| %>
<li>
<a href="<%= guide[:url] %>">
<%= guide[:name]%>
</a>
</li>
<% end %>
</ul>
</div><!-- close ofp-box -->
<% end %>
</div><!-- close ofb-boxes -->
}
puts %q{<div id="opennebula-frontpage">}
toc.each do |manual|
nboxes = (1..3).cycle
# styles = ['ofp-box-1','ofp-box-2','ofp-box-3'].cycle
puts ERB.new(toc_template).result(binding)
end
puts %q{</div><!-- close opennebula-frontpage -->}
puts %q{<div class="clear-both"></div>}