-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext.rb
More file actions
45 lines (34 loc) · 1.07 KB
/
text.rb
File metadata and controls
45 lines (34 loc) · 1.07 KB
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
require 'rubygems'
require 'erb'
require 'maruku'
def load(database)
graphs = []
open(database).each do |line|
name, data = line.gsub('(', '|[').gsub(')', ']').split('|')
data = eval(data)
nodes = {}
data[3].each_with_index {|c, i| nodes["#{i+1}"] = c.join(',')}
graphs << {
:name => name, :n => data[0], :m => data[1],
:degrees => data[2].map {|x, y| [x] * y}.flatten,
:nodes => nodes, :edges => data[4],
}
end
graphs
end
def create_template(filename); ERB.new(open(filename).read); end
GRAPHS = load('database.gdb')
GRAPHVIZ = create_template('graph.dot.erb')
README = Maruku.new(open('README.md').read).to_html
INDEX = create_template('index.html.erb')
ABOUT = create_template('about.html.erb')
GRAPH_PAGE = create_template('graph.html.erb')
open('public/index.html', 'w').puts(INDEX.result)
open('public/about.html', 'w').puts(ABOUT.result)
GRAPHS.each do |graph|
g = graph
open("dot/#{g[:name]}.dot", 'w').
puts(GRAPHVIZ.result(binding))
open("public/#{g[:name]}.html", 'w').
puts(GRAPH_PAGE.result(binding))
end