Skip to content

Commit

Permalink
[FEATURE ember-handlebars-caps-lookup] Use Ember.lookup as context fo…
Browse files Browse the repository at this point in the history
…r {{CONSTANT}}. Fixes emberjs#3098
  • Loading branch information
Christian Wesselhoeft authored and wagenet committed Nov 9, 2013
1 parent a372b01 commit fc4df51
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

* 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
* 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`.
* Ensure Handlebars values starting with capital letters are always looked up on `Ember.lookup`.

### Ember 1.2.0 _(TBD)_

Expand Down
16 changes: 12 additions & 4 deletions FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ for a detailed explanation.

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
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
be entered for `loading`/`error` events emitted from
`ApplicationRoute`.

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

Added in [#3695](https://github.com/emberjs/ember.js/pull/3695).

* `ember-handlebars-caps-lookup`
Forces Handlebars values starting with capital letters, like `{{CONSTANT}}`,
to always be looked up on `Ember.lookup`. Previously, these values would be
looked up on the controller in certain cases.

Added in [#3218](https://github.com/emberjs/ember.js/pull/3218)

3 changes: 2 additions & 1 deletion features.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"string-humanize": null,
"propertyBraceExpansion": null,
"ember-routing-named-substates": null,
"ember-testing-lazy-routing": null
"ember-testing-lazy-routing": null,
"ember-handlebars-caps-lookup": null
}
36 changes: 24 additions & 12 deletions packages/ember-handlebars/lib/ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,31 @@ var handlebarsGet = Ember.Handlebars.get = function(root, path, options) {
normalizedPath = normalizePath(root, path, data),
value;

// In cases where the path begins with a keyword, change the
// root to the value represented by that keyword, and ensure
// the path is relative to it.
root = normalizedPath.root;
path = normalizedPath.path;

value = Ember.get(root, path);

// If the path starts with a capital letter, look it up on Ember.lookup,
// which defaults to the `window` object in browsers.
if (value === undefined && root !== Ember.lookup && Ember.isGlobalPath(path)) {
value = Ember.get(Ember.lookup, path);
if (Ember.FEATURES.isEnabled("ember-handlebars-caps-lookup")) {

// If the path starts with a capital letter, look it up on Ember.lookup,
// which defaults to the `window` object in browsers.
if (Ember.isGlobalPath(path)) {
value = Ember.get(Ember.lookup, path);
} else {

// In cases where the path begins with a keyword, change the
// root to the value represented by that keyword, and ensure
// the path is relative to it.
value = Ember.get(normalizedPath.root, normalizedPath.path);
}

} else {
root = normalizedPath.root;
path = normalizedPath.path;

value = Ember.get(root, path);

if (value === undefined && root !== Ember.lookup && Ember.isGlobalPath(path)) {
value = Ember.get(Ember.lookup, path);
}
}

return value;
};

Expand Down
11 changes: 11 additions & 0 deletions packages/ember-handlebars/tests/lookup_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ test("ID parameters should be looked up on the context", function() {
deepEqual(params, ["Mr", "Tom", "Dale"]);
});

if (Ember.FEATURES.isEnabled("ember-handlebars-caps-lookup")) {
test("ID parameters that start with capital letters use Ember.lookup as their context", function() {
Ember.lookup.FOO = "BAR";

var context = { FOO: "BAZ" };

var params = Ember.Handlebars.resolveParams(context, ["FOO"], { types: ["ID"] });
deepEqual(params, ["BAR"]);
});
}

test("ID parameters can look up keywords", function() {
var controller = {
salutation: "Mr"
Expand Down

0 comments on commit fc4df51

Please sign in to comment.