Skip to content

Commit b570cb8

Browse files
committed
separate chapter items into its own template, for reuse inside of pop-out navigation. add active classes to current chapter and item.
1 parent f6b779a commit b570cb8

File tree

3 files changed

+31
-30
lines changed

3 files changed

+31
-30
lines changed

layouts/chapter_contents.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<% myFolder = @item[:filename].split('/')[1] %>
2+
<% folderItems = @items.group_by {|item| item[:filename].split('/')[1] } %>
3+
<ul>
4+
<% folderItems[ myFolder ].sort_by {|i| i[:section] || 0 }. each do |i| %>
5+
<% if i[:title] && !(i[:filename] =~ /\/dex\.md$/) %>
6+
<li <% if item[:filename] == i[:filename] %>class="active"<% end %>><a href="<%= i.path %>"><%= i[:title] %></a></li>
7+
<% end %>
8+
<% end %>
9+
</ul>

layouts/dex.html

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,8 @@ <h2 class="title"><%= @item[:title] %></h2>
1111

1212
<%= yield %>
1313

14-
<% myFolder = @item[:filename].split('/')[1] %>
15-
<% folderItems = @items.group_by {|item| item[:filename].split('/')[1] } %>
16-
<ul>
17-
<% folderItems[ myFolder ].sort_by {|item| item[:section] || 0 }. each do |item| %>
18-
<% if item[:title] && !(item[:filename] =~ /\/dex\.md$/) %>
19-
<li><a href="<%= item.path %>"><%= item[:title] %></a></li>
20-
<% end %>
21-
<% end %>
22-
</ul>
14+
<%= render 'chapter_contents' %>
15+
2316
</div>
2417

2518
<%= render 'sidebar' %>

layouts/sidebar.html

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<!-- sidebar -->
22
<aside id="sidebar" class="clearfix autoHeight">
3-
4-
<h2>Categories</h2>
5-
<hr>
6-
7-
<ul class="nav">
3+
4+
<h2>Categories</h2>
5+
<hr>
6+
7+
<ul class="nav">
88
<% chapters = [
99
"getting-started",
1010
"javascript-101",
@@ -19,21 +19,20 @@ <h2>Categories</h2>
1919
"custom-events",
2020
"how-to"
2121
] %>
22-
<% folders = @items.group_by {|item| item[:filename].split('/')[1] } %>
23-
<% chapters.each do |section| %>
24-
<li><a href="/<%= section %>"><%= section.gsub(/-/, " ").upcase %></a></li>
25-
<% end %>
26-
</ul>
27-
28-
<div class="paper subnav">
29-
<div class="shadow"></div>
30-
<a href="#" class="paper_edges">Open</a>
31-
<div class="inner">
32-
<ul>
33-
<li></li>
34-
</ul>
35-
</div>
36-
</div>
37-
22+
<% currentChapter = @item[:filename].split('/')[1] %>
23+
<% folders = @items.group_by {|item| item[:filename].split('/')[1] } %>
24+
<% chapters.each do |chapter| %>
25+
<li <% if chapter == currentChapter %>class="active"<% end %>><a href="/<%= chapter %>"><%= chapter.gsub(/-/, " ").upcase %></a></li>
26+
<% end %>
27+
</ul>
28+
29+
<div class="paper subnav">
30+
<div class="shadow"></div>
31+
<a href="#" class="paper_edges">Open</a>
32+
<div class="inner">
33+
<%= render 'chapter_contents' %>
34+
</div>
35+
</div>
36+
3837
</aside>
3938
<!-- sidebar -->

0 commit comments

Comments
 (0)