Skip to content

Commit fc4df51

Browse files
Christian Wesselhoeftwagenet
authored andcommitted
[FEATURE ember-handlebars-caps-lookup] Use Ember.lookup as context for {{CONSTANT}}. Fixes #3098
1 parent a372b01 commit fc4df51

File tree

5 files changed

+50
-17
lines changed

5 files changed

+50
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
* Add query params support to the ember router. You can now define which query params your routes respond to, use them in your route hooks to affect model loading or controller state, and transition query parameters with the link-to helper and the transitionTo method
77
* Add named substates; e.g. when resolving a `loading` or `error` substate to enter, Ember will take into account the name of the immediate child route that the `error`/`loading` action originated from, e.g. 'foo' if `FooRoute`, and try and enter `foo_error` or `foo_loading` if it exists. This also adds the ability for a top-level `application_loading` or `application_error` state to be entered for `loading`/`error` events emitted from `ApplicationRoute`.
8+
* Ensure Handlebars values starting with capital letters are always looked up on `Ember.lookup`.
89

910
### Ember 1.2.0 _(TBD)_
1011

FEATURES.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ for a detailed explanation.
9494

9595
Add named substates; e.g. when resolving a `loading` or `error`
9696
substate to enter, Ember will take into account the name of the
97-
immediate child route that the `error`/`loading` action originated
98-
from, e.g. 'foo' if `FooRoute`, and try and enter `foo_error` or
99-
`foo_loading` if it exists. This also adds the ability for a
97+
immediate child route that the `error`/`loading` action originated
98+
from, e.g. 'foo' if `FooRoute`, and try and enter `foo_error` or
99+
`foo_loading` if it exists. This also adds the ability for a
100100
top-level `application_loading` or `application_error` state to
101-
be entered for `loading`/`error` events emitted from
101+
be entered for `loading`/`error` events emitted from
102102
`ApplicationRoute`.
103103

104104
Added in [#3655](https://github.com/emberjs/ember.js/pull/3655).
@@ -112,3 +112,11 @@ for a detailed explanation.
112112
`setupForTesting` (i.e. in a deferred state of readiness).
113113

114114
Added in [#3695](https://github.com/emberjs/ember.js/pull/3695).
115+
116+
* `ember-handlebars-caps-lookup`
117+
Forces Handlebars values starting with capital letters, like `{{CONSTANT}}`,
118+
to always be looked up on `Ember.lookup`. Previously, these values would be
119+
looked up on the controller in certain cases.
120+
121+
Added in [#3218](https://github.com/emberjs/ember.js/pull/3218)
122+

features.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"string-humanize": null,
1111
"propertyBraceExpansion": null,
1212
"ember-routing-named-substates": null,
13-
"ember-testing-lazy-routing": null
13+
"ember-testing-lazy-routing": null,
14+
"ember-handlebars-caps-lookup": null
1415
}

packages/ember-handlebars/lib/ext.js

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,31 @@ var handlebarsGet = Ember.Handlebars.get = function(root, path, options) {
6262
normalizedPath = normalizePath(root, path, data),
6363
value;
6464

65-
// In cases where the path begins with a keyword, change the
66-
// root to the value represented by that keyword, and ensure
67-
// the path is relative to it.
68-
root = normalizedPath.root;
69-
path = normalizedPath.path;
70-
71-
value = Ember.get(root, path);
72-
73-
// If the path starts with a capital letter, look it up on Ember.lookup,
74-
// which defaults to the `window` object in browsers.
75-
if (value === undefined && root !== Ember.lookup && Ember.isGlobalPath(path)) {
76-
value = Ember.get(Ember.lookup, path);
65+
if (Ember.FEATURES.isEnabled("ember-handlebars-caps-lookup")) {
66+
67+
// If the path starts with a capital letter, look it up on Ember.lookup,
68+
// which defaults to the `window` object in browsers.
69+
if (Ember.isGlobalPath(path)) {
70+
value = Ember.get(Ember.lookup, path);
71+
} else {
72+
73+
// In cases where the path begins with a keyword, change the
74+
// root to the value represented by that keyword, and ensure
75+
// the path is relative to it.
76+
value = Ember.get(normalizedPath.root, normalizedPath.path);
77+
}
78+
79+
} else {
80+
root = normalizedPath.root;
81+
path = normalizedPath.path;
82+
83+
value = Ember.get(root, path);
84+
85+
if (value === undefined && root !== Ember.lookup && Ember.isGlobalPath(path)) {
86+
value = Ember.get(Ember.lookup, path);
87+
}
7788
}
89+
7890
return value;
7991
};
8092

packages/ember-handlebars/tests/lookup_test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ test("ID parameters should be looked up on the context", function() {
2828
deepEqual(params, ["Mr", "Tom", "Dale"]);
2929
});
3030

31+
if (Ember.FEATURES.isEnabled("ember-handlebars-caps-lookup")) {
32+
test("ID parameters that start with capital letters use Ember.lookup as their context", function() {
33+
Ember.lookup.FOO = "BAR";
34+
35+
var context = { FOO: "BAZ" };
36+
37+
var params = Ember.Handlebars.resolveParams(context, ["FOO"], { types: ["ID"] });
38+
deepEqual(params, ["BAR"]);
39+
});
40+
}
41+
3142
test("ID parameters can look up keywords", function() {
3243
var controller = {
3344
salutation: "Mr"

0 commit comments

Comments
 (0)