-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #721 Using topic map to generate navigation
- Loading branch information
1 parent
cebec68
commit fd33efc
Showing
3 changed files
with
56 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require 'yaml' | ||
|
||
module CustomHelpers | ||
|
||
def navigation_menu | ||
navigation = "" | ||
topic_map = YAML.load_file('build/_topic_map.yml') | ||
topic_map["Topics"].each_with_index do |topic, index| | ||
topic_directory = topic["Dir"] | ||
if topic_directory.nil? | ||
next "<li><a class=\"\" href=\"/#{topic["File"]}.html\"> #{topic["Name"]}</a></li>" | ||
end | ||
|
||
caret = "fa-caret-right" | ||
in_class = "" | ||
subnav = "" | ||
entries = "" | ||
sub_topics = topic["Topics"] | ||
unless sub_topics.nil? | ||
sub_topics.each do |subtopic| | ||
path = current_page.url | ||
sub_topic_file = subtopic["File"] | ||
sub_topic_name = subtopic["Name"] | ||
if !path.end_with?("html") | ||
path += "index.html" | ||
end | ||
if path == "/#{topic_directory}/#{sub_topic_file}.html" | ||
in_class = "in" | ||
caret = "fa-caret-down" | ||
entries += "<li><a class=\"active\" href=\"/#{topic_directory}/#{sub_topic_file}.html\"> #{sub_topic_name}</a></li>" | ||
else | ||
entries += "<li><a class=\"\" href=\"/#{topic_directory}/#{sub_topic_file}.html\"> #{sub_topic_name}</a></li>" | ||
end | ||
end | ||
|
||
subnav += "<ul id=\"topicSubGroup-#{index}\" class=\"nav-tertiary list-unstyled collapse #{in_class}\">" | ||
subnav += entries | ||
subnav += "</ul>" | ||
end | ||
|
||
topic_nav = <<-HEREDOC | ||
<li class="nav-header"> | ||
<a class="" href="javascript:void(0);" data-toggle="collapse" data-target="#topicSubGroup-%d"> | ||
<span id="sgSpan-%d" class="fa %s"></span> %s | ||
</a> | ||
%s | ||
</li> | ||
HEREDOC | ||
navigation += topic_nav % [index, index, caret, topic["Name"], subnav] | ||
end | ||
|
||
navigation | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters