Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Render TOC based on the selected version when viewing an API page
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio Scandurra committed Jul 5, 2019
1 parent 9c457cd commit ccef5c1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion layouts/api-class.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<%= renderp '/includes/search.html', :version => version %>

<div class="toc">
<%= renderp '/includes/toc.html', :heading => 'h4', :title => @item[:title] %>
<%= renderp '/includes/toc.html', :heading => 'h4', :title => @item[:title], :version => version %>
</div>

<div class="content-column">
Expand Down
8 changes: 4 additions & 4 deletions layouts/includes/toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
</ul>
<% end %>

<% klasses = latest_atom_version_class_names() %>
<% latest = latest_atom_version_number() %>
<% @version ||= latest_atom_version_number %>
<% klasses = atom_version_class_names(version) %>

<<%= @heading %>>
<a href="/api/v<%= latest %>/">Reference: API</a>
<a href="/api/v<%= @version %>/">Reference: API</a>
</<%= @heading %>>
<ul>
<% klasses.each do |name| %>
<li>
<a href="/api/v<%= latest %>/<%= name %>/"><%= name %></a>
<a href="/api/v<%= @version %>/<%= name %>/"><%= name %></a>
</li>
<% end %>
</ul>
Expand Down
6 changes: 3 additions & 3 deletions lib/versions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ def atom_version_apis(version)
items.map { |item| JSON.parse(File.read(item.raw_filename)) }
end

def latest_atom_version_class_names
temp_memoize('latest_atom_version_class_names') do
def atom_version_class_names(version)
temp_memoize("atom_#{version}_class_names") do
@items
.find_all("/api/v#{latest_atom_version_number}/*.json")
.find_all("/api/v#{version}/*.json")
.map { |item| File.basename(item.raw_filename, ".json") }
.sort
end
Expand Down

0 comments on commit ccef5c1

Please sign in to comment.