Skip to content

Commit cdbe97e

Browse files
committed
Site index dropdown contains categories like on docs.step
1 parent e46e5e7 commit cdbe97e

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

lib/site_index.rb

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,24 @@ class SiteIndex < Erector::Widget
22
needs :site_name, :locale
33
attr_accessor :site_name
44

5+
def categorized_sites
6+
{
7+
'setup' => ['installfest'],
8+
'rails' => ['intro-to-rails', 'job-board', 'intermediate-rails'],
9+
'frontend' => ['frontend', 'intro-to-javascript'],
10+
'ruby' => ['learn-to-code', 'ruby']
11+
}
12+
end
13+
514
def sites
615
return @sites if @sites
716
@sites = Dir.glob("#{Site.sites_dir(@locale)}/**").map { |filename| File.basename(filename) }.sort
817
end
918

19+
def site_category category
20+
li Titleizer.title_for_page(category), class: 'category'
21+
end
22+
1023
def site_link site
1124
if site == site_name
1225
return li Titleizer.title_for_page(site_name), class: 'current'
@@ -20,7 +33,14 @@ def site_link site
2033

2134
def content
2235
ul :class => "dropdown-menu" do
23-
sites.each do |site|
36+
categorized_sites.each do |category, category_sites|
37+
site_category category
38+
category_sites.each do |site|
39+
site_link site
40+
end
41+
end
42+
site_category I18n.t('sites.other_categories')
43+
(sites - categorized_sites.values.flatten).each do |site|
2444
site_link site
2545
end
2646
end

locales/en.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ en:
2929
challenge: "Challenge(s)"
3030
tools_and_references: "Tools and References"
3131
requirements: "Requirements to advance"
32+
33+
sites:
34+
other_categories: Other Stuff

public/css/header.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ nav *, nav *:before, nav *:after {
5454
font-weight: bold;
5555
color: #333;
5656
}
57+
&.category {
58+
padding: 0 5px;
59+
font-weight: bold;
60+
}
5761

5862
a {
5963
color: #333;

spec/site_index_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
@site_index.sites.should =~ all_sites
1414
end
1515

16+
it "only references existing sites in the 'categorized_sites' method" do
17+
@site_index.sites.should include(*@site_index.categorized_sites.values.flatten)
18+
end
19+
1620
it "emboldens the current site, links other sites" do
1721
index_html = Nokogiri.parse(@site_index.to_html)
1822

0 commit comments

Comments
 (0)