Skip to content

Commit

Permalink
[BUGFIX beta] Partially revert emberjs#12229 and add a test for ember…
Browse files Browse the repository at this point in the history
…js#13432

This PR partially reverts emberjs#12229 given that it made the inline form of
components extending from `LinkTo` impossible.

Beware that matching the exact behaviour is not there yet (as it wasn't
before emberjs#12229) given that {{{link-to title route}}} would unescape title
while {{{my-link-to title route}}} would not. This behaviour was not working
before and therefore is not working after this revert.

This PR does not address whether the inline form for link-to should be
deprecated or not.
  • Loading branch information
Serabe authored and toddjordan committed Sep 9, 2016
1 parent 9e9a86d commit 62e2b4e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 12 additions & 0 deletions packages/ember-routing-htmlbars/tests/helpers/link-to_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,16 @@ QUnit.test('able to safely extend the built-in component and use the normal path
equal(view.$().text(), 'my custom link-to component', 'rendered a custom-link-to component');
});

QUnit.test('[GH#13432] able to safely extend the built-in component and invoke it inline', function() {
view = EmberView.create({
[OWNER]: owner,
title: 'my custom link-to component',
template: compile('{{custom-link-to view.title \'index\'}}')
});

runAppend(view);

equal(view.$().text(), 'my custom link-to component', 'rendered a custom-link-to component');
});

}
8 changes: 6 additions & 2 deletions packages/ember-routing-views/lib/components/link-to.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ import EmberComponent from 'ember-views/components/component';
import inject from 'ember-runtime/inject';
import 'ember-runtime/system/service'; // creates inject.service
import ControllerMixin from 'ember-runtime/mixins/controller';
import { HAS_BLOCK } from 'ember-htmlbars/node-managers/component-node-manager';
import htmlbarsTemplate from 'ember-htmlbars/templates/link-to';
import require from 'require';

Expand Down Expand Up @@ -666,7 +667,7 @@ let LinkComponent = EmberComponent.extend({
if (lastParam && lastParam.isQueryParams) {
params.pop();
}
let onlyQueryParamsSupplied = (params.length === 0);
let onlyQueryParamsSupplied = (this[HAS_BLOCK] ? params.length === 0 : params.length === 1);
if (onlyQueryParamsSupplied) {
return get(this, '_routing.currentRouteName');
}
Expand Down Expand Up @@ -777,7 +778,10 @@ let LinkComponent = EmberComponent.extend({
}

// Process the positional arguments, in order.
// 1. Inline link title was shifted off by AST.
// 1. Inline link title comes first, if present.
if (!this[HAS_BLOCK]) {
this.set('linkTitle', params.shift());
}

// 2. `targetRouteName` is now always at index 0.
this.set('targetRouteName', params[0]);
Expand Down

0 comments on commit 62e2b4e

Please sign in to comment.