Skip to content

Commit 6c11083

Browse files
kevinansfieldtoddjordan
authored andcommitted
Add heading anchors to allow deep-linking
closes #494 - adds `id` attributes to headings so they can be linked to with #anchor URLs - utilises the same "anchorable" markup and image as used in the Ember guides to show a 🔗 icon next to headings on hover
1 parent efe6b54 commit 6c11083

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

app/helpers/function-heading-id.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { helper } from '@ember/component/helper';
2+
import { A } from '@ember/array';
3+
4+
export function functionHeadingId([heading]/*, hash*/) {
5+
return `functions-${A(heading.split('/')).get('lastObject')}`;
6+
}
7+
8+
export default helper(functionHeadingId);

app/templates/project-version/modules/module.hbs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515

1616
{{#if submodules}}
1717
<section>
18-
<h2>Submodules</h2>
18+
<h2 id="submodules" class="anchorable-toc">
19+
<a href="#submodules" class="toc-anchor"></a>
20+
Submodules
21+
</h2>
1922
<ul class="spec-method-list">
2023
{{#each submodules as |module|}}
2124
<li>
@@ -30,7 +33,10 @@
3033

3134
{{#if classesAndNamespaces}}
3235
<section>
33-
<h2>Classes</h2>
36+
<h2 id="classes" class="anchorable-toc">
37+
<a href="#classes" class="toc-anchor"></a>
38+
Classes
39+
</h2>
3440
<ul class="spec-property-list">
3541
{{#each classesAndNamespaces as |klass|}}
3642
{{#if (not (and (eq model.name "ember-data") (eq klass "Ember")))}}
@@ -47,9 +53,15 @@
4753

4854
{{#if (and functionHeadings (gt functionHeadings.length 0)) }}
4955

50-
<h2>Functions</h2>
56+
<h2 id="functions" class="anchorable-toc">
57+
<a href="#functions" class="toc-anchor"></a>
58+
Functions
59+
</h2>
5160
{{#each functionHeadings as |funcHeading|}}
52-
<h4>{{funcHeading}}</h4>
61+
<h4 id="{{function-heading-id funcHeading}}" class="anchorable-toc">
62+
<a href="#{{function-heading-id funcHeading}}" class="toc-anchor"></a>
63+
{{funcHeading}}
64+
</h4>
5365
<ul class="spec-method-list">
5466
{{#each (better-get functions funcHeading) as |method|}}
5567
<li>

public/assets/images/link.png

701 Bytes
Loading
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
import { moduleForComponent, test } from 'ember-qunit';
3+
import hbs from 'htmlbars-inline-precompile';
4+
5+
moduleForComponent('function-heading-id', 'helper:function-heading-id', {
6+
integration: true
7+
});
8+
9+
test('should transform nested package to id', function(assert) {
10+
this.set('inputValue', '@ember/object/computed');
11+
12+
this.render(hbs`{{function-heading-id inputValue}}`);
13+
14+
assert.equal(this.$().text().trim(), 'functions-computed');
15+
});

0 commit comments

Comments
 (0)