Skip to content

Commit f4e643f

Browse files
erkieknownasilya
authored andcommitted
feat: Make it possible to specify that a token should ALWAYS be in front (#152)
* Add a new attribute called 'front' to ensure that the token is ALWAYS appended at the start * PR feedback: Remove unused route, add description column to README
1 parent d32c4e9 commit f4e643f

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ This file is added automatically if you use `ember install`. This is for all the
3232

3333
### API
3434

35-
| attribute | type | default |
36-
|-----------|:--------|:--------|
37-
| separator | string | `" \| "`|
38-
| prepend | boolean | true |
39-
| replace | boolean | false |
35+
| attribute | type | default | description |
36+
|-----------|:--------|:--------|:--------------------------------------------------------------------------|
37+
| separator | string | `" \| "`| Which separator should be displayed _after_ this instance of `{{title }}` |
38+
| prepend | boolean | true | If the token should be prepended or appended to the list of tokens |
39+
| replace | boolean | false | Replace all previous elements with the active |
40+
| front | boolean | false | If the token should always be in the beginning of the resulting title. |
4041

4142
These defaults are configurable in `config/environment.js`:
4243

addon/services/page-title-list.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,11 @@ export default Service.extend({
147147
let appending = true;
148148
let group = [];
149149
let groups = A([group]);
150+
let frontGroups = [];
150151
visible.forEach((token) => {
151-
if (token.prepend) {
152+
if (token.front) {
153+
frontGroups.unshift(token);
154+
} else if (token.prepend) {
152155
if (appending) {
153156
appending = false;
154157
group = [];
@@ -170,7 +173,9 @@ export default Service.extend({
170173
}
171174
});
172175

173-
return groups.reduce((E, group) => E.concat(group), []);
176+
return frontGroups.concat(
177+
groups.reduce((E, group) => E.concat(group), [])
178+
);
174179
}
175180
}),
176181

tests/acceptance/posts-test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,11 @@ module('Acceptance: title', function(hooks) {
8585
});
8686
assert.equal(title(), 'Tomster (@tomster)');
8787
});
88+
89+
test('front tokens work', async function (assert) {
90+
assert.expect(1);
91+
await visit('/reader');
92+
93+
assert.equal(title(), '(10) Reader | My App');
94+
});
8895
});

tests/dummy/app/router.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Router.map(function() {
1717
this.route('author', { path: '/authors/:author_id' });
1818
this.route('hollywood', { path: '/hollywood' });
1919
this.route('feed', { path: '/feeds/:name' });
20+
this.route('reader', { path: '/reader' });
2021
});
2122

2223
export default Router;

tests/dummy/app/templates/reader.hbs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{{title "Reader"}}
2+
3+
{{title "(10)" front=true separator=" "}}

0 commit comments

Comments
 (0)