forked from railsbridge/docs
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathsite_index.rb
55 lines (50 loc) · 1.52 KB
/
site_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
class SiteIndex < Erector::Widget
@@order = {"docs" => -1, "installfest" => 0, "intro" => 1, "intermediate" => 2, "advanced" => 3}
needs :site_name, :locale
attr_accessor :site_name
def sites
return @sites if @sites
@sites = Dir.glob("#{Site.sites_dir(@locale)}/**").map { |filename| File.basename(filename) }.sort do |a,b|
a_word = a.split(/[-_]/, 0)[0].downcase
b_word = b.split(/[-_]/, 0)[0].downcase
# One or more words are unknown
case
when (!@@order.key?(a_word) && !@@order.key?(b_word))
# Both unknown, so compare to each other
a <=> b
when (!@@order.key?(a_word) && @@order.key?(b_word))
# Unknown are higher precedence than all known
1
when (@@order.key?(a_word) && !@@order.key?(b_word))
# Opposite of above
-1
# Both are known
when @@order[a_word] == @@order[b_word]
# Both have the same order so compare to each other
a <=> b
when @@order[a_word] < @@order[b_word]
# Left has lower order than right
-1
else
# Right has lower order then left
1
end
end
end
def site_link site
if site == site_name
return li Titleizer.title_for_page(site_name), class: 'current'
end
path = "/#{site}/"
li do
a(Titleizer.title_for_page(site), :href => path)
end
end
def content
ul :class => "dropdown-menu" do
sites.each do |site|
site_link site
end
end
end
end