-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
55 lines (45 loc) · 881 Bytes
/
app.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
require 'sinatra'
require 'sinatra/reloader'
require 'slim'
require 'coffee-script'
require 'json'
class ModulesGraph
attr_reader :tree
def initialize(const)
@tree = build(const)
end
protected
def build(const)
{
name: const.name.split('::').last,
path: const.name.gsub('::', '/'),
children: nested_modules(const)
}
end
def nested_modules(const)
return [] if const.is_a? Class
const.constants
.sort
.map { |c| const.const_get(c) }
.select { |c| c.is_a? Module }
.map { |c| build(c) }
end
end
helpers do
def json(value)
content_type :json
value.to_json
end
end
get '/application.css' do
scss :application
end
get '/application.js' do
coffee :application
end
get '/data.json' do
json ModulesGraph.new(Sinatra).tree
end
get '/' do
slim :index
end