Skip to content

Commit

Permalink
Merge pull request emberjs#9 from serenaf/serena/add-toc
Browse files Browse the repository at this point in the history
Adding a table of contents component
  • Loading branch information
serenaf authored Jan 7, 2018
2 parents 2f2f2d8 + 4c9bbc0 commit 9e2f67c
Show file tree
Hide file tree
Showing 24 changed files with 121 additions and 32 deletions.
13 changes: 13 additions & 0 deletions app/components/table-of-contents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Component from '@ember/component';
import { get, computed } from '@ember/object';

export default Component.extend({
elementId: 'toc-list',
tagName: 'ol',
tocLevel: computed('level', function() {
return `level-${get(this, 'level')}`;
}),
level: '1',
sortDefinition: ['since'],
sortedGroupedResults: computed.sort('groupedResults', 'sortDefinition')
});
21 changes: 21 additions & 0 deletions app/controllers/v2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Controller from '@ember/controller';
import EmberObject, { computed } from '@ember/object';

export default Controller.extend({
groupedResults: computed('sortedResults.[]', function() {
let result = [];
this.get('content').forEach(function(item) {
let since = result.findBy('since', item.get('since'));
if(!since) {
result.pushObject(EmberObject.create({
since: item.get('since'),
contents: []
}));
}
result.findBy('since', item.get('since')).get('contents').pushObject(item);
});
return result;
}),
sortDefinition: ['since'],
sortedResults: computed.sort('content.[]', 'sortDefinition')
});
2 changes: 2 additions & 0 deletions app/models/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ import DS from 'ember-data';
export default DS.Model.extend({
content: DS.attr('string'),
title: DS.attr('string'),
until: DS.attr('string'),
since: DS.attr('number')
});
10 changes: 10 additions & 0 deletions app/styles/_table_of_content.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#sidebar ol#toc-list li.level-1 {
text-transform: uppercase;
}

#sidebar ol#toc-list li {
font-size: 12px;
list-style: none;
margin: 0px;
padding: 0px;
}
10 changes: 1 addition & 9 deletions app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,7 @@
</header>

<div id="content-wrapper">
<div id="sidebar">
<ol id='toc-list'>
</ol>

<div id="back-to-top"><a id="back-top-top" href="#">&#11014; Back to Top</a></div>
</div>
<div class="has-sidebar" id="content">
{{outlet}}
</div>
{{outlet}}
</div>

<div class="footer">
Expand Down
4 changes: 2 additions & 2 deletions app/templates/components/deprecation-article.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h4>{{model.title}}</h4>
{{!-- <h6>until: <%= resource.data.until %></h6>
<h6>id: <%= resource.data.id %></h6> --}}
<h6>UNTIL: {{model.until}}</h6>
<h6>SINCE: {{model.since}}</h6>
<p>
{{markdown-to-html model.content}}
</p>
7 changes: 7 additions & 0 deletions app/templates/components/table-of-contents.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{#each sortedGroupedResults as |result|}}
<li class="level-1">
<a class="slide-widget-head" href="#toc toc_deprecations-added-in-ember-2-x">
Deprecations added in {{result.since}}
</a>
</li>
{{/each}}
22 changes: 15 additions & 7 deletions app/templates/v2.hbs
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
<h2 class="anchorable-toc" id="toc_deprecations-added-in-ember-2-x"><a class="toc-anchor" href="#toc_deprecations-added-in-ember-2-x"></a>Deprecations Added in Ember 2.x</h2>
<p>What follows is a list of deprecations introduced to Ember.js during the 2.x
cycle.</p>
<p>For more information on deprecations in Ember, see the <a href="/deprecations">main deprecations page</a>.</p>
<div id="sidebar">
{{table-of-contents groupedResults=groupedResults}}
<div id="back-to-top"><a id="back-top-top" href="#">&#11014; Back to Top</a></div>
</div>

{{#each model as |deprecation|}}
{{deprecation-article model=deprecation}}
{{/each}}
<div class="has-sidebar" id="content">

<h2 class="anchorable-toc" id="toc_deprecations-added-in-ember-2-x"><a class="toc-anchor" href="#toc_deprecations-added-in-ember-2-x"></a>Deprecations Added in Ember 2.x</h2>
<p>What follows is a list of deprecations introduced to Ember.js during the 2.x
cycle.</p>
<p>For more information on deprecations in Ember, see the <a href="/deprecations">main deprecations page</a>.</p>

{{#each sortedResults as |deprecation|}}
{{deprecation-article model=deprecation}}
{{/each}}
</div>
2 changes: 1 addition & 1 deletion content/ember/v2/application-instance-container.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: ember-application.app-instance-container
name: Ember.ApplicationInstance#container
title: Ember.ApplicationInstance#container
until: 3.0.0
since: 2.1
---
Expand Down
2 changes: 1 addition & 1 deletion content/ember/v2/application-registry.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: ember-application.app-instance-registry
name: Ember.Application#registry / Ember.ApplicationInstance#registry
title: Ember.Application#registry / Ember.ApplicationInstance#registry
until: 3.0.0
since: 2.1
---
Expand Down
2 changes: 1 addition & 1 deletion content/ember/v2/current-state.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: ember-view.current-state
name: Ember.Component#currentState
title: Ember.Component#currentState
until: 2.3.0
since: 2.1
---
Expand Down
2 changes: 1 addition & 1 deletion content/ember/v2/debug-function-options.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: ember-debug.deprecate-options-missing, ember-debug.deprecate-id-missing, ember-debug.deprecate-until-missing, ember-debug.warn-options-missing, ember-debug.warn-id-missing
name: Ember debug function options
title: Ember debug function options
until: 3.0.0
since: 2.1
---
Expand Down
2 changes: 1 addition & 1 deletion content/ember/v2/default-layout.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: ember-views.component.defaultLayout
name: Ember.Component#defaultLayout
title: Ember.Component#defaultLayout
until: 3.0.0
since: 2.1
---
Expand Down
2 changes: 1 addition & 1 deletion content/ember/v2/ember-backburner.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: ember-metal.ember-backburner
name: Ember.Backburner
title: Ember.Backburner
until: 2.8.0
since: 2.7
---
Expand Down
2 changes: 1 addition & 1 deletion content/ember/v2/ember-binding.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: ember-metal.binding
name: Ember.Binding
title: Ember.Binding
until: 3.0.0
since: 2.7
---
Expand Down
2 changes: 1 addition & 1 deletion content/ember/v2/enumerable-contains.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: ember-runtime.enumerable-contains
name: Enumerable#contains
title: Enumerable#contains
until: 3.0.0
since: 2.8
---
Expand Down
2 changes: 1 addition & 1 deletion content/ember/v2/html-safe.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: ember-htmlbars.ember-handlebars-safestring
name: Use Ember.String.htmlSafe over Ember.Handlebars.SafeString
title: Use Ember.String.htmlSafe over Ember.Handlebars.SafeString
until: 3.0.0
since: 2.8
---
Expand Down
2 changes: 1 addition & 1 deletion content/ember/v2/init-attrs.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: ember-views.did-init-attrs
name: Ember.Component#didInitAttrs
title: Ember.Component#didInitAttrs
until: 3.0.0
since: 2.6
---
Expand Down
2 changes: 1 addition & 1 deletion content/ember/v2/injected-container-access.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: ember-application.injected-container
name: Injected container access
title: Injected container access
until: 3.0.0
since: 2.3
---
Expand Down
2 changes: 1 addition & 1 deletion content/ember/v2/model-params-render.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: ember-template-compiler.deprecate-render-model
name: Model param in render helper
title: Model param in render helper
until: 3.0.0
since: 2.6
---
Expand Down
2 changes: 1 addition & 1 deletion content/ember/v2/render-helper.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: ember-template-compiler.deprecate-render-block
name: render helper with block
title: render helper with block
until: 2.4.0
since: 2.4
---
Expand Down
2 changes: 1 addition & 1 deletion content/ember/v2/test-as-function.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: ember-debug.deprecate-test-as-function
name: Function as test in Ember.deprecate, Ember.warn, Ember.assert
title: Function as test in Ember.deprecate, Ember.warn, Ember.assert
until: 2.5.0
since: 2.2
---
Expand Down
24 changes: 24 additions & 0 deletions tests/integration/components/table-of-contents-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';

moduleForComponent('table-of-contents', 'Integration | Component | table of contents', {
integration: true
});

test('it renders', function(assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });

this.render(hbs`{{table-of-contents}}`);

assert.equal(this.$().text().trim(), '');

// Template block usage:
this.render(hbs`
{{#table-of-contents}}
template block text
{{/table-of-contents}}
`);

assert.equal(this.$().text().trim(), 'template block text');
});
12 changes: 12 additions & 0 deletions tests/unit/controllers/v2-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { moduleFor, test } from 'ember-qunit';

moduleFor('controller:v2', 'Unit | Controller | v2', {
// Specify the other units that are required for this test.
// needs: ['controller:foo']
});

// Replace this with your real tests.
test('it exists', function(assert) {
let controller = this.subject();
assert.ok(controller);
});

0 comments on commit 9e2f67c

Please sign in to comment.