Skip to content

Commit 4d3ac2f

Browse files
committed
Added a Site Index page to the upper-right menus
1 parent 29d20dc commit 4d3ac2f

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

lib/contents.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def toc_list toc_items
149149
end
150150

151151
def content
152-
div class: "toc" do
152+
div id: "table_of_contents", class: "toc" do
153153
h1 "Contents"
154154
toc_list hierarchy
155155

lib/doc_page.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'erector'
22
require "github_flavored_markdown"
33
require "contents"
4+
require "site_index"
45

56
class InstallfestExternalRenderer < ExternalRenderer
67
# render <style> tags plainly, without "text/css" (which browsers will assume by default)
@@ -216,8 +217,9 @@ def git_url
216217

217218
def top_links
218219
[
220+
TopLink.new(:name => "sites", :href => "#", :onclick => "$('#site_index').toggle(); return false;"),
219221
TopLink.new(:name => "src", :href => "#{file_name.split('.').first}/src"),
220-
TopLink.new(:name => "toc", :href => "#", :onclick => "$('div.toc').toggle(); return false;"),
222+
TopLink.new(:name => "toc", :href => "#", :onclick => "$('#table_of_contents').toggle(); return false;"),
221223
TopLink.new(:name => "git", :href => git_url),
222224
]
223225
end
@@ -233,6 +235,7 @@ def body_content
233235
}
234236

235237
widget Contents, site_name: site_name
238+
widget SiteIndex
236239

237240
div(:class=>:main) {
238241
h1 doc_title, :class=>"doc_title"

lib/site_index.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class SiteIndex < Erector::Widget
2+
@@here = File.expand_path(File.dirname(__FILE__))
3+
@@project_root = File.dirname(@@here)
4+
@@sites_dir = File.expand_path("sites", @@project_root)
5+
6+
def sites
7+
return @sites if @sites
8+
all_sites = Dir.glob("#{@@sites_dir}/**").map { |filename| File.basename(filename) }.sort
9+
@sites = all_sites - ['es']
10+
end
11+
12+
def site_link site
13+
path = "/#{site}/"
14+
li do
15+
a(site, :href => path)
16+
end
17+
end
18+
19+
def content
20+
div id: "site_index", class: "toc" do
21+
h1 "Site List"
22+
ul do
23+
sites.each do |site|
24+
site_link site
25+
end
26+
end
27+
end
28+
end
29+
end

spec/site_index_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
here = File.expand_path File.dirname(__FILE__)
2+
require "#{here}/spec_helper"
3+
4+
require "#{here}/../app"
5+
require "#{here}/../lib/site_index"
6+
7+
describe Contents do
8+
before :all do
9+
@site_index = SiteIndex.new
10+
end
11+
12+
it "lists all sites in the /sites/ directory, sorted, except 'es'" do
13+
@site_index.sites.should == ["curriculum", "frontend", "installfest", "workshop"]
14+
end
15+
end

0 commit comments

Comments
 (0)