-
Notifications
You must be signed in to change notification settings - Fork 451
/
Copy pathsite.rb
53 lines (39 loc) · 899 Bytes
/
site.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
class Site
DOC_TYPES = %w{step md deck.md mw}
@@here = File.expand_path(File.dirname(__FILE__))
@@project_root = File.dirname(@@here)
def self.sites_dir
File.expand_path('sites', @@project_root)
end
def self.all
Dir[File.join(sites_dir, '*')].map{|dir| Site.new(dir)}
end
def self.named name
site = all.detect { |folder| folder.name == name }
raise "No site found with the name '#{name}'" unless site
site
end
attr_reader :dir
def initialize dir
@dir = dir
end
def name
@dir.split('/').last
end
def docs
file_path_glob = File.join(@dir, "*.{#{DOC_TYPES.join(',')}}")
Dir[file_path_glob].map{|path| Doc.new(path)}
end
class Doc
attr_reader :path
def initialize path
@path = path
end
def filename
File.basename(@path)
end
def name
filename.split('.').first
end
end
end