jleyba / js-dossier

A JavaScript documentation generation tool.
Apache License 2.0
149 stars 15 forks source link

More relevant breadcrumbs #82

Closed jleyba closed 7 years ago

jleyba commented 8 years ago

For each page, the type header currently links to the parent type. So we get something like:

<div><b>Namespace: </b><code><a>goog</a></code></div>
<h1>goog.Promise</h1>

The problem is while goog.Promise is a direct descendant of goog, it still needs to be explicitly required.

Option 1: Render the declarative statement.

<div><code>goog.provide(<a>'goog.Promise'</a>)</code></div>
<h1>Class goog.Promise</h1>

This doesn't work as well for types exported by a module:

<div><code>goog.module(<a>'foo.bar'</a>)</code></div>
<h1>Class SomeClass</h1>

Option 2: Render the import statement.

This works well for modules:

<div><code>const {SomeClass} = goog.require(<a>'foo.bar'</a>)</code></div>
<h1>Class SomeClass</h1>

It does not work as well for types that use goog.provide since the import statement depends on the context:

<div><code>goog.require(<a>'goog.Promise'</a>)</code></div>
<h1>Class goog.Promise</h1>
<div><code>const Promise = goog.require(<a>'goog.Promise'</a>)</code></div>
<h1>Class goog.Promise</h1>

I'm inclined to go with Option 1 and render the declaration for the closest parent (whether it's a goog.provide or goog.module style). In the case of CommonJS/ES6 modules, the module path would be rendered.