-
Notifications
You must be signed in to change notification settings - Fork 469
Share Aliki class navigation across generated pages #1840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
skatkov
wants to merge
11
commits into
ruby:master
Choose a base branch
from
skatkov:shared-class-navigation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e75c46b
Share Aliki class navigation across generated pages
ampagent 9820723
Use existing search_data.index
skatkov 7d98fa2
navigation should renders into root <ul>
skatkov 95967fe
remove table_of_ocntents and extra link that we added.
skatkov 1db8e80
remove refute_file assertions
skatkov bef02d1
render all navigation links immediately, without listeners
skatkov d0ce24f
simplify
skatkov 78f6701
remove redundant tests
skatkov 7d54e9f
renamed id to 'namespace-navigation'
skatkov cf3ff01
better specs
skatkov 362a3ef
remove tests
skatkov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,70 @@ | ||
| 'use strict'; | ||
|
|
||
| // Reuse the search index's visible classes and modules, adding unlinked | ||
| // ancestors where a namespace is hidden but has visible descendants. | ||
| function buildClassTree(index) { | ||
| const roots = []; | ||
| const byName = new Map(); | ||
|
|
||
| index.forEach((entry) => { | ||
| if (entry.type !== 'class' && entry.type !== 'module') return; | ||
|
|
||
| let children = roots; | ||
| let fullName = ''; | ||
| entry.full_name.split('::').forEach((name) => { | ||
| fullName = fullName ? fullName + '::' + name : name; | ||
| let node = byName.get(fullName); | ||
| if (!node) { | ||
| node = {name, path: null, children: []}; | ||
| byName.set(fullName, node); | ||
| children.push(node); | ||
| } | ||
| children = node.children; | ||
| }); | ||
| byName.get(fullName).path = entry.path; | ||
| }); | ||
|
|
||
| return roots; | ||
| } | ||
|
|
||
| // Share the class tree across pages without embedding it in every page's HTML. | ||
| function buildClassNavigation(container, nodes, prefix) { | ||
| function renderBranch(entries, list, expandSingleRoot = false) { | ||
| list.className = 'link-list nav-list'; | ||
|
|
||
| entries.forEach((node) => { | ||
| const item = document.createElement('li'); | ||
| const code = document.createElement('code'); | ||
| if (node.path) { | ||
| const link = document.createElement('a'); | ||
| link.href = prefix + node.path; | ||
| link.textContent = node.name; | ||
| code.appendChild(link); | ||
| } else { | ||
| code.textContent = node.name; | ||
| } | ||
|
|
||
| if (node.children.length) { | ||
| const details = document.createElement('details'); | ||
| const summary = document.createElement('summary'); | ||
| summary.appendChild(code); | ||
| details.appendChild(summary); | ||
| details.appendChild(renderBranch(node.children, document.createElement('ul'))); | ||
| details.open = expandSingleRoot; | ||
| item.appendChild(details); | ||
| } else { | ||
| item.appendChild(code); | ||
| } | ||
| list.appendChild(item); | ||
| }); | ||
| return list; | ||
| } | ||
|
|
||
| renderBranch(nodes, container, nodes.length === 1); | ||
| } | ||
|
|
||
| document.addEventListener('DOMContentLoaded', () => { | ||
| const container = document.getElementById('namespace-navigation'); | ||
| if (!container || typeof search_data === 'undefined') return; | ||
| buildClassNavigation(container, buildClassTree(search_data.index), index_rel_prefix); | ||
| }); |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this method still be needed?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is still used in the Darkfish generator.
The Darkfish generator has same problem as well as Aliki. But because Darkfish is already deprecated, I assume there is no need to do similar changes to Darkfish.