language stringclasses 1
value | owner stringlengths 2 15 | repo stringlengths 2 21 | sha stringlengths 45 45 | message stringlengths 7 36.3k | path stringlengths 1 199 | patch stringlengths 15 102k | is_multipart bool 2
classes |
|---|---|---|---|---|---|---|---|
Other | emberjs | ember.js | a4e4033d7ec4db777bac463efa9b7e3e6e7da53e.json | Change default template context to controller | packages/ember-handlebars/tests/handlebars_test.js | @@ -1954,6 +1954,7 @@ test("bindings should respect keywords", function() {
museumOpen: true,
controller: {
+ museumOpen: true,
museumDetails: Ember.Object.create({
name: "SFMoMA",
price: 20
@@ -1964,7 +1965,7 @@ test("bindings should respect keywords", function() {
template: Ember.Handlebars.compile('Name: {{view.name}} Price: ${{view.dollars}}')
}),
- template: Ember.Handlebars.compile('{{#if museumOpen}}{{view museumView nameBinding="controller.museumDetails.name" dollarsBinding="controller.museumDetails.price"}}{{/if}}')
+ template: Ember.Handlebars.compile('{{#if view.museumOpen}}{{view view.museumView nameBinding="controller.museumDetails.name" dollarsBinding="controller.museumDetails.price"}}{{/if}}')
});
Ember.run(function() { | true |
Other | emberjs | ember.js | a4e4033d7ec4db777bac463efa9b7e3e6e7da53e.json | Change default template context to controller | packages/ember-views/lib/views/view.js | @@ -557,13 +557,17 @@ Ember.View = Ember.Object.extend(Ember.Evented,
to be re-rendered.
*/
_templateContext: Ember.computed(function(key, value) {
- var parentView;
+ var parentView, controller;
if (arguments.length === 2) {
return value;
}
if (VIEW_PRESERVES_CONTEXT) {
+ if (controller = get(this, 'controller')) {
+ return controller;
+ }
+
parentView = get(this, '_parentView');
if (parentView) {
return get(parentView, '_templateContext'); | true |
Other | emberjs | ember.js | a4e4033d7ec4db777bac463efa9b7e3e6e7da53e.json | Change default template context to controller | packages/ember-views/tests/views/view/template_test.js | @@ -25,7 +25,7 @@ test("should call the function of the associated template", function() {
Ember.run(function(){
view.createElement();
});
-
+
ok(view.$('#twas-called').length, "the named template was called");
});
@@ -48,7 +48,7 @@ test("should call the function of the associated template with itself as the con
Ember.run(function(){
view.createElement();
});
-
+
equal("template was called for Tom DAAAALE", view.$('#twas-called').text(), "the named template was called with the view as the data source");
});
@@ -83,7 +83,7 @@ test("should not use defaultTemplate if template is provided", function() {
Ember.run(function(){
view.createElement();
});
-
+
equal("foo", view.$().text(), "default template was not printed");
});
@@ -103,7 +103,7 @@ test("should not use defaultTemplate if template is provided", function() {
Ember.run(function(){
view.createElement();
});
-
+
equal("foo", view.$().text(), "default template was not printed");
});
@@ -119,15 +119,26 @@ test("should render an empty element if no template is specified", function() {
});
test("should provide a controller to the template if a controller is specified on the view", function() {
- expect(5);
- var controller1 = Ember.Object.create(),
- controller2 = Ember.Object.create(),
+ expect(7);
+
+ var Controller1 = Ember.Object.extend({
+ toString: function() { return "Controller1"; }
+ });
+
+ var Controller2 = Ember.Object.extend({
+ toString: function() { return "Controller2"; }
+ });
+
+ var controller1 = Controller1.create(),
+ controller2 = Controller2.create(),
optionsDataKeywordsControllerForView,
- optionsDataKeywordsControllerForChildView;
-
+ optionsDataKeywordsControllerForChildView,
+ contextForView,
+ contextForControllerlessView;
+
var view = Ember.View.create({
controller: controller1,
-
+
template: function(buffer, options) {
optionsDataKeywordsControllerForView = options.data.keywords.controller;
}
@@ -136,59 +147,62 @@ test("should provide a controller to the template if a controller is specified o
Ember.run(function() {
view.appendTo('#qunit-fixture');
});
-
+
strictEqual(optionsDataKeywordsControllerForView, controller1, "passes the controller in the data");
-
+
Ember.run(function(){
view.destroy();
});
-
+
var parentView = Ember.View.create({
controller: controller1,
-
+
template: function(buffer, options) {
options.data.view.appendChild(Ember.View.create({
controller: controller2,
templateData: options.data,
- template: function(buffer, options) {
+ template: function(context, options) {
+ contextForView = context;
optionsDataKeywordsControllerForChildView = options.data.keywords.controller;
}
}));
optionsDataKeywordsControllerForView = options.data.keywords.controller;
}
});
-
+
Ember.run(function() {
parentView.appendTo('#qunit-fixture');
});
-
+
strictEqual(optionsDataKeywordsControllerForView, controller1, "passes the controller in the data");
strictEqual(optionsDataKeywordsControllerForChildView, controller2, "passes the child view's controller in the data");
-
+
Ember.run(function(){
parentView.destroy();
});
-
-
+
+
var parentViewWithControllerlessChild = Ember.View.create({
controller: controller1,
-
+
template: function(buffer, options) {
options.data.view.appendChild(Ember.View.create({
templateData: options.data,
- template: function(buffer, options) {
+ template: function(context, options) {
+ contextForControllerlessView = context;
optionsDataKeywordsControllerForChildView = options.data.keywords.controller;
}
}));
optionsDataKeywordsControllerForView = options.data.keywords.controller;
}
});
-
+
Ember.run(function() {
parentViewWithControllerlessChild.appendTo('#qunit-fixture');
});
-
-
+
strictEqual(optionsDataKeywordsControllerForView, controller1, "passes the original controller in the data");
strictEqual(optionsDataKeywordsControllerForChildView, controller1, "passes the controller in the data to child views");
+ strictEqual(contextForView, controller2, "passes the controller in as the main context of the parent view");
+ strictEqual(contextForControllerlessView, controller1, "passes the controller in as the main context of the child view");
}); | true |
Other | emberjs | ember.js | d86253456eedebe238a07da1914b9e11b867e835.json | Remove unused variable | packages/ember-views/lib/views/view.js | @@ -1768,7 +1768,7 @@ Ember.View = Ember.Object.extend(Ember.Evented,
@test in createChildViews
*/
createChildView: function(view, attrs) {
- var coreAttrs, templateData;
+ var coreAttrs;
if (Ember.View.detect(view)) {
coreAttrs = { _parentView: this, templateData: get(this, 'templateData') }; | false |
Other | emberjs | ember.js | 87245ceb5b9871c6d93a9461bbcc28e43e5ac7c4.json | QUnit test runner: Run all packages by default
The test `if (!packages.length)` didn't actually do anything before,
because split always returns at least ['']. But it's more convenient
anyway to just run everything by default, rather than displaying an
error message. This way people can open the test runner without
parameters and it Just Works.
Note on the diff: The if main clause is deleted, and the rest is just a
dedent. | tests/index.html | @@ -153,64 +153,59 @@ <h2 id="qunit-userAgent"></h2>
// Load Tests and Depenencies
- var packages = (QUnit.urlParams.package || "").split(","),
+ var packages = (QUnit.urlParams.package || "all").split(","),
packageName, el, idx, len, re, match, moduleName;
- if (!packages.length) {
- el = document.getElementById('qunit-header');
- el.innerHTML = 'Add package=package1,package2 in the URL to test packages';
- } else {
- if (packages[0] === 'all') {
- packages = [
- 'ember-handlebars',
- 'ember-metal',
- 'ember-runtime',
- 'ember-states',
- 'ember-views',
- 'ember-viewstates',
- 'ember-application'
- ];
- }
+ if (packages[0] === 'all') {
+ packages = [
+ 'ember-handlebars',
+ 'ember-metal',
+ 'ember-runtime',
+ 'ember-states',
+ 'ember-views',
+ 'ember-viewstates',
+ 'ember-application'
+ ];
+ }
+
+ len = packages.length;
+
+ // There is no require for this in the code
+ if (dist == 'spade') {
+ minispade.require('handlebars');
+ minispade.require('ember-debug');
+ }
- len = packages.length;
+ for (idx=0; idx<len; idx++) {
+ packageName = packages[idx];
+ re = new RegExp('^'+packageName+'/([^/]+)');
- // There is no require for this in the code
if (dist == 'spade') {
- minispade.require('handlebars');
- minispade.require('ember-debug');
+ minispade.require(packageName);
}
- for (idx=0; idx<len; idx++) {
- packageName = packages[idx];
- re = new RegExp('^'+packageName+'/([^/]+)');
+ for (moduleName in minispade.modules) {
+ if (!minispade.modules.hasOwnProperty(moduleName)) { continue; }
- if (dist == 'spade') {
- minispade.require(packageName);
- }
+ match = moduleName.match(re);
+ if (match) {
+ if (match[1] === '~tests') {
+ // Only require the actual tests since we already required the module
+ minispade.require(moduleName);
+ }
- for (moduleName in minispade.modules) {
- if (!minispade.modules.hasOwnProperty(moduleName)) { continue; }
-
- match = moduleName.match(re);
- if (match) {
- if (match[1] === '~tests') {
- // Only require the actual tests since we already required the module
- minispade.require(moduleName);
- }
-
- if (jsHint) {
- // JSHint all modules in this package, tests and code
- // (closure to preserve variable values)
- (function() {
- var jshintModule = moduleName;
- module(jshintModule);
- test('should pass jshint', function() {
- var passed = JSHINT(minispade.modules[jshintModule], JSHINTRC),
- errors = jsHintReporter(jshintModule, JSHINT.errors);
- ok(passed, jshintModule+" should pass jshint."+(errors ? "\n"+errors : ''));
- });
- })();
- }
+ if (jsHint) {
+ // JSHint all modules in this package, tests and code
+ // (closure to preserve variable values)
+ (function() {
+ var jshintModule = moduleName;
+ module(jshintModule);
+ test('should pass jshint', function() {
+ var passed = JSHINT(minispade.modules[jshintModule], JSHINTRC),
+ errors = jsHintReporter(jshintModule, JSHINT.errors);
+ ok(passed, jshintModule+" should pass jshint."+(errors ? "\n"+errors : ''));
+ });
+ })();
}
}
} | false |
Other | emberjs | ember.js | bbe1038a37ddf505d0f15d792a026fdeb66c39ae.json | Use @type instead of @property to make JsDoc happy | packages/ember-metal/lib/run_loop.js | @@ -272,7 +272,7 @@ Ember.run.end = function() {
simply adding the queue name to this array. Normally you should not need
to inspect or modify this property.
- @property {String}
+ @type Array
@default ['sync', 'actions', 'destroy', 'timers']
*/
Ember.run.queues = ['sync', 'actions', 'destroy', 'timers']; | true |
Other | emberjs | ember.js | bbe1038a37ddf505d0f15d792a026fdeb66c39ae.json | Use @type instead of @property to make JsDoc happy | packages/ember-metal/lib/utils.js | @@ -138,7 +138,7 @@ var META_KEY = Ember.GUID_KEY+'_meta';
The key used to store meta information on object for property observing.
@static
- @property
+ @type String
*/
Ember.META_KEY = META_KEY;
| true |
Other | emberjs | ember.js | bbe1038a37ddf505d0f15d792a026fdeb66c39ae.json | Use @type instead of @property to make JsDoc happy | packages/ember-runtime/lib/mixins/array.js | @@ -284,7 +284,7 @@ Ember.Array = Ember.Mixin.create(Ember.Enumerable, /** @scope Ember.Array.protot
Becomes true whenever the array currently has observers watching changes
on the array.
- @property {Boolean}
+ @type Boolean
*/
hasArrayObservers: Ember.computed(function() {
return Ember.hasListeners(this, '@array:change') || Ember.hasListeners(this, '@array:before'); | true |
Other | emberjs | ember.js | bbe1038a37ddf505d0f15d792a026fdeb66c39ae.json | Use @type instead of @property to make JsDoc happy | packages/ember-runtime/lib/mixins/enumerable.js | @@ -621,7 +621,7 @@ Ember.Enumerable = Ember.Mixin.create( /** @lends Ember.Enumerable */ {
For plain enumerables, this property is read only. Ember.Array overrides
this method.
- @property {Ember.Array}
+ @type Ember.Array
*/
'[]': Ember.computed(function(key, value) {
return this;
@@ -666,7 +666,7 @@ Ember.Enumerable = Ember.Mixin.create( /** @lends Ember.Enumerable */ {
Becomes true whenever the array currently has observers watching changes
on the array.
- @property {Boolean}
+ @type Boolean
*/
hasEnumerableObservers: Ember.computed(function() {
return Ember.hasListeners(this, '@enumerable:change') || Ember.hasListeners(this, '@enumerable:before'); | true |
Other | emberjs | ember.js | bbe1038a37ddf505d0f15d792a026fdeb66c39ae.json | Use @type instead of @property to make JsDoc happy | packages/ember-runtime/lib/mixins/freezable.js | @@ -74,7 +74,7 @@ Ember.Freezable = Ember.Mixin.create(
Set to true when the object is frozen. Use this property to detect whether
your object is frozen or not.
- @property {Boolean}
+ @type Boolean
*/
isFrozen: false,
| true |
Other | emberjs | ember.js | bbe1038a37ddf505d0f15d792a026fdeb66c39ae.json | Use @type instead of @property to make JsDoc happy | packages/ember-runtime/lib/system/array_proxy.js | @@ -52,7 +52,7 @@ Ember.ArrayProxy = Ember.Object.extend(Ember.MutableArray,
The content array. Must be an object that implements Ember.Array and/or
Ember.MutableArray.
- @property {Ember.Array}
+ @type Ember.Array
*/
content: null,
| true |
Other | emberjs | ember.js | bbe1038a37ddf505d0f15d792a026fdeb66c39ae.json | Use @type instead of @property to make JsDoc happy | packages/ember-runtime/lib/system/set.js | @@ -119,7 +119,7 @@ Ember.Set = Ember.CoreObject.extend(Ember.MutableEnumerable, Ember.Copyable, Emb
/**
This property will change as the number of objects in the set changes.
- @property Number
+ @type number
@default 0
*/
length: 0, | true |
Other | emberjs | ember.js | bbe1038a37ddf505d0f15d792a026fdeb66c39ae.json | Use @type instead of @property to make JsDoc happy | packages/ember-runtime/lib/system/string.js | @@ -17,7 +17,7 @@ var STRING_UNDERSCORE_REGEXP_2 = (/\-|\s+/g);
the `Ember.String.loc()` helper. To localize, add string values to this
hash.
- @property {String}
+ @type Hash
*/
Ember.STRINGS = {};
| true |
Other | emberjs | ember.js | bbe1038a37ddf505d0f15d792a026fdeb66c39ae.json | Use @type instead of @property to make JsDoc happy | packages/ember-runtime/tests/suites/copyable.js | @@ -35,7 +35,7 @@ Ember.CopyableTests = Ember.Suite.extend({
you say you can't test freezable it will verify that your objects really
aren't freezable.)
- @property {Boolean}
+ @type Boolean
*/
shouldBeFreezable: false
| true |
Other | emberjs | ember.js | bbe1038a37ddf505d0f15d792a026fdeb66c39ae.json | Use @type instead of @property to make JsDoc happy | packages/ember-runtime/tests/suites/enumerable.js | @@ -129,7 +129,7 @@ var EnumerableTests = Ember.Object.extend({
/**
Define a name for these tests - all modules are prefixed w/ it.
- @property {String}
+ @type String
*/
name: Ember.required(String),
@@ -193,7 +193,7 @@ var EnumerableTests = Ember.Object.extend({
Becomes true when you define a new mutate() method, indicating that
mutation tests should run. This is calculated automatically.
- @property {Boolean}
+ @type Boolean
*/
canTestMutation: Ember.computed(function() {
return this.mutate !== EnumerableTests.prototype.mutate; | true |
Other | emberjs | ember.js | bbe1038a37ddf505d0f15d792a026fdeb66c39ae.json | Use @type instead of @property to make JsDoc happy | packages/ember-runtime/tests/suites/suite.js | @@ -42,7 +42,7 @@ Ember.Suite = Ember.Object.extend(
/**
Define a name for these tests - all modules are prefixed w/ it.
- @property {String}
+ @type String
*/
name: Ember.required(String),
| true |
Other | emberjs | ember.js | bbe1038a37ddf505d0f15d792a026fdeb66c39ae.json | Use @type instead of @property to make JsDoc happy | packages/ember-states/lib/state.js | @@ -82,7 +82,7 @@ Ember.State = Ember.Object.extend(Ember.Evented, {
in the state hierarchy. This is false if the state has child
states; otherwise it is true.
- @property {Boolean}
+ @type Boolean
*/
isLeaf: Ember.computed(function() {
return !get(this, 'childStates').length; | true |
Other | emberjs | ember.js | bbe1038a37ddf505d0f15d792a026fdeb66c39ae.json | Use @type instead of @property to make JsDoc happy | packages/ember-states/lib/state_manager.js | @@ -389,7 +389,8 @@ Ember.StateManager = Ember.State.extend(
raised if you attempt to send an event to a state manager that is not
handled by the current state or any of its parent states.
- @property {Boolean}
+ @type Boolean
+ @default true
*/
errorOnUnhandledEvent: true,
| true |
Other | emberjs | ember.js | bbe1038a37ddf505d0f15d792a026fdeb66c39ae.json | Use @type instead of @property to make JsDoc happy | packages/ember-viewstates/lib/state_manager.js | @@ -8,7 +8,7 @@ Ember.StateManager.reopen(
this property will be the view associated with it. If there is no
view state active in this state manager, this value will be null.
- @property
+ @type Ember.View
*/
currentView: Ember.computed(function() {
var currentState = get(this, 'currentState'), | true |
Other | emberjs | ember.js | eaaa0927943dc2ecca30ae5415ab8b6ba653ad88.json | update String#objectAt documentation | packages/ember-runtime/lib/mixins/array.js | @@ -4,11 +4,8 @@
// License: Licensed under MIT license (see license.js)
// ==========================================================================
-
require('ember-runtime/mixins/enumerable');
-
-
// ..........................................................
// HELPERS
//
@@ -66,20 +63,29 @@ Ember.Array = Ember.Mixin.create(Ember.Enumerable, /** @scope Ember.Array.protot
/**
@field {Number} length
- Your array must support the length property. Your replace methods should
+ Your array must support the length property. Your replace methods should
set this property whenever it changes.
*/
length: Ember.required(),
/**
- This is one of the primitives you must implement to support Ember.Array.
- Returns the object at the named index. If your object supports retrieving
- the value of an array item using get() (i.e. myArray.get(0)), then you do
- not need to implement this method yourself.
+ Returns the object at the given index. If the given index is negative or
+ is greater or equal than the array length, returns `undefined`.
+
+ This is one of the primitives you must implement to support `Ember.Array`.
+ If your object supports retrieving the value of an array item using `get()`
+ (i.e. `myArray.get(0)`), then you do not need to implement this method
+ yourself.
+
+ var arr = ['a', 'b', 'c', 'd'];
+ arr.objectAt(0); => "a"
+ arr.objectAt(3); => "d"
+ arr.objectAt(-1); => undefined
+ arr.objectAt(4); => undefined
+ arr.objectAt(5); => undefined
@param {Number} idx
- The index of the item to return. If idx exceeds the current length,
- return null.
+ The index of the item to return.
*/
objectAt: function(idx) {
if ((idx < 0) || (idx>=get(this, 'length'))) return undefined ;
@@ -131,7 +137,7 @@ Ember.Array = Ember.Mixin.create(Ember.Enumerable, /** @scope Ember.Array.protot
// Add any extra methods to Ember.Array that are native to the built-in Array.
/**
- Returns a new array that is a slice of the receiver. This implementation
+ Returns a new array that is a slice of the receiver. This implementation
uses the observable array methods to retrieve the objects for the new
slice.
@@ -390,9 +396,4 @@ Ember.Array = Ember.Mixin.create(Ember.Enumerable, /** @scope Ember.Array.protot
return this.__each;
}).property().cacheable()
-
-
}) ;
-
-
- | false |
Other | emberjs | ember.js | df91fd23b505b2eda250e0d91697aef31c8faaa4.json | Add triageMustache as a known helper | packages/ember-handlebars/lib/ext.js | @@ -106,7 +106,8 @@ Ember.Handlebars.precompile = function(string) {
unbound: true,
bindAttr: true,
template: true,
- view: true
+ view: true,
+ _triageMustache: true
},
data: true,
stringParams: true | false |
Other | emberjs | ember.js | e880673950810a06c25b3cb9d763cc7513927285.json | Improve output for more common case
Since escaped is more common, don't generate
extra code for that case. | packages/ember-handlebars/lib/ext.js | @@ -82,9 +82,9 @@ Ember.Handlebars.Compiler.prototype.mustache = function(mustache) {
// Update the mustache node to include a hash value indicating whether the original node
// was escaped. This will allow us to properly escape values when the underlying value
// changes and we need to re-render the value.
- if(mustache.escaped) {
+ if(!mustache.escaped) {
mustache.hash = mustache.hash || new Handlebars.AST.HashNode([]);
- mustache.hash.pairs.push(["escaped", new Handlebars.AST.StringNode("true")]);
+ mustache.hash.pairs.push(["unescaped", new Handlebars.AST.StringNode("true")]);
}
mustache = new Handlebars.AST.MustacheNode([id].concat([mustache.id]), mustache.hash, !mustache.escaped);
return Handlebars.Compiler.prototype.mustache.call(this, mustache); | true |
Other | emberjs | ember.js | e880673950810a06c25b3cb9d763cc7513927285.json | Improve output for more common case
Since escaped is more common, don't generate
extra code for that case. | packages/ember-handlebars/lib/helpers/binding.js | @@ -44,7 +44,7 @@ var bind = function(property, options, preserveContext, shouldDisplay, valueNorm
path: path,
pathRoot: pathRoot,
previousContext: currentContext,
- isEscaped: options.hash.escaped,
+ isEscaped: !options.hash.unescaped,
templateData: options.data
});
| true |
Other | emberjs | ember.js | 9fce04129121884c522a887dc57fe0c6d5bbb2c2.json | Reduce need for runtime template compilation | packages/ember-handlebars/lib/controls/checkbox.js | @@ -81,16 +81,5 @@ Ember.Checkbox = Ember.View.extend({
_updateElementValue: function() {
var input = get(this, 'title') ? this.$('input:checkbox') : this.$();
set(this, 'checked', input.prop('checked'));
- },
-
- init: function() {
- if (get(this, 'title') || get(this, 'titleBinding')) {
- Ember.deprecate("Automatically surrounding Ember.Checkbox inputs with a label by providing a 'title' property is deprecated");
- this.tagName = undefined;
- this.attributeBindings = [];
- this.defaultTemplate = Ember.Handlebars.compile('<label><input type="checkbox" {{bindAttr checked="checked" disabled="disabled"}}>{{title}}</label>');
- }
-
- this._super();
}
}); | true |
Other | emberjs | ember.js | 9fce04129121884c522a887dc57fe0c6d5bbb2c2.json | Reduce need for runtime template compilation | packages/ember-handlebars/lib/controls/select.js | @@ -179,9 +179,13 @@ Ember.Select = Ember.View.extend(
Ember.SelectOption = Ember.View.extend({
tagName: 'option',
- defaultTemplate: Ember.Handlebars.compile("{{view.label}}"),
attributeBindings: ['value', 'selected'],
+ defaultTemplate: function(context, options) {
+ options = { data: options.data, hash: {} };
+ Ember.Handlebars.helpers.bind.call(context, "view.label", options);
+ },
+
init: function() {
this.labelPathDidChange();
this.valuePathDidChange(); | true |
Other | emberjs | ember.js | 9fce04129121884c522a887dc57fe0c6d5bbb2c2.json | Reduce need for runtime template compilation | packages/ember-handlebars/tests/controls/checkbox_test.js | @@ -96,19 +96,6 @@ test("checking the checkbox updates the value", function() {
equal(get(checkboxView, 'checked'), false, "changing the checkbox causes the view's value to get updated");
});
-// deprecated behaviors
-test("wraps the checkbox in a label if a title attribute is provided", function(){
- Ember.TESTING_DEPRECATION = true;
-
- try {
- checkboxView = Ember.Checkbox.create({ title: "I have a title" });
- append();
- equal(checkboxView.$('label').length, 1);
- } finally {
- Ember.TESTING_DEPRECATION = false;
- }
-});
-
test("proxies the checked attribute to value for backwards compatibility", function(){
Ember.TESTING_DEPRECATION = true;
| true |
Other | emberjs | ember.js | 7f1e74b95820d5698a1e9564e40bdbc394f89aca.json | Add known helpers to precompilation | packages/ember-handlebars/lib/ext.js | @@ -99,7 +99,19 @@ Ember.Handlebars.Compiler.prototype.mustache = function(mustache) {
*/
Ember.Handlebars.precompile = function(string) {
var ast = Handlebars.parse(string);
- var options = { data: true, stringParams: true };
+
+ var options = {
+ knownHelpers: {
+ action: true,
+ unbound: true,
+ bindAttr: true,
+ template: true,
+ view: true
+ },
+ data: true,
+ stringParams: true
+ };
+
var environment = new Ember.Handlebars.Compiler().compile(ast, options);
return new Ember.Handlebars.JavaScriptCompiler().compile(environment, options, undefined, true);
}; | false |
Other | emberjs | ember.js | 7349345dee477bba864854454c948b0ff6dccc30.json | Use Ember.Logger instead of console.log | packages/ember-views/lib/views/states.js | @@ -40,7 +40,7 @@ Ember.View.RenderStateManager = Ember.StateManager.extend({
// and we should still raise an exception in that
// case.
if (typeof action === 'function') {
- if (log) { console.log(fmt("STATEMANAGER: Sending event '%@' to state %@.", [event, get(currentState, 'path')])); }
+ if (log) { Ember.Logger.log(fmt("STATEMANAGER: Sending event '%@' to state %@.", [event, get(currentState, 'path')])); }
// remove event and currentState from the args
// and move `this` to the first argument position. | false |
Other | emberjs | ember.js | 2ec0dfa472b854932061b65ca347cc636a144ba7.json | Fix application tests | packages/ember-application/tests/system/application_test.js | @@ -131,15 +131,15 @@ test('initialized application go to initial route', function() {
onUpdateURL: function() {}
},
- start: Ember.State.extend({
+ root: Ember.State.extend({
index: Ember.State.extend({
route: '/'
})
})
});
});
- equal(app.getPath('stateManager.currentState.path'), 'start.index', "The router moved the state into the right place");
+ equal(app.getPath('stateManager.currentState.path'), 'root.index', "The router moved the state into the right place");
});
test("initialize application with non routable stateManager", function() {
@@ -165,7 +165,7 @@ test("initialize application with stateManager via initialize call", function()
app.Router = Ember.Router.extend({
location: 'hash',
- start: Ember.State.extend({
+ root: Ember.State.extend({
index: Ember.State.extend({
route: '/'
})
@@ -177,7 +177,7 @@ test("initialize application with stateManager via initialize call", function()
equal(app.getPath('stateManager') instanceof Ember.Router, true, "Router was set from initialize call");
equal(app.getPath('stateManager.location') instanceof Ember.HashLocation, true, "Location was set from location implementation name");
- equal(app.getPath('stateManager.currentState.path'), 'start.index', "The router moved the state into the right place");
+ equal(app.getPath('stateManager.currentState.path'), 'root.index', "The router moved the state into the right place");
});
test("initialize application with stateManager via initialize call from Router class", function() {
@@ -189,7 +189,7 @@ test("initialize application with stateManager via initialize call from Router c
app.Router = Ember.Router.extend({
location: 'hash',
- start: Ember.State.extend({
+ root: Ember.State.extend({
index: Ember.State.extend({
route: '/'
})
@@ -200,5 +200,5 @@ test("initialize application with stateManager via initialize call from Router c
});
equal(app.getPath('stateManager') instanceof Ember.Router, true, "Router was set from initialize call");
- equal(app.getPath('stateManager.currentState.path'), 'start.index', "The router moved the state into the right place");
+ equal(app.getPath('stateManager.currentState.path'), 'root.index', "The router moved the state into the right place");
}); | true |
Other | emberjs | ember.js | 2ec0dfa472b854932061b65ca347cc636a144ba7.json | Fix application tests | packages/ember-states/lib/routable.js | @@ -176,7 +176,9 @@ Ember.Routable = Ember.Mixin.create({
var object = state.deserialize(manager, match.hash) || {};
manager.transitionTo(get(state, 'path'), object);
manager.send('routePath', match.remaining);
- }
+ },
+
+ connectOutlets: Ember.K
});
Ember.State.reopen(Ember.Routable); | true |
Other | emberjs | ember.js | c01c19f023efa4279a4d9465c8aaa951e05a847b.json | Add urlFor to Router
Note: In general, you will not want to use
urlFor outside of the Router. Instead you will
either set the appropriate URL on a controller to
be used in a view, or use a feature we will write
next to allow a URL to be extracted from an event
that triggers a transition. | packages/ember-states/lib/routable.js | @@ -17,6 +17,13 @@ var paramForClass = function(classObject) {
return Ember.String.underscore(last) + "_id";
};
+var merge = function(original, hash) {
+ for (var prop in hash) {
+ if (!hash.hasOwnProperty(prop)) { continue; }
+ original[prop] = hash[prop];
+ }
+};
+
Ember.Routable = Ember.Mixin.create({
init: function() {
var redirection;
@@ -53,17 +60,19 @@ Ember.Routable = Ember.Mixin.create({
}
},
- absoluteRoute: function(manager) {
+ absoluteRoute: function(manager, hash) {
var parentState = get(this, 'parentState');
var path = '';
if (get(parentState, 'isRoutable')) {
- path = parentState.absoluteRoute(manager);
+ path = parentState.absoluteRoute(manager, hash);
}
var matcher = get(this, 'routeMatcher'),
- hash = get(manager, 'stateMeta').get(this);
+ meta = get(manager, 'stateMeta').get(this);
+ hash = hash || {};
+ merge(hash, meta);
var generated = matcher.generate(hash);
if (generated !== "") { | true |
Other | emberjs | ember.js | c01c19f023efa4279a4d9465c8aaa951e05a847b.json | Add urlFor to Router
Note: In general, you will not want to use
urlFor outside of the Router. Instead you will
either set the appropriate URL on a controller to
be used in a view, or use a feature we will write
next to allow a URL to be extracted from an event
that triggers a transition. | packages/ember-states/lib/state_manager.js | @@ -421,6 +421,35 @@ Ember.StateManager = Ember.State.extend(
}
},
+ /**
+ Finds a state by its state path.
+
+ Example:
+
+ manager = Ember.StateManager.create({
+ root: Ember.State.create({
+ dashboard: Ember.State.create()
+ })
+ });
+
+ manager.findStatesByPath(manager, "root.dashboard")
+
+ // returns the dashboard state
+
+ @param {Ember.State} root the state to start searching from
+ @param {String} path the state path to follow
+ @returns {Ember.State} the state at the end of the path
+ */
+ findStatesByPath: function(root, path) {
+ var parts = path.split('.'), state = root;
+
+ for (var i=0, l=parts.length; i<l; i++) {
+ state = get(get(state, 'states'), parts[i]);
+ }
+
+ return state;
+ },
+
findStatesByRoute: function(state, route) {
if (!route || route === "") { return undefined; }
var r = route.split('.'), ret = [];
@@ -451,6 +480,11 @@ Ember.StateManager = Ember.State.extend(
}).join(".");
},
+ urlFor: function(path, hash) {
+ var state = this.findStatesByPath(this, path);
+ return state.absoluteRoute(this, hash);
+ },
+
transitionTo: function(name, context) {
// 1. Normalize arguments
// 2. Ensure that we are in the correct state | true |
Other | emberjs | ember.js | c01c19f023efa4279a4d9465c8aaa951e05a847b.json | Add urlFor to Router
Note: In general, you will not want to use
urlFor outside of the Router. Instead you will
either set the appropriate URL on a controller to
be used in a view, or use a feature we will write
next to allow a URL to be extracted from an event
that triggers a transition. | packages/ember-states/tests/routable_test.js | @@ -453,3 +453,115 @@ test("you cannot have a redirectsTo in a non-leaf state", function () {
});
});
});
+
+module("urlFor", {
+
+});
+
+test("urlFor returns an absolute route", function() {
+ var router = Ember.Router.create({
+ root: Ember.State.create({
+ dashboard: Ember.State.create({
+ route: '/dashboard'
+ })
+ })
+ });
+
+ var url = router.urlFor('root.dashboard');
+ equal(url, "/dashboard");
+});
+
+test("urlFor supports dynamic segments", function() {
+ var router = Ember.Router.create({
+ root: Ember.State.create({
+ dashboard: Ember.State.create({
+ route: '/dashboard',
+
+ posts: Ember.State.create({
+ route: '/posts/:post_id'
+ })
+ })
+ })
+ });
+
+ var url = router.urlFor('root.dashboard.posts', { post_id: 1 });
+ equal(url, "/dashboard/posts/1");
+});
+
+test("urlFor supports using the current information for dynamic segments", function() {
+ var router = Ember.Router.create({
+ namespace: {
+ Post: {
+ toString: function() { return "Post"; },
+ find: function() { return { id: 1 }; }
+ }
+ },
+
+ root: Ember.State.create({
+ dashboard: Ember.State.create({
+ route: '/dashboard',
+
+ posts: Ember.State.create({
+ route: '/posts/:post_id',
+
+ index: Ember.State.create({
+ route: '/'
+ }),
+
+ manage: Ember.State.create({
+ route: '/manage'
+ })
+ })
+ })
+ })
+ });
+
+ Ember.run(function() {
+ router.route('/dashboard/posts/1');
+ });
+
+ var url = router.urlFor('root.dashboard.posts.manage');
+ equal(url, '/dashboard/posts/1/manage');
+});
+
+test("urlFor supports merging the current information for dynamic segments", function() {
+ var router = Ember.Router.create({
+ namespace: {
+ Post: {
+ toString: function() { return "Post"; },
+ find: function() { return { id: 1 }; }
+ },
+
+ Widget: {
+ toString: function() { return "Widget"; },
+ find: function() { return { id: 2 }; }
+ }
+ },
+
+ root: Ember.State.create({
+ dashboard: Ember.State.create({
+ route: '/dashboard',
+
+ posts: Ember.State.create({
+ route: '/posts/:post_id',
+
+ index: Ember.State.create({
+ route: '/'
+ }),
+
+ manage: Ember.State.create({
+ route: '/manage/:widget_id'
+ })
+ })
+ })
+ })
+ });
+
+ Ember.run(function() {
+ router.route('/dashboard/posts/1');
+ });
+
+ var url = router.urlFor('root.dashboard.posts.manage', { widget_id: 2 });
+ equal(url, '/dashboard/posts/1/manage/2');
+});
+ | true |
Other | emberjs | ember.js | ee1d2d55bb66cc8bb82c8ca1e535995c37221a53.json | make transitionEvent on state manager configurable | packages/ember-states/lib/router.js | @@ -21,8 +21,16 @@ require('ember-states/routable');
*/
Ember.Router = Ember.StateManager.extend(
/** @scope Ember.Router.prototype */ {
+
initialState: 'root',
+ /**
+ On router, transitionEvent should be called connectOutlets
+
+ @property {String}
+ */
+ transitionEvent: 'connectOutlets',
+
route: function(path) {
if (path.charAt(0) === '/') {
path = path.substr(1); | true |
Other | emberjs | ember.js | ee1d2d55bb66cc8bb82c8ca1e535995c37221a53.json | make transitionEvent on state manager configurable | packages/ember-states/lib/state.js | @@ -88,7 +88,7 @@ Ember.State = Ember.Object.extend(Ember.Evented, {
return !get(this, 'childStates').length;
}).cacheable(),
- connectOutlets: Ember.K,
+ setup: Ember.K,
enter: Ember.K,
exit: Ember.K
}); | true |
Other | emberjs | ember.js | ee1d2d55bb66cc8bb82c8ca1e535995c37221a53.json | make transitionEvent on state manager configurable | packages/ember-states/lib/state_manager.js | @@ -377,6 +377,13 @@ Ember.StateManager = Ember.State.extend(
currentState: null,
+ /**
+ The name of transitionEvent that this stateManager will dispatch
+
+ @property {String}
+ */
+ transitionEvent: 'setup',
+
/**
If set to true, `errorOnUnhandledEvents` will cause an exception to be
raised if you attempt to send an event to a state manager that is not
@@ -448,7 +455,7 @@ Ember.StateManager = Ember.State.extend(
// 1. Normalize arguments
// 2. Ensure that we are in the correct state
// 3. Map provided path to context objects and send
- // appropriate connectOutlets events
+ // appropriate transitionEvent events
if (Ember.empty(name)) { return; }
@@ -527,7 +534,7 @@ Ember.StateManager = Ember.State.extend(
state = this.findStatesByRoute(state, path);
state = state[state.length-1];
- state.fire('connectOutlets', this, context);
+ state.fire(get(this, 'transitionEvent'), this, context);
}, this);
},
| true |
Other | emberjs | ember.js | ee1d2d55bb66cc8bb82c8ca1e535995c37221a53.json | make transitionEvent on state manager configurable | packages/ember-states/tests/state_manager_test.js | @@ -456,7 +456,7 @@ test("goToState with current state does not trigger enter or exit", function() {
module("Transition contexts");
-test("if a context is passed to a transition, the state's connectOutlets event is triggered after the transition has completed", function() {
+test("if a context is passed to a transition, the state's setup event is triggered after the transition has completed", function() {
expect(1);
var context = {};
@@ -469,7 +469,7 @@ test("if a context is passed to a transition, the state's connectOutlets event i
}),
next: Ember.State.create({
- connectOutlets: function(manager, passedContext) {
+ setup: function(manager, passedContext) {
equal(context, passedContext, "The context is passed through");
}
})
@@ -479,7 +479,7 @@ test("if a context is passed to a transition, the state's connectOutlets event i
stateManager.send('goNext', context);
});
-test("if a context is passed to a transition and the path is to the current state, the state's connectOutlets event is triggered again", function() {
+test("if a context is passed to a transition and the path is to the current state, the state's setup event is triggered again", function() {
expect(2);
var counter = 0;
@@ -499,7 +499,7 @@ test("if a context is passed to a transition and the path is to the current stat
manager.goToState('next', counter);
},
- connectOutlets: function(manager, context) {
+ setup: function(manager, context) {
equal(context, counter, "The context is passed through");
}
})
@@ -511,7 +511,7 @@ test("if a context is passed to a transition and the path is to the current stat
stateManager.send('goNext', counter);
});
-test("if no context is provided, connectOutlets is triggered with an undefined context", function() {
+test("if no context is provided, setup is triggered with an undefined context", function() {
expect(2);
Ember.run(function() {
@@ -528,8 +528,8 @@ test("if no context is provided, connectOutlets is triggered with an undefined c
manager.transitionTo('next');
},
- connectOutlets: function(manager, context) {
- equal(context, undefined, "connectOutlets is called with no context");
+ setup: function(manager, context) {
+ equal(context, undefined, "setup is called with no context");
}
})
})
@@ -552,12 +552,12 @@ test("multiple contexts can be provided in a single transitionTo", function() {
}),
planters: Ember.State.create({
- connectOutlets: function(manager, context) {
+ setup: function(manager, context) {
deepEqual(context, { company: true });
},
nuts: Ember.State.create({
- connectOutlets: function(manager, context) {
+ setup: function(manager, context) {
deepEqual(context, { product: true });
}
}) | true |
Other | emberjs | ember.js | 91a8975b8d3a0b873b421f1dbc4ea41f92c92bc2.json | Add redirectsTo in routes | packages/ember-states/lib/routable.js | @@ -19,9 +19,20 @@ var paramForClass = function(classObject) {
Ember.Routable = Ember.Mixin.create({
init: function() {
+ var redirection;
this.on('connectOutlets', this, this.stashContext);
+ if (redirection = get(this, 'redirectsTo')) {
+ Ember.assert("You cannot use `redirectsTo` if you already have a `connectOutlets` method", this.connectOutlets === Ember.K);
+
+ this.connectOutlets = function(router) {
+ router.transitionTo(redirection);
+ };
+ }
+
this._super();
+
+ Ember.assert("You cannot use `redirectsTo` on a state that has child states", !redirection || (!!redirection && !!get(this, 'isLeaf')));
},
stashContext: function(manager, context) { | true |
Other | emberjs | ember.js | 91a8975b8d3a0b873b421f1dbc4ea41f92c92bc2.json | Add redirectsTo in routes | packages/ember-states/tests/routable_test.js | @@ -405,3 +405,56 @@ test("should use a specified String `modelType` in the default `deserialize`", f
router.route("/posts/1");
});
+
+module("redirectsTo");
+
+test("if a leaf state has a redirectsTo, it automatically transitions into that state", function() {
+ var router = Ember.Router.create({
+ initialState: 'root',
+ root: Ember.State.create({
+
+ index: Ember.State.create({
+ route: '/',
+ redirectsTo: 'someOtherState'
+ }),
+
+ someOtherState: Ember.State.create({
+ route: '/other'
+ })
+ })
+ });
+
+ Ember.run(function() {
+ router.route("/");
+ });
+
+ equal(router.getPath('currentState.path'), "root.someOtherState");
+});
+
+test("you cannot define connectOutlets AND redirectsTo", function() {
+ raises(function() {
+ Ember.Router.create({
+ initialState: 'root',
+ root: Ember.State.create({
+ index: Ember.State.create({
+ route: '/',
+ redirectsTo: 'someOtherState',
+ connectOutlets: function() {}
+ })
+ })
+ });
+ });
+});
+
+test("you cannot have a redirectsTo in a non-leaf state", function () {
+ raises(function() {
+ Ember.Router.create({
+ initialState: 'root',
+ root: Ember.State.create({
+ redirectsTo: 'someOtherState',
+
+ index: Ember.State.create()
+ })
+ });
+ });
+}); | true |
Other | emberjs | ember.js | 3fa1ed671ceb774a956fc1bd9ba2a8c5611c073a.json | Add documentation stub for Ember.Router | packages/ember-states/lib/router.js | @@ -2,7 +2,25 @@ require('ember-states/state');
require('ember-states/route_matcher');
require('ember-states/routable');
-Ember.Router = Ember.StateManager.extend({
+/**
+ @class
+
+ `Ember.Router` is a state manager used for routing.
+
+ A special `Router` property name is recognized on applications:
+
+ var app = Ember.Application.create({
+ Router: Ember.Router.extend(...)
+ });
+ app.initialize();
+
+ Here, `app.initialize` will instantiate the `app.Router` and assign the
+ instance to the `app.stateManager` property.
+
+ @extends Ember.StateManager
+*/
+Ember.Router = Ember.StateManager.extend(
+/** @scope Ember.Router.prototype */ {
route: function(path) {
if (path.charAt(0) === '/') {
path = path.substr(1); | false |
Other | emberjs | ember.js | 1bff946579a832526349ac3f70ce032c6eb95d2c.json | Add TODO note about Ember.Location documentation | packages/ember-application/lib/system/location.js | @@ -10,6 +10,9 @@ var get = Ember.get, set = Ember.set;
onUpdateURL(callback): triggers the callback when the URL changes
Calling setURL will not trigger onUpdateURL callbacks.
+
+ TODO: This, as well as the Ember.Location documentation below, should
+ perhaps be moved so that it's visible in the JsDoc output.
*/
/** | false |
Other | emberjs | ember.js | bc75b1ac96b5c675aa27397250c5c02b1e0e46a7.json | Add @scope so properties are picked up by JsDoc | packages/ember-viewstates/lib/view_state.js | @@ -243,7 +243,8 @@ var get = Ember.get, set = Ember.set;
`view` that references the `Ember.View` object that was interacted with.
**/
-Ember.ViewState = Ember.State.extend({
+Ember.ViewState = Ember.State.extend(
+/** @scope Ember.ViewState.prototype */ {
isViewState: true,
enter: function(stateManager) { | false |
Other | emberjs | ember.js | 483c4555bf41042cfd3e1ab513823d80788f5a47.json | add missing require | packages/ember-runtime/lib/controllers.js | @@ -1 +1,2 @@
require('ember-runtime/controllers/array_controller');
+require('ember-runtime/controllers/object_controller'); | false |
Other | emberjs | ember.js | 7830f434af827923e1c3cdeee4103f5535047183.json | Fix doc api | packages/ember-runtime/lib/system/array_proxy.js | @@ -22,7 +22,7 @@ var get = Ember.get, set = Ember.set;
A simple example of usage:
var pets = ['dog', 'cat', 'fish'];
- var arrayProxy = Ember.ArrayProxy.create({ content: Ember.A(pets) });
+ var ap = Ember.ArrayProxy.create({ content: Ember.A(pets) });
ap.get('firstObject'); // => 'dog'
ap.set('content', ['amoeba', 'paramecium']);
ap.get('firstObject'); // => 'amoeba' | false |
Other | emberjs | ember.js | 4fba5a1e6c8016c74649224280318d43074d8983.json | Fix parentView and nearestChildOf documentation
If the parentView documentation comes before _parentView, it won't show
up in JsDoc. | packages/ember-views/lib/views/view.js | @@ -590,8 +590,6 @@ Ember.View = Ember.Object.extend(Ember.Evented,
@type Ember.View
@default null
*/
- _parentView: null,
-
parentView: Ember.computed(function() {
var parent = get(this, '_parentView');
@@ -602,6 +600,8 @@ Ember.View = Ember.Object.extend(Ember.Evented,
}
}).property('_parentView').volatile(),
+ _parentView: null,
+
// return the current view, not including virtual views
concreteView: Ember.computed(function() {
if (!this.isVirtual) { return this; }
@@ -682,8 +682,8 @@ Ember.View = Ember.Object.extend(Ember.Evented,
},
/**
- Return the nearest ancestor that is a direct child of a
- view of.
+ Return the nearest ancestor whose parent is an instance of
+ `klass`.
@param {Class} klass Subclass of Ember.View (or Ember.View itself)
@returns Ember.View | false |
Other | emberjs | ember.js | d1848b4f26766701693fcfd1a1e1e85341d53e97.json | Fix doc api | packages/ember-runtime/lib/system/array_proxy.js | @@ -22,7 +22,7 @@ var get = Ember.get, set = Ember.set;
A simple example of usage:
var pets = ['dog', 'cat', 'fish'];
- var arrayProxy = Ember.ArrayProxy.create({ content: Ember.A(pets) });
+ var ap = Ember.ArrayProxy.create({ content: Ember.A(pets) });
ap.get('firstObject'); // => 'dog'
ap.set('content', ['amoeba', 'paramecium']);
ap.get('firstObject'); // => 'amoeba' | false |
Other | emberjs | ember.js | 1a60eccb6ca96f4503a48bb502bfa16af74d8205.json | Fix parentView and nearestChildOf documentation
If the parentView documentation comes before _parentView, it won't show
up in JsDoc. | packages/ember-views/lib/views/view.js | @@ -590,8 +590,6 @@ Ember.View = Ember.Object.extend(Ember.Evented,
@type Ember.View
@default null
*/
- _parentView: null,
-
parentView: Ember.computed(function() {
var parent = get(this, '_parentView');
@@ -602,6 +600,8 @@ Ember.View = Ember.Object.extend(Ember.Evented,
}
}).property('_parentView').volatile(),
+ _parentView: null,
+
// return the current view, not including virtual views
concreteView: Ember.computed(function() {
if (!this.isVirtual) { return this; }
@@ -682,8 +682,8 @@ Ember.View = Ember.Object.extend(Ember.Evented,
},
/**
- Return the nearest ancestor that is a direct child of a
- view of.
+ Return the nearest ancestor whose parent is an instance of
+ `klass`.
@param {Class} klass Subclass of Ember.View (or Ember.View itself)
@returns Ember.View | false |
Other | emberjs | ember.js | 640f00cacabddcbc6881ed4770fa500534ecbf70.json | Fix initialization with non routable stateManager | packages/ember-application/lib/system/application.js | @@ -125,7 +125,7 @@ Ember.Application = Ember.Namespace.extend(
this.ready();
- if (stateManager) {
+ if (stateManager && stateManager instanceof Ember.Router) {
this.setupStateManager(stateManager);
}
}, | true |
Other | emberjs | ember.js | 640f00cacabddcbc6881ed4770fa500534ecbf70.json | Fix initialization with non routable stateManager | packages/ember-application/tests/system/application_test.js | @@ -116,17 +116,19 @@ test("initialize controllers into a state manager", function() {
equal(getPath(stateManager, 'barController.target'), stateManager, "the state manager is assigned");
});
-module("Ember.Application initial route", function() {
+test('initialized application go to initial route', function() {
Ember.run(function() {
app = Ember.Application.create({
rootElement: '#qunit-fixture'
});
- app.stateManager = Ember.StateManager.create({
+ app.stateManager = Ember.Router.create({
location: {
getURL: function() {
return '/';
- }
+ },
+ setURL: function() {},
+ onUpdateURL: function() {}
},
start: Ember.State.extend({
@@ -139,3 +141,17 @@ module("Ember.Application initial route", function() {
equal(app.getPath('stateManager.currentState.path'), 'start.index', "The router moved the state into the right place");
});
+
+test("initialize application with non routable stateManager", function() {
+ Ember.run(function() {
+ app = Ember.Application.create({
+ rootElement: '#qunit-fixture'
+ });
+
+ app.stateManager = Ember.StateManager.create({
+ start: Ember.State.extend()
+ });
+ });
+
+ equal(app.getPath('stateManager.currentState.path'), 'start', "Application sucessfuly started");
+}); | true |
Other | emberjs | ember.js | 2d876a6d1b4309a004246d7ec616a5faf93cfb05.json | Fix initialization with non routable stateManager | packages/ember-application/lib/system/application.js | @@ -125,7 +125,7 @@ Ember.Application = Ember.Namespace.extend(
this.ready();
- if (stateManager) {
+ if (stateManager && stateManager instanceof Ember.Router) {
this.setupStateManager(stateManager);
}
}, | true |
Other | emberjs | ember.js | 2d876a6d1b4309a004246d7ec616a5faf93cfb05.json | Fix initialization with non routable stateManager | packages/ember-application/tests/system/application_test.js | @@ -116,17 +116,19 @@ test("initialize controllers into a state manager", function() {
equal(getPath(stateManager, 'barController.target'), stateManager, "the state manager is assigned");
});
-module("Ember.Application initial route", function() {
+test('initialized application go to initial route', function() {
Ember.run(function() {
app = Ember.Application.create({
rootElement: '#qunit-fixture'
});
- app.stateManager = Ember.StateManager.create({
+ app.stateManager = Ember.Router.create({
location: {
getURL: function() {
return '/';
- }
+ },
+ setURL: function() {},
+ onUpdateURL: function() {}
},
start: Ember.State.extend({
@@ -139,3 +141,17 @@ module("Ember.Application initial route", function() {
equal(app.getPath('stateManager.currentState.path'), 'start.index', "The router moved the state into the right place");
});
+
+test("initialize application with non routable stateManager", function() {
+ Ember.run(function() {
+ app = Ember.Application.create({
+ rootElement: '#qunit-fixture'
+ });
+
+ app.stateManager = Ember.StateManager.create({
+ start: Ember.State.extend()
+ });
+ });
+
+ equal(app.getPath('stateManager.currentState.path'), 'start', "Application sucessfuly started");
+}); | true |
Other | emberjs | ember.js | 1f540aed8ef00684ea170d5f4576c014bfbd4ad5.json | Upload starter-kit to the correct location | Rakefile | @@ -10,19 +10,23 @@ def pipeline
Rake::Pipeline::Project.new("Assetfile")
end
-def setup_uploader
+def setup_uploader(root=Dir.pwd)
require './lib/github_uploader'
- # get the github user name
- login = `git config github.user`.chomp
+ login = origin = nil
- # get repo from git config's origin url
- origin = `git config remote.origin.url`.chomp # url to origin
- # extract USERNAME/REPO_NAME
- # sample urls: https://github.com/emberjs/ember.js.git
- # git://github.com/emberjs/ember.js.git
- # git@github.com:emberjs/ember.js.git
- # git@github.com:emberjs/ember.js
+ Dir.chdir(root) do
+ # get the github user name
+ login = `git config github.user`.chomp
+
+ # get repo from git config's origin url
+ origin = `git config remote.origin.url`.chomp # url to origin
+ # extract USERNAME/REPO_NAME
+ # sample urls: https://github.com/emberjs/ember.js.git
+ # git://github.com/emberjs/ember.js.git
+ # git@github.com:emberjs/ember.js.git
+ # git@github.com:emberjs/ember.js
+ end
repoUrl = origin.match(/github\.com[\/:]((.+?)\/(.+?))(\.git)?$/)
username = repoUrl[2] # username part of origin url
@@ -351,7 +355,7 @@ namespace :release do
desc "Upload release"
task :upload do
- uploader = setup_uploader
+ uploader = setup_uploader("tmp/starter-kit")
# Upload minified first, so non-minified shows up on top
upload_file(uploader, "starter-kit.#{EMBER_VERSION}.zip", "Ember.js #{EMBER_VERSION} Starter Kit", "dist/starter-kit.#{EMBER_VERSION}.zip") | false |
Other | emberjs | ember.js | e432e7cf585a07166f7a8ff769a80194c72b801c.json | Run tests for when running all | tests/index.html | @@ -141,7 +141,8 @@ <h2 id="qunit-userAgent"></h2>
'ember-runtime',
'ember-states',
'ember-views',
- 'ember-viewstates'
+ 'ember-viewstates',
+ 'ember-application'
];
}
| false |
Other | emberjs | ember.js | 5a4917b9aaee4f53c8196f9b3349ff775774dae2.json | Add Ember.Controller and `connectOutlet`
The goal of `connectOutlet` is to make it easy to
fill in a Handlebars-specified outlet with a new
view.
It also connects the view's associated controller
to the view's `controller` property, if an
associated controller can be found using
conventional naming. | packages/ember-application/lib/system/application.js | @@ -179,12 +179,14 @@ Ember.Application.reopenClass({
}
});
-Ember.Application.registerInjection(function(app, stateManager, property) {
+Ember.Application.registerInjection(function(app, router, property) {
if (!/^[A-Z].*Controller$/.test(property)) { return; }
var name = property[0].toLowerCase() + property.substr(1),
controller = app[property].create();
- stateManager.set(name, controller);
- controller.set('target', stateManager);
+ router.set(name, controller);
+
+ controller.set('target', router);
+ controller.set('controllers', router);
}); | true |
Other | emberjs | ember.js | 5a4917b9aaee4f53c8196f9b3349ff775774dae2.json | Add Ember.Controller and `connectOutlet`
The goal of `connectOutlet` is to make it easy to
fill in a Handlebars-specified outlet with a new
view.
It also connects the view's associated controller
to the view's `controller` property, if an
associated controller can be found using
conventional naming. | packages/ember-metal/lib/mixin.js | @@ -358,6 +358,8 @@ Mixin.prototype.reopen = function() {
mixin.properties = this.properties;
delete this.properties;
this.mixins = [mixin];
+ } else if (!this.mixins) {
+ this.mixins = [];
}
var len = arguments.length, mixins = this.mixins, idx; | true |
Other | emberjs | ember.js | 5a4917b9aaee4f53c8196f9b3349ff775774dae2.json | Add Ember.Controller and `connectOutlet`
The goal of `connectOutlet` is to make it easy to
fill in a Handlebars-specified outlet with a new
view.
It also connects the view's associated controller
to the view's `controller` property, if an
associated controller can be found using
conventional naming. | packages/ember-runtime/lib/controllers.js | @@ -1 +1,2 @@
require('ember-runtime/controllers/array_controller');
+require('ember-runtime/controllers/controller'); | true |
Other | emberjs | ember.js | 5a4917b9aaee4f53c8196f9b3349ff775774dae2.json | Add Ember.Controller and `connectOutlet`
The goal of `connectOutlet` is to make it easy to
fill in a Handlebars-specified outlet with a new
view.
It also connects the view's associated controller
to the view's `controller` property, if an
associated controller can be found using
conventional naming. | packages/ember-runtime/lib/controllers/array_controller.js | @@ -5,6 +5,7 @@
// ==========================================================================
require('ember-runtime/system/array_proxy');
+require('ember-runtime/controllers/controller');
/**
@class
@@ -45,4 +46,4 @@ require('ember-runtime/system/array_proxy');
@extends Ember.ArrayProxy
*/
-Ember.ArrayController = Ember.ArrayProxy.extend();
+Ember.ArrayController = Ember.ArrayProxy.extend(Ember.ControllerMixin); | true |
Other | emberjs | ember.js | 5a4917b9aaee4f53c8196f9b3349ff775774dae2.json | Add Ember.Controller and `connectOutlet`
The goal of `connectOutlet` is to make it easy to
fill in a Handlebars-specified outlet with a new
view.
It also connects the view's associated controller
to the view's `controller` property, if an
associated controller can be found using
conventional naming. | packages/ember-runtime/lib/controllers/controller.js | @@ -0,0 +1,6 @@
+require('ember-runtime/system/object');
+require('ember-runtime/system/string');
+
+Ember.ControllerMixin = Ember.Mixin.create();
+
+Ember.Controller = Ember.Object.extend(Ember.ControllerMixin); | true |
Other | emberjs | ember.js | 5a4917b9aaee4f53c8196f9b3349ff775774dae2.json | Add Ember.Controller and `connectOutlet`
The goal of `connectOutlet` is to make it easy to
fill in a Handlebars-specified outlet with a new
view.
It also connects the view's associated controller
to the view's `controller` property, if an
associated controller can be found using
conventional naming. | packages/ember-views/lib/system.js | @@ -8,3 +8,4 @@
require("ember-views/system/render_buffer");
require("ember-views/system/event_dispatcher");
require("ember-views/system/ext");
+require("ember-views/system/controller"); | true |
Other | emberjs | ember.js | 5a4917b9aaee4f53c8196f9b3349ff775774dae2.json | Add Ember.Controller and `connectOutlet`
The goal of `connectOutlet` is to make it easy to
fill in a Handlebars-specified outlet with a new
view.
It also connects the view's associated controller
to the view's `controller` property, if an
associated controller can be found using
conventional naming. | packages/ember-views/lib/system/controller.js | @@ -0,0 +1,106 @@
+var get = Ember.get, set = Ember.set;
+
+Ember.ControllerMixin.reopen({
+ /**
+ `connectOutlet` creates a new instance of a provided view
+ class, wires it up to its associated controller, and
+ assigns the new view to a property on the current controller.
+
+ The purpose of this method is to enable views that use
+ outlets to quickly assign new views for a given outlet.
+
+ For example, an application view's template may look like
+ this:
+
+ <h1>My Blog</h1>
+ {{outlet}}
+
+ The view for this outlet is specified by assigning a
+ `view` property to the application's controller. The
+ following code will assign a new `App.PostsView` to
+ that outlet:
+
+ applicationController.connectOutlet(App.PostsView);
+
+ You can specify a particular outlet to use as the first
+ parameter to `connectOutlet`. For example, if your
+ main template looks like:
+
+ <h1>My Blog</h1>
+ {{outlet master}}
+ {{outlet detail}}
+
+ You can assign an `App.PostsView` to the master outlet:
+
+ applicationController.connectOutlet('master', App.PostsView);
+
+ In general, you will also want to assign a controller
+ to the newly created view. By convention, a controller
+ named `postsController` will be assigned as the view's
+ controller.
+
+ In an application initialized using `app.initialize(router)`,
+ `connectOutlet` will look for `postsController` on the
+ router. The initialization process will automatically
+ create an instance of `App.PostsController` called
+ `postsController`, so you don't need to do anything
+ beyond `connectOutlet` to assign your view and wire it
+ up to its associated controller.
+
+ You can supply a `content` for the controller by supplying
+ a final argument after the view class:
+
+ application.createOutlet(App.PostsView, App.Post.find());
+
+ The only required argument is `viewClass`. You can optionally
+ specify an `outletName` before `viewClass` and/or a `context`
+ after `viewClass` in any combination.
+
+ @param {String} outletName the name of the outlet to assign
+ the newly created view to (optional)
+ @param {Class} viewClass a view class to instantiate
+ @param {Object} context a context object to assign to the
+ controller's `content` property, if a controller can be
+ found.
+ */
+ connectOutlet: function(outletName, viewClass, context) {
+ // Normalize arguments. Supported arguments:
+ //
+ // viewClass
+ // outletName, viewClass
+ // viewClass, context
+ // outletName, viewClass, context
+ if (arguments.length === 2) {
+ if (Ember.Object.detect(outletName)) {
+ context = viewClass;
+ viewClass = outletName;
+ outletName = 'view';
+ }
+ } else if (arguments.length === 1) {
+ viewClass = outletName;
+ outletName = 'view';
+ }
+
+ var parts = viewClass.toString().split("."),
+ last = parts[parts.length - 1],
+ match = last.match(/^(.*)View$/);
+
+ Ember.assert("The parameter you pass to connectOutlet must be a class ending with View", !!match);
+
+ var bareName = match[1], controllerName;
+ bareName = bareName.charAt(0).toLowerCase() + bareName.substr(1);
+
+ controllerName = bareName + "Controller";
+
+ var controller = get(get(this, 'controllers'), controllerName);
+
+ Ember.assert("You specified a context, but no " + controllerName + " was found", !context || !!controller);
+ if (context) { controller.set('content', context); }
+
+ var view = viewClass.create({ controller: controller });
+ set(this, outletName, view);
+
+ return view;
+ }
+});
+ | true |
Other | emberjs | ember.js | 5a4917b9aaee4f53c8196f9b3349ff775774dae2.json | Add Ember.Controller and `connectOutlet`
The goal of `connectOutlet` is to make it easy to
fill in a Handlebars-specified outlet with a new
view.
It also connects the view's associated controller
to the view's `controller` property, if an
associated controller can be found using
conventional naming. | packages/ember-views/tests/system/controller_test.js | @@ -0,0 +1,74 @@
+/*globals TestApp*/
+
+module("Ember.Controller#connectOutlet", {
+ setup: function() {
+ window.TestApp = Ember.Application.create();
+
+ TestApp.ApplicationController = Ember.Controller.extend();
+
+ TestApp.PostController = Ember.Controller.extend();
+ TestApp.PostView = Ember.Controller.extend();
+ },
+
+ teardown: function() {
+ window.TestApp = undefined;
+ }
+});
+
+test("connectOutlet instantiates a view, controller, and connects them", function() {
+ var postController = Ember.Controller.create();
+
+ var appController = TestApp.ApplicationController.create({
+ controllers: { postController: postController }
+ });
+ var view = appController.connectOutlet(TestApp.PostView);
+
+ ok(view instanceof TestApp.PostView, "the view is an instance of PostView");
+ equal(view.get('controller'), postController, "the controller is looked up on the parent's controllers hash");
+ equal(appController.get('view'), view, "the app controller's view is set");
+});
+
+test("connectOutlet takes an optional outlet name", function() {
+ var postController = Ember.Controller.create();
+
+ var appController = TestApp.ApplicationController.create({
+ controllers: { postController: postController }
+ });
+ var view = appController.connectOutlet('mainView', TestApp.PostView);
+
+ ok(view instanceof TestApp.PostView, "the view is an instance of PostView");
+ equal(view.get('controller'), postController, "the controller is looked up on the parent's controllers hash");
+ equal(appController.get('mainView'), view, "the app controller's view is set");
+});
+
+test("connectOutlet takes an optional controller context", function() {
+ var postController = Ember.Controller.create(),
+ context = {};
+
+ var appController = TestApp.ApplicationController.create({
+ controllers: { postController: postController }
+ });
+ var view = appController.connectOutlet(TestApp.PostView, context);
+
+ ok(view instanceof TestApp.PostView, "the view is an instance of PostView");
+ equal(view.get('controller'), postController, "the controller is looked up on the parent's controllers hash");
+ equal(appController.get('view'), view, "the app controller's view is set");
+ equal(view.getPath('controller.content'), context, "the controller receives the context");
+});
+
+test("connectOutlet works if all three parameters are provided", function() {
+ var postController = Ember.Controller.create(),
+ context = {};
+
+ var appController = TestApp.ApplicationController.create({
+ controllers: { postController: postController }
+ });
+ var view = appController.connectOutlet('mainView', TestApp.PostView, context);
+
+ ok(view instanceof TestApp.PostView, "the view is an instance of PostView");
+ equal(view.get('controller'), postController, "the controller is looked up on the parent's controllers hash");
+ equal(appController.get('mainView'), view, "the app controller's view is set");
+ equal(view.getPath('controller.content'), context, "the controller receives the context");
+});
+
+ | true |
Other | emberjs | ember.js | 7050fae731d96fddbe2ab3640e0786f4d8928bd4.json | Implement modelType guessing.
The way it works is:
if you have a single dynamic segment in your
state (e.g. your route is `/posts/:post_id`),
the router will remove the `_id` part off the
end and convert the remainder into class form.
in this case, that would be `Post`. It will then
look up the class on its `namespace` property:
router.getPath('namespace.Post')
Also in this commit, app.initialize(router) sets
the router's `namespace` to the application. | packages/ember-application/lib/system/application.js | @@ -94,23 +94,31 @@ Ember.Application = Ember.Namespace.extend(
...
});
- App.initialize(stateManager);
+ App.initialize(router);
- stateManager.get('postsController') // <App.PostsController:ember1234>
- stateManager.get('commentsController') // <App.CommentsController:ember1235>
+ router.get('postsController') // <App.PostsController:ember1234>
+ router.get('commentsController') // <App.CommentsController:ember1235>
- stateManager.getPath('postsController.stateManager') // stateManager
+ router.getPath('postsController.router') // router
*/
- initialize: function(stateManager) {
+ initialize: function(router) {
var properties = Ember.A(Ember.keys(this)),
injections = get(this.constructor, 'injections'),
namespace = this, controller, name;
+ // By default, the router's namespace is the current application.
+ //
+ // This allows it to find model classes when a state has a
+ // route like `/posts/:post_id`. In that case, it would first
+ // convert `post_id` into `Post`, and then look it up on its
+ // namespace.
+ set(router, 'namespace', this);
+
Ember.runLoadHooks('application', this);
properties.forEach(function(property) {
injections.forEach(function(injection) {
- injection(namespace, stateManager, property);
+ injection(namespace, router, property);
});
});
}, | true |
Other | emberjs | ember.js | 7050fae731d96fddbe2ab3640e0786f4d8928bd4.json | Implement modelType guessing.
The way it works is:
if you have a single dynamic segment in your
state (e.g. your route is `/posts/:post_id`),
the router will remove the `_id` part off the
end and convert the remainder into class form.
in this case, that would be `Post`. It will then
look up the class on its `namespace` property:
router.getPath('namespace.Post')
Also in this commit, app.initialize(router) sets
the router's `namespace` to the application. | packages/ember-runtime/lib/system/string.js | @@ -171,6 +171,19 @@ Ember.String = {
});
},
+ /**
+ Returns the UpperCamelCase form of a string.
+
+ 'innerHTML'.classify() => 'InnerHTML'
+ 'action_name'.classify() => 'ActionName'
+ 'css-class-name'.classify() => 'CssClassName'
+ 'my favorite items'.classift() => 'MyFavoriteItems'
+ */
+ classify: function(str) {
+ var camelized = Ember.String.camelize(str);
+ return camelized.charAt(0).toUpperCase() + camelized.substr(1);
+ },
+
/**
More general than decamelize. Returns the lower_case_and_underscored
form of a string. | true |
Other | emberjs | ember.js | 7050fae731d96fddbe2ab3640e0786f4d8928bd4.json | Implement modelType guessing.
The way it works is:
if you have a single dynamic segment in your
state (e.g. your route is `/posts/:post_id`),
the router will remove the `_id` part off the
end and convert the remainder into class form.
in this case, that would be `Post`. It will then
look up the class on its `namespace` property:
router.getPath('namespace.Post')
Also in this commit, app.initialize(router) sets
the router's `namespace` to the application. | packages/ember-states/lib/routable.js | @@ -19,7 +19,7 @@ var paramForClass = function(classObject) {
Ember.Routable = Ember.Mixin.create({
init: function() {
- this.on('setupControllers', this, this.stashContext);
+ this.on('connectOutlets', this, this.stashContext);
this._super();
},
@@ -67,7 +67,9 @@ Ember.Routable = Ember.Mixin.create({
}).cacheable(),
routeMatcher: Ember.computed(function() {
- return Ember._RouteMatcher.create({ route: get(this, 'route') });
+ if (get(this, 'route')) {
+ return Ember._RouteMatcher.create({ route: get(this, 'route') });
+ }
}).cacheable(),
modelClass: Ember.computed(function() {
@@ -80,20 +82,52 @@ Ember.Routable = Ember.Mixin.create({
}
}).cacheable(),
+ modelClassFor: function(manager) {
+ var modelClass, namespace, routeMatcher, identifiers, match, className;
+
+ // if an explicit modelType was specified, use that
+ if (modelClass = get(this, 'modelClass')) { return modelClass; }
+
+ // if the router has no lookup namespace, we won't be able to guess
+ // the modelType
+ namespace = get(manager, 'namespace');
+ if (!namespace) { return; }
+
+ // make sure this state is actually a routable state
+ routeMatcher = get(this, 'routeMatcher');
+ if (!routeMatcher) { return; }
+
+ // only guess modelType for states with a single dynamic segment
+ // (no more, no fewer)
+ identifiers = routeMatcher.identifiers;
+ if (identifiers.length !== 2) { return; }
+
+ // extract the `_id` from the end of the dynamic segment; if the
+ // dynamic segment does not end in `_id`, we can't guess the
+ // modelType
+ match = identifiers[1].match(/^(.*)_id$/);
+ if (!match) { return; }
+
+ // convert the underscored type into a class form and look it up
+ // on the router's namespace
+ className = Ember.String.classify(match[1]);
+ return get(namespace, className);
+ },
+
deserialize: function(manager, params) {
- var modelClass, param;
+ var modelClass, routeMatcher, param;
- if (modelClass = get(this, 'modelClass')) {
+ if (modelClass = this.modelClassFor(manager)) {
return modelClass.find(params[paramForClass(modelClass)]);
- } else {
- return params;
}
+
+ return params;
},
serialize: function(manager, context) {
- var modelClass, param, id;
+ var modelClass, routeMatcher, namespace, param, id;
- if (modelClass = get(this, 'modelClass')) {
+ if (modelClass = this.modelClassFor(manager)) {
param = paramForClass(modelClass);
id = get(context, 'id');
context = {}; | true |
Other | emberjs | ember.js | 7050fae731d96fddbe2ab3640e0786f4d8928bd4.json | Implement modelType guessing.
The way it works is:
if you have a single dynamic segment in your
state (e.g. your route is `/posts/:post_id`),
the router will remove the `_id` part off the
end and convert the remainder into class form.
in this case, that would be `Post`. It will then
look up the class on its `namespace` property:
router.getPath('namespace.Post')
Also in this commit, app.initialize(router) sets
the router's `namespace` to the application. | packages/ember-states/lib/state.js | @@ -88,7 +88,7 @@ Ember.State = Ember.Object.extend(Ember.Evented, {
return !get(this, 'childStates').length;
}).cacheable(),
- setupControllers: Ember.K,
+ connectOutlets: Ember.K,
enter: Ember.K,
exit: Ember.K
}); | true |
Other | emberjs | ember.js | 7050fae731d96fddbe2ab3640e0786f4d8928bd4.json | Implement modelType guessing.
The way it works is:
if you have a single dynamic segment in your
state (e.g. your route is `/posts/:post_id`),
the router will remove the `_id` part off the
end and convert the remainder into class form.
in this case, that would be `Post`. It will then
look up the class on its `namespace` property:
router.getPath('namespace.Post')
Also in this commit, app.initialize(router) sets
the router's `namespace` to the application. | packages/ember-states/lib/state_manager.js | @@ -449,7 +449,7 @@ Ember.StateManager = Ember.State.extend(
// 1. Normalize arguments
// 2. Ensure that we are in the correct state
// 3. Map provided path to context objects and send
- // appropriate setupControllers events
+ // appropriate connectOutlets events
if (Ember.empty(name)) { return; }
@@ -528,9 +528,8 @@ Ember.StateManager = Ember.State.extend(
state = this.findStatesByRoute(state, path);
state = state[state.length-1];
- state.fire('setupControllers', this, context);
+ state.fire('connectOutlets', this, context);
}, this);
- //getPath(root, path).setupControllers(this, context);
},
getState: function(name) { | true |
Other | emberjs | ember.js | 7050fae731d96fddbe2ab3640e0786f4d8928bd4.json | Implement modelType guessing.
The way it works is:
if you have a single dynamic segment in your
state (e.g. your route is `/posts/:post_id`),
the router will remove the `_id` part off the
end and convert the remainder into class form.
in this case, that would be `Post`. It will then
look up the class on its `namespace` property:
router.getPath('namespace.Post')
Also in this commit, app.initialize(router) sets
the router's `namespace` to the application. | packages/ember-states/tests/routable_test.js | @@ -229,7 +229,7 @@ module("Routing Serialization and Deserialization", {
show: Ember.State.create({
route: "/:post_id",
- setupControllers: function(manager, context) {
+ connectOutlets: function(manager, context) {
equal(context.post.id, 2, "should be the same value regardless of entry point");
},
@@ -279,7 +279,7 @@ test("should invoke the serialize method on a state when it is entered programma
var url, firstPost, firstUser;
-module("default serialize and deserialize", {
+module("default serialize and deserialize with modelType", {
setup: function() {
window.TestApp = Ember.Namespace.create();
window.TestApp.Post = Ember.Object.extend();
@@ -308,7 +308,7 @@ module("default serialize and deserialize", {
route: '/posts/:post_id',
modelType: 'TestApp.Post',
- setupControllers: function(router, post) {
+ connectOutlets: function(router, post) {
equal(post, firstPost, "the post should have deserialized correctly");
}
}),
@@ -317,7 +317,7 @@ module("default serialize and deserialize", {
route: '/users/:user_id',
modelType: window.TestApp.User,
- setupControllers: function(router, user) {
+ connectOutlets: function(router, user) {
equal(user, firstUser, "the post should have deserialized correctly");
}
})
@@ -352,3 +352,56 @@ test("should use a specified class `modelType` in the default `deserialize`", fu
router.route("/users/1");
});
+module("default serialize and deserialize without modelType", {
+ setup: function() {
+ window.TestApp = Ember.Namespace.create();
+ window.TestApp.Post = Ember.Object.extend();
+ window.TestApp.Post.find = function(id) {
+ if (id === "1") { return firstPost; }
+ };
+
+ window.TestApp.User = Ember.Object.extend();
+ window.TestApp.User.find = function(id) {
+ if (id === "1") { return firstUser; }
+ };
+
+ firstPost = window.TestApp.Post.create({ id: 1 });
+ firstUser = window.TestApp.User.create({ id: 1 });
+
+ router = Ember.Router.create({
+ namespace: window.TestApp,
+
+ location: {
+ setURL: function(passedURL) {
+ url = passedURL;
+ }
+ },
+
+ initialState: 'root',
+ root: Ember.State.extend({
+ post: Ember.State.extend({
+ route: '/posts/:post_id',
+
+ connectOutlets: function(router, post) {
+ equal(post, firstPost, "the post should have deserialized correctly");
+ }
+ })
+ })
+ });
+ },
+
+ teardown: function() {
+ window.TestApp = undefined;
+ }
+});
+
+test("should use a specified String `modelType` in the default `serialize`", function() {
+ router.transitionTo('post', firstPost);
+ equal(url, "/posts/1");
+});
+
+test("should use a specified String `modelType` in the default `deserialize`", function() {
+ expect(1);
+
+ router.route("/posts/1");
+}); | true |
Other | emberjs | ember.js | 7050fae731d96fddbe2ab3640e0786f4d8928bd4.json | Implement modelType guessing.
The way it works is:
if you have a single dynamic segment in your
state (e.g. your route is `/posts/:post_id`),
the router will remove the `_id` part off the
end and convert the remainder into class form.
in this case, that would be `Post`. It will then
look up the class on its `namespace` property:
router.getPath('namespace.Post')
Also in this commit, app.initialize(router) sets
the router's `namespace` to the application. | packages/ember-states/tests/state_manager_test.js | @@ -456,7 +456,7 @@ test("goToState with current state does not trigger enter or exit", function() {
module("Transition contexts");
-test("if a context is passed to a transition, the state's setupControllers event is triggered after the transition has completed", function() {
+test("if a context is passed to a transition, the state's connectOutlets event is triggered after the transition has completed", function() {
expect(1);
var context = {};
@@ -469,7 +469,7 @@ test("if a context is passed to a transition, the state's setupControllers event
}),
next: Ember.State.create({
- setupControllers: function(manager, passedContext) {
+ connectOutlets: function(manager, passedContext) {
equal(context, passedContext, "The context is passed through");
}
})
@@ -479,7 +479,7 @@ test("if a context is passed to a transition, the state's setupControllers event
stateManager.send('goNext', context);
});
-test("if a context is passed to a transition and the path is to the current state, the state's setupControllers event is triggered again", function() {
+test("if a context is passed to a transition and the path is to the current state, the state's connectOutlets event is triggered again", function() {
expect(2);
var counter = 0;
@@ -499,7 +499,7 @@ test("if a context is passed to a transition and the path is to the current stat
manager.goToState('next', counter);
},
- setupControllers: function(manager, context) {
+ connectOutlets: function(manager, context) {
equal(context, counter, "The context is passed through");
}
})
@@ -511,7 +511,7 @@ test("if a context is passed to a transition and the path is to the current stat
stateManager.send('goNext', counter);
});
-test("if no context is provided, setupControllers is triggered with an undefined context", function() {
+test("if no context is provided, connectOutlets is triggered with an undefined context", function() {
expect(2);
Ember.run(function() {
@@ -528,8 +528,8 @@ test("if no context is provided, setupControllers is triggered with an undefined
manager.transitionTo('next');
},
- setupControllers: function(manager, context) {
- equal(context, undefined, "setupControllers is called with no context");
+ connectOutlets: function(manager, context) {
+ equal(context, undefined, "connectOutlets is called with no context");
}
})
})
@@ -552,12 +552,12 @@ test("multiple contexts can be provided in a single transitionTo", function() {
}),
planters: Ember.State.create({
- setupControllers: function(manager, context) {
+ connectOutlets: function(manager, context) {
deepEqual(context, { company: true });
},
nuts: Ember.State.create({
- setupControllers: function(manager, context) {
+ connectOutlets: function(manager, context) {
deepEqual(context, { product: true });
}
}) | true |
Other | emberjs | ember.js | 0ecc1d799950eb29b6d672f3c1702bdd8f2e5e53.json | Add support for modelType in the router
If a `modelType` is specified in the router, the
router will automatically convert routes to
objects and vice versa.
For example, if the modelType is `App.Post` and
the state's route is `/posts/:post_id`:
* if the user navigates to `/posts/1`, the router
will automatically look up `App.Post.find(1)`
and pass it into setupControllers. The router
figures out the dynamic segment based on
naming conventions (App.Post => :post_id)
* if the app programmatically transitions to
the post state, passing in a post whose `id` is
5, the router will automatically set the current
URL to `/posts/5`. Again, this works via naming
conventions (the router looks up the `id`
property on the model and serializes it into
the `:post_id` dynamic segment) | packages/ember-states/lib/routable.js | @@ -9,6 +9,14 @@ var get = Ember.get, getPath = Ember.getPath;
// * .onURLChange(callback) - this happens when the user presses
// the back or forward button
+var paramForClass = function(classObject) {
+ var className = classObject.toString(),
+ parts = className.split("."),
+ last = parts[parts.length - 1];
+
+ return Ember.String.underscore(last) + "_id";
+};
+
Ember.Routable = Ember.Mixin.create({
init: function() {
this.on('setupControllers', this, this.stashContext);
@@ -62,11 +70,36 @@ Ember.Routable = Ember.Mixin.create({
return Ember._RouteMatcher.create({ route: get(this, 'route') });
}).cacheable(),
- deserialize: function(manager, context) {
- return context;
+ modelClass: Ember.computed(function() {
+ var modelType = get(this, 'modelType');
+
+ if (typeof modelType === 'string') {
+ return Ember.getPath(window, modelType);
+ } else {
+ return modelType;
+ }
+ }).cacheable(),
+
+ deserialize: function(manager, params) {
+ var modelClass, param;
+
+ if (modelClass = get(this, 'modelClass')) {
+ return modelClass.find(params[paramForClass(modelClass)]);
+ } else {
+ return params;
+ }
},
serialize: function(manager, context) {
+ var modelClass, param, id;
+
+ if (modelClass = get(this, 'modelClass')) {
+ param = paramForClass(modelClass);
+ id = get(context, 'id');
+ context = {};
+ context[param] = id;
+ }
+
return context;
},
| true |
Other | emberjs | ember.js | 0ecc1d799950eb29b6d672f3c1702bdd8f2e5e53.json | Add support for modelType in the router
If a `modelType` is specified in the router, the
router will automatically convert routes to
objects and vice versa.
For example, if the modelType is `App.Post` and
the state's route is `/posts/:post_id`:
* if the user navigates to `/posts/1`, the router
will automatically look up `App.Post.find(1)`
and pass it into setupControllers. The router
figures out the dynamic segment based on
naming conventions (App.Post => :post_id)
* if the app programmatically transitions to
the post state, passing in a post whose `id` is
5, the router will automatically set the current
URL to `/posts/5`. Again, this works via naming
conventions (the router looks up the `id`
property on the model and serializes it into
the `:post_id` dynamic segment) | packages/ember-states/tests/routable_test.js | @@ -277,3 +277,78 @@ test("should invoke the serialize method on a state when it is entered programma
equal(setURL, '/posts/2');
});
+var url, firstPost, firstUser;
+
+module("default serialize and deserialize", {
+ setup: function() {
+ window.TestApp = Ember.Namespace.create();
+ window.TestApp.Post = Ember.Object.extend();
+ window.TestApp.Post.find = function(id) {
+ if (id === "1") { return firstPost; }
+ };
+
+ window.TestApp.User = Ember.Object.extend();
+ window.TestApp.User.find = function(id) {
+ if (id === "1") { return firstUser; }
+ };
+
+ firstPost = window.TestApp.Post.create({ id: 1 });
+ firstUser = window.TestApp.User.create({ id: 1 });
+
+ router = Ember.Router.create({
+ location: {
+ setURL: function(passedURL) {
+ url = passedURL;
+ }
+ },
+
+ initialState: 'root',
+ root: Ember.State.extend({
+ post: Ember.State.extend({
+ route: '/posts/:post_id',
+ modelType: 'TestApp.Post',
+
+ setupControllers: function(router, post) {
+ equal(post, firstPost, "the post should have deserialized correctly");
+ }
+ }),
+
+ user: Ember.State.extend({
+ route: '/users/:user_id',
+ modelType: window.TestApp.User,
+
+ setupControllers: function(router, user) {
+ equal(user, firstUser, "the post should have deserialized correctly");
+ }
+ })
+ })
+ });
+ },
+
+ teardown: function() {
+ window.TestApp = undefined;
+ }
+});
+
+test("should use a specified String `modelType` in the default `serialize`", function() {
+ router.transitionTo('post', firstPost);
+ equal(url, "/posts/1");
+});
+
+test("should use a specified String `modelType` in the default `deserialize`", function() {
+ expect(1);
+
+ router.route("/posts/1");
+});
+
+test("should use a specified class `modelType` in the default `serialize`", function() {
+ router.transitionTo('user', firstUser);
+ equal(url, "/users/1");
+});
+
+test("should use a specified class `modelType` in the default `deserialize`", function() {
+ expect(1);
+
+ router.route("/users/1");
+});
+ | true |
Other | emberjs | ember.js | 0f649992a5fe915137ef4915aff30492649d995a.json | Change default test params | Rakefile | @@ -118,7 +118,7 @@ task :test, [:suite] => :dist do |t, args|
"package=all&extendprototypes=true&nojshint=true",
"package=all&extendprototypes=true&jquery=1.6.4&nojshint=true",
"package=all&extendprototypes=true&jquery=git&nojshint=true",
- "package=all&cpdefaultcacheable=true&nojshint=true",
+ "package=all&nocpdefaultcacheable=true&nojshint=true",
"package=all&noviewpreservescontext=true&nojshint=true",
"package=all&dist=build&nojshint=true"]
} | true |
Other | emberjs | ember.js | 0f649992a5fe915137ef4915aff30492649d995a.json | Change default test params | tests/index.html | @@ -41,10 +41,10 @@
ENV['EXTEND_PROTOTYPES'] = !!extendPrototypes;
// Handle CP cacheable by default
- QUnit.config.urlConfig.push('cpdefaultcacheable');
+ QUnit.config.urlConfig.push('nocpdefaultcacheable');
- var cpDefaultCacheable = QUnit.urlParams.cpdefaultcacheable;
- ENV['CP_DEFAULT_CACHEABLE'] = !!cpDefaultCacheable;
+ var noCpDefaultCacheable = QUnit.urlParams.nocpdefaultcacheable;
+ ENV['CP_DEFAULT_CACHEABLE'] = !noCpDefaultCacheable;
// Handle preserving context
QUnit.config.urlConfig.push('noviewpreservescontext'); | true |
Other | emberjs | ember.js | 3631ff0f1ba73a193da653935ca27bdff1552929.json | remove reschedule fixes #742 | packages/ember-metal/lib/watching.js | @@ -120,16 +120,15 @@ var pendingQueue = [];
// back in the queue and reschedule is true, schedules a timeout to try
// again.
/** @private */
-function flushPendingChains(reschedule) {
+function flushPendingChains() {
if (pendingQueue.length===0) return ; // nothing to do
var queue = pendingQueue;
pendingQueue = [];
forEach(queue, function(q) { q[0].add(q[1]); });
- if (reschedule!==false && pendingQueue.length>0) {
- setTimeout(flushPendingChains, 1);
- }
+
+ Ember.warn('Watching an undefined global, Ember expects watched globals to be setup by the time the run loop is flushed, check for typos', pendingQueue.length > 0);
}
/** @private */ | false |
Other | emberjs | ember.js | 8118866ef1c6838a5c08ac3b1a9d092fd023f835.json | Fix failing unit tests due to deferred teardown
Object destruction is deferred until the end of
the run loop. This was causing failing unit
tests in some cases where the old event dispatcher
was not being torn down before a new test started.
This ensures that application creation and
teardown happen inside run loops. This commit
also starts the process of ensuring that no code
gets scheduled to run from an auto timer.
In the future we should throw an exception if
deferred code is run outside a run loop. | packages/ember-application/tests/system/application_test.js | @@ -80,7 +80,9 @@ test("acts like a namespace", function() {
});
app.Foo = Ember.Object.extend();
equal(app.Foo.toString(), "TestApp.Foo", "Classes pick up their parent namespace");
- app.destroy();
+ Ember.run(function() {
+ app.destroy();
+ });
window.TestApp = undefined;
});
@@ -93,7 +95,9 @@ module("Ember.Application initialization", {
});
test("initialize controllers into a state manager", function() {
- app = Ember.Application.create();
+ Ember.run(function() {
+ app = Ember.Application.create();
+ });
app.FooController = Ember.Object.extend();
app.BarController = Ember.ArrayController.extend(); | true |
Other | emberjs | ember.js | 8118866ef1c6838a5c08ac3b1a9d092fd023f835.json | Fix failing unit tests due to deferred teardown
Object destruction is deferred until the end of
the run loop. This was causing failing unit
tests in some cases where the old event dispatcher
was not being torn down before a new test started.
This ensures that application creation and
teardown happen inside run loops. This commit
also starts the process of ensuring that no code
gets scheduled to run from an auto timer.
In the future we should throw an exception if
deferred code is run outside a run loop. | packages/ember-handlebars/tests/controls/select_test.js | @@ -10,8 +10,10 @@ module("Ember.Select", {
},
teardown: function() {
- dispatcher.destroy();
- select.destroy();
+ Ember.run(function() {
+ dispatcher.destroy();
+ select.destroy();
+ });
}
});
@@ -228,7 +230,9 @@ module("Ember.Select - usage inside templates", {
},
teardown: function() {
- dispatcher.destroy();
+ Ember.run(function() {
+ dispatcher.destroy();
+ });
}
});
| true |
Other | emberjs | ember.js | 8118866ef1c6838a5c08ac3b1a9d092fd023f835.json | Fix failing unit tests due to deferred teardown
Object destruction is deferred until the end of
the run loop. This was causing failing unit
tests in some cases where the old event dispatcher
was not being torn down before a new test started.
This ensures that application creation and
teardown happen inside run loops. This commit
also starts the process of ensuring that no code
gets scheduled to run from an auto timer.
In the future we should throw an exception if
deferred code is run outside a run loop. | packages/ember-handlebars/tests/controls/text_area_test.js | @@ -18,7 +18,9 @@ module("Ember.TextArea", {
},
teardown: function() {
- textArea.destroy();
+ Ember.run(function() {
+ textArea.destroy();
+ });
TestObject = textArea = null;
}
}); | true |
Other | emberjs | ember.js | 8118866ef1c6838a5c08ac3b1a9d092fd023f835.json | Fix failing unit tests due to deferred teardown
Object destruction is deferred until the end of
the run loop. This was causing failing unit
tests in some cases where the old event dispatcher
was not being torn down before a new test started.
This ensures that application creation and
teardown happen inside run loops. This commit
also starts the process of ensuring that no code
gets scheduled to run from an auto timer.
In the future we should throw an exception if
deferred code is run outside a run loop. | packages/ember-handlebars/tests/controls/text_field_test.js | @@ -18,7 +18,9 @@ module("Ember.TextField", {
},
teardown: function() {
- textField.destroy();
+ Ember.run(function() {
+ textField.destroy();
+ });
TestObject = textField = null;
}
}); | true |
Other | emberjs | ember.js | 8118866ef1c6838a5c08ac3b1a9d092fd023f835.json | Fix failing unit tests due to deferred teardown
Object destruction is deferred until the end of
the run loop. This was causing failing unit
tests in some cases where the old event dispatcher
was not being torn down before a new test started.
This ensures that application creation and
teardown happen inside run loops. This commit
also starts the process of ensuring that no code
gets scheduled to run from an auto timer.
In the future we should throw an exception if
deferred code is run outside a run loop. | packages/ember-handlebars/tests/handlebars_test.js | @@ -80,7 +80,9 @@ module("Ember.View - handlebars integration", {
teardown: function() {
if (view) {
- view.destroy();
+ Ember.run(function() {
+ view.destroy();
+ });
view = null;
}
window.TemplateTests = undefined;
@@ -515,7 +517,9 @@ test("Handlebars templates update properties if a content object changes", funct
equal(view.$('#price').text(), "$5", "should update price field when price property is changed");
- view.destroy();
+ Ember.run(function() {
+ view.destroy();
+ });
});
test("Template updates correctly if a path is passed to the bind helper", function() {
@@ -853,7 +857,9 @@ test("should warn if setting a template on a view with a templateName already sp
appendView();
}, Error, "raises if conflicting template and templateName are provided");
- view.destroy();
+ Ember.run(function() {
+ view.destroy();
+ });
view = Ember.View.create({
childView: Ember.View.extend(),
@@ -936,7 +942,9 @@ test("Collection views that specify an example view class have their children be
ok(firstGrandchild(parentView).isCustom, "uses the example view class");
- parentView.destroy();
+ Ember.run(function() {
+ parentView.destroy();
+ });
});
test("itemViewClass works in the #collection helper", function() {
@@ -958,7 +966,9 @@ test("itemViewClass works in the #collection helper", function() {
ok(firstGrandchild(parentView).isAlsoCustom, "uses the example view class specified in the #collection helper");
- parentView.destroy();
+ Ember.run(function() {
+ parentView.destroy();
+ });
});
test("itemViewClass works in the #collection helper relatively", function() {
@@ -984,7 +994,9 @@ test("itemViewClass works in the #collection helper relatively", function() {
ok(firstGrandchild(parentView).isAlsoCustom, "uses the example view class specified in the #collection helper");
- parentView.destroy();
+ Ember.run(function() {
+ parentView.destroy();
+ });
});
test("should update boundIf blocks if the conditional changes", function() {
@@ -1338,7 +1350,9 @@ test("should not reset cursor position when text field receives keyUp event", fu
equal(view.$().caretPosition(), 5, "The keyUp event should not result in the cursor being reset due to the bindAttr observers");
- view.destroy();
+ Ember.run(function() {
+ view.destroy();
+ });
});
test("should be able to bind element attributes using {{bindAttr}} inside a block", function() {
@@ -1642,7 +1656,9 @@ test("should expose a controller keyword when present on the view", function() {
equal(view.$().text(), "BARBLARGH", "updates the DOM when a bound value is updated");
- view.destroy();
+ Ember.run(function() {
+ view.destroy();
+ });
view = Ember.View.create({
controller: "aString",
@@ -1756,7 +1772,9 @@ module("Templates redrawing and bindings", {
MyApp = Ember.Object.create({});
},
teardown: function(){
- if (view) view.destroy();
+ Ember.run(function() {
+ if (view) view.destroy();
+ });
window.MyApp = null;
}
});
@@ -1927,7 +1945,10 @@ test("bindings can be 'this', in which case they *are* the current context", fun
test("should not enter an infinite loop when binding an attribute in Handlebars", function() {
expect(0);
- App = Ember.Application.create();
+ Ember.run(function() {
+ App = Ember.Application.create();
+ });
+
App.test = Ember.Object.create({ href: 'test' });
App.Link = Ember.View.extend({
classNames: ['app-link'],
@@ -1951,7 +1972,9 @@ test("should not enter an infinite loop when binding an attribute in Handlebars"
});
// equal(view.$().attr('href'), 'test');
- parentView.destroy();
+ Ember.run(function() {
+ parentView.destroy();
+ });
Ember.run(function() {
App.destroy(); | true |
Other | emberjs | ember.js | 8118866ef1c6838a5c08ac3b1a9d092fd023f835.json | Fix failing unit tests due to deferred teardown
Object destruction is deferred until the end of
the run loop. This was causing failing unit
tests in some cases where the old event dispatcher
was not being torn down before a new test started.
This ensures that application creation and
teardown happen inside run loops. This commit
also starts the process of ensuring that no code
gets scheduled to run from an auto timer.
In the future we should throw an exception if
deferred code is run outside a run loop. | packages/ember-handlebars/tests/views/collection_view_test.js | @@ -65,7 +65,9 @@ test("collection helper should accept relative paths", function() {
});
test("empty views should be removed when content is added to the collection (regression, ht: msofaer)", function() {
- window.App = Ember.Application.create();
+ Ember.run(function() {
+ window.App = Ember.Application.create();
+ });
App.EmptyView = Ember.View.extend({
template : Ember.Handlebars.compile("<td>No Rows Yet</td>") | true |
Other | emberjs | ember.js | 8118866ef1c6838a5c08ac3b1a9d092fd023f835.json | Fix failing unit tests due to deferred teardown
Object destruction is deferred until the end of
the run loop. This was causing failing unit
tests in some cases where the old event dispatcher
was not being torn down before a new test started.
This ensures that application creation and
teardown happen inside run loops. This commit
also starts the process of ensuring that no code
gets scheduled to run from an auto timer.
In the future we should throw an exception if
deferred code is run outside a run loop. | packages/ember-states/tests/state_manager_test.js | @@ -31,9 +31,11 @@ module("Ember.StateManager", {
},
teardown: function() {
- if (stateManager) {
- stateManager.destroy();
- }
+ Ember.run(function() {
+ if (stateManager) {
+ stateManager.destroy();
+ }
+ });
}
});
| true |
Other | emberjs | ember.js | 8118866ef1c6838a5c08ac3b1a9d092fd023f835.json | Fix failing unit tests due to deferred teardown
Object destruction is deferred until the end of
the run loop. This was causing failing unit
tests in some cases where the old event dispatcher
was not being torn down before a new test started.
This ensures that application creation and
teardown happen inside run loops. This commit
also starts the process of ensuring that no code
gets scheduled to run from an auto timer.
In the future we should throw an exception if
deferred code is run outside a run loop. | packages/ember-views/tests/system/event_dispatcher_test.js | @@ -11,13 +11,17 @@ var set = Ember.set, get = Ember.get;
module("Ember.EventDispatcher", {
setup: function() {
- dispatcher = Ember.EventDispatcher.create();
- dispatcher.setup();
+ Ember.run(function() {
+ dispatcher = Ember.EventDispatcher.create();
+ dispatcher.setup();
+ });
},
teardown: function() {
- if (view) { view.destroy(); }
- dispatcher.destroy();
+ Ember.run(function() {
+ if (view) { view.destroy(); }
+ dispatcher.destroy();
+ });
}
});
@@ -154,7 +158,10 @@ test("events should stop propagating if the view is destroyed", function() {
change: function(evt) {
receivedEvent = true;
- get(this, 'parentView').destroy();
+ var self = this;
+ Ember.run(function() {
+ get(self, 'parentView').destroy();
+ });
}
});
| true |
Other | emberjs | ember.js | 27eca01d12ee22de0997be117158699678b40ca9.json | Fix bindAttr with keywords - Fixed #798
bindAttr was not properly setting up observers when keywords were used
so changes weren't properly propagated. | packages/ember-handlebars/lib/helpers/binding.js | @@ -8,7 +8,8 @@ require('ember-handlebars/ext');
require('ember-handlebars/views/handlebars_bound_view');
require('ember-handlebars/views/metamorph_view');
-var get = Ember.get, getPath = Ember.Handlebars.getPath, set = Ember.set, fmt = Ember.String.fmt;
+var get = Ember.get, getPath = Ember.getPath, set = Ember.set, fmt = Ember.String.fmt;
+var normalizePath = Ember.Handlebars.normalizePath;
var forEach = Ember.ArrayUtils.forEach;
var EmberHandlebars = Ember.Handlebars, helpers = EmberHandlebars.helpers;
@@ -23,7 +24,7 @@ var bind = function(property, options, preserveContext, shouldDisplay, valueNorm
currentContext = this,
pathRoot, path, normalized;
- normalized = Ember.Handlebars.normalizePath(currentContext, property, data);
+ normalized = normalizePath(currentContext, property, data);
pathRoot = normalized.root;
path = normalized.path;
@@ -251,11 +252,17 @@ EmberHandlebars.registerHelper('bindAttr', function(options) {
// For each attribute passed, create an observer and emit the
// current value of the property as an attribute.
forEach(attrKeys, function(attr) {
- var property = attrs[attr];
+ var path = attrs[attr],
+ pathRoot, normalized;
- Ember.assert(fmt("You must provide a String for a bound attribute, not %@", [property]), typeof property === 'string');
+ Ember.assert(fmt("You must provide a String for a bound attribute, not %@", [path]), typeof path === 'string');
- var value = (property === 'this') ? ctx : getPath(ctx, property, options),
+ normalized = normalizePath(ctx, path, options.data);
+
+ pathRoot = normalized.root;
+ path = normalized.path;
+
+ var value = (path === 'this') ? pathRoot : getPath(pathRoot, path, options),
type = Ember.typeOf(value);
Ember.assert(fmt("Attributes must be numbers, strings or booleans, not %@", [value]), value === null || value === undefined || type === 'number' || type === 'string' || type === 'boolean');
@@ -264,7 +271,7 @@ EmberHandlebars.registerHelper('bindAttr', function(options) {
/** @private */
observer = function observer() {
- var result = getPath(ctx, property, options);
+ var result = getPath(pathRoot, path, options);
Ember.assert(fmt("Attributes must be numbers, strings or booleans, not %@", [result]), result === null || result === undefined || typeof result === 'number' || typeof result === 'string' || typeof result === 'boolean');
@@ -275,7 +282,7 @@ EmberHandlebars.registerHelper('bindAttr', function(options) {
// In that case, we can assume the template has been re-rendered
// and we need to clean up the observer.
if (elem.length === 0) {
- Ember.removeObserver(ctx, property, invoker);
+ Ember.removeObserver(pathRoot, path, invoker);
return;
}
@@ -290,8 +297,8 @@ EmberHandlebars.registerHelper('bindAttr', function(options) {
// Add an observer to the view for when the property changes.
// When the observer fires, find the element using the
// unique data id and update the attribute to the new value.
- if (property !== 'this') {
- Ember.addObserver(ctx, property, invoker);
+ if (path !== 'this') {
+ Ember.addObserver(pathRoot, path, invoker);
}
// if this changes, also change the logic in ember-views/lib/views/view.js
@@ -341,13 +348,8 @@ EmberHandlebars.bindClasses = function(context, classBindings, view, bindAttrId,
// Helper method to retrieve the property from the context and
// determine which class string to return, based on whether it is
// a Boolean or not.
- var classStringForProperty = function(property) {
- var split = property.split(':'),
- className = split[1];
-
- property = split[0];
-
- var val = property !== '' ? getPath(context, property, options) : true;
+ var classStringForPath = function(root, path, className, options) {
+ var val = path !== '' ? getPath(root, path, options) : true;
// If the value is truthy and we're using the colon syntax,
// we should return the className directly
@@ -360,7 +362,7 @@ EmberHandlebars.bindClasses = function(context, classBindings, view, bindAttrId,
// Normalize property path to be suitable for use
// as a class name. For exaple, content.foo.barBaz
// becomes bar-baz.
- var parts = property.split('.');
+ var parts = path.split('.');
return Ember.String.dasherize(parts[parts.length-1]);
// If the value is not false, undefined, or null, return the current
@@ -386,18 +388,31 @@ EmberHandlebars.bindClasses = function(context, classBindings, view, bindAttrId,
var observer, invoker;
+ var split = binding.split(':'),
+ path = split[0],
+ className = split[1],
+ pathRoot = context,
+ normalized;
+
+ if (path !== '') {
+ normalized = normalizePath(context, path, options.data);
+
+ pathRoot = normalized.root;
+ path = normalized.path;
+ }
+
// Set up an observer on the context. If the property changes, toggle the
// class name.
/** @private */
observer = function() {
// Get the current value of the property
- newClass = classStringForProperty(binding);
+ newClass = classStringForPath(pathRoot, path, className, options);
elem = bindAttrId ? view.$("[data-bindattr-" + bindAttrId + "='" + bindAttrId + "']") : view.$();
// If we can't find the element anymore, a parent template has been
// re-rendered and we've been nuked. Remove the observer.
if (elem.length === 0) {
- Ember.removeObserver(context, binding, invoker);
+ Ember.removeObserver(pathRoot, path, invoker);
} else {
// If we had previously added a class to the element, remove it.
if (oldClass) {
@@ -420,14 +435,13 @@ EmberHandlebars.bindClasses = function(context, classBindings, view, bindAttrId,
Ember.run.once(observer);
};
- var property = binding.split(':')[0];
- if (property !== '') {
- Ember.addObserver(context, property, invoker);
+ if (path !== '') {
+ Ember.addObserver(pathRoot, path, invoker);
}
// We've already setup the observer; now we just need to figure out the
// correct behavior right now on the first pass through.
- value = classStringForProperty(binding);
+ value = classStringForPath(pathRoot, path, className, options);
if (value) {
ret.push(value); | true |
Other | emberjs | ember.js | 27eca01d12ee22de0997be117158699678b40ca9.json | Fix bindAttr with keywords - Fixed #798
bindAttr was not properly setting up observers when keywords were used
so changes weren't properly propagated. | packages/ember-handlebars/tests/handlebars_test.js | @@ -1235,6 +1235,23 @@ test("should be able to bind element attributes using {{bindAttr}}", function()
equal(view.$('img').attr('alt'), "Nanananana Ember!", "updates alt attribute when title property is computed");
});
+test("should be able to bind to view attributes with {{bindAttr}}", function() {
+ view = Ember.View.create({
+ value: 'test.jpg',
+ template: Ember.Handlebars.compile('<img {{bindAttr src="view.value"}}>')
+ });
+
+ appendView();
+
+ equal(view.$('img').attr('src'), "test.jpg", "renders initial value");
+
+ Ember.run(function() {
+ view.set('value', 'updated.jpg');
+ });
+
+ equal(view.$('img').attr('src'), "updated.jpg", "updates value");
+});
+
test("should not allow XSS injection via {{bindAttr}}", function() {
view = Ember.View.create({
template: Ember.Handlebars.compile('<img {{bindAttr src="content.url"}}>'),
@@ -1385,6 +1402,25 @@ test("should be able to bind class attribute via a truthy property with {{bindAt
equal(view.$('.is-truthy').length, 0, "removes class name if bound property is set to something non-truthy");
});
+test("should be able to bind class to view attribute with {{bindAttr}}", function() {
+ var template = Ember.Handlebars.compile('<img {{bindAttr class="view.foo"}}>');
+
+ view = Ember.View.create({
+ template: template,
+ foo: 'bar'
+ });
+
+ appendView();
+
+ equal(view.$('img').attr('class'), 'bar', "renders class");
+
+ Ember.run(function() {
+ set(view, 'foo', 'baz');
+ });
+
+ equal(view.$('img').attr('class'), 'baz', "updates class");
+});
+
test("should not allow XSS injection via {{bindAttr}} with class", function() {
view = Ember.View.create({
template: Ember.Handlebars.compile('<img {{bindAttr class="foo"}}>'), | true |
Other | emberjs | ember.js | 4435dc7b79efd950e3c47bcfcf9796d6462a7b03.json | Fix example to reflect classes not instances. | packages/ember-views/lib/system/application.js | @@ -89,8 +89,8 @@ Ember.Application = Ember.Namespace.extend(
Example:
- App.PostsController = Ember.ArrayController.create();
- App.CommentsController = Ember.ArrayController.create();
+ App.PostsController = Ember.ArrayController.extend();
+ App.CommentsController = Ember.ArrayController.extend();
var stateManager = Ember.StateManager.create({
... | false |
Other | emberjs | ember.js | 455b2ecbcd3e4fe72a9eec9ed9ddb1d52ba92ee7.json | Defer readiness to the end of the run loop
Currently, the application "becomes ready"
immediately upon being notified by jQuery that
the DOM is ready.
However, in cases where the Ember app loads after
the DOM ready event, this doesn't give your
classes a chance to load before the app is
initialized.
This change defers running application setup
until after the first run loop when bindings have
synchronized. This means that your classes will
be defined and all of their bindings synchronized
before your state manager receives its readiness
notification. | packages/ember-application/lib/system/application.js | @@ -72,11 +72,11 @@ Ember.Application = Ember.Namespace.extend(
// jQuery 1.7 doesn't call the ready callback if already ready
if (Ember.$.isReady) {
- this.didBecomeReady();
+ Ember.run.once(this, this.didBecomeReady);
} else {
var self = this;
Ember.$(document).ready(function() {
- self.didBecomeReady();
+ Ember.run.once(self, self.didBecomeReady);
});
}
},
@@ -117,11 +117,32 @@ Ember.Application = Ember.Namespace.extend(
/** @private */
didBecomeReady: function() {
var eventDispatcher = get(this, 'eventDispatcher'),
+ stateManager = get(this, 'stateManager'),
customEvents = get(this, 'customEvents');
eventDispatcher.setup(customEvents);
this.ready();
+
+ if (stateManager) {
+ this.setupStateManager(stateManager);
+ }
+ },
+
+ /**
+ @private
+
+ If the application has a state manager, use it to route
+ to the current URL, and trigger a new call to `route`
+ whenever the URL changes.
+ */
+ setupStateManager: function(stateManager) {
+ var location = get(stateManager, 'location');
+
+ stateManager.route(location.getURL());
+ location.onUpdateURL(function(url) {
+ stateManager.route(url);
+ });
},
/** | true |
Other | emberjs | ember.js | 455b2ecbcd3e4fe72a9eec9ed9ddb1d52ba92ee7.json | Defer readiness to the end of the run loop
Currently, the application "becomes ready"
immediately upon being notified by jQuery that
the DOM is ready.
However, in cases where the Ember app loads after
the DOM ready event, this doesn't give your
classes a chance to load before the app is
initialized.
This change defers running application setup
until after the first run loop when bindings have
synchronized. This means that your classes will
be defined and all of their bindings synchronized
before your state manager receives its readiness
notification. | packages/ember-application/tests/system/application_test.js | @@ -12,7 +12,9 @@ var set = Ember.set, get = Ember.get, getPath = Ember.getPath;
module("Ember.Application", {
setup: function() {
Ember.$("#qunit-fixture").html("<div id='one'><div id='one-child'>HI</div></div><div id='two'>HI</div>");
- application = Ember.Application.create({ rootElement: '#one' });
+ Ember.run(function() {
+ application = Ember.Application.create({ rootElement: '#one' });
+ });
},
teardown: function() {
@@ -21,41 +23,61 @@ module("Ember.Application", {
});
test("you can make a new application in a non-overlapping element", function() {
- var app = Ember.Application.create({ rootElement: '#two' });
- app.destroy();
+ var app;
+ Ember.run(function() {
+ app = Ember.Application.create({ rootElement: '#two' });
+ });
+ Ember.run(function() {
+ app.destroy();
+ });
ok(true, "should not raise");
});
test("you cannot make a new application that is a parent of an existing application", function() {
raises(function() {
- Ember.Application.create({ rootElement: '#qunit-fixture' });
+ Ember.run(function() {
+ Ember.Application.create({ rootElement: '#qunit-fixture' });
+ });
}, Error);
});
test("you cannot make a new application that is a descendent of an existing application", function() {
raises(function() {
- Ember.Application.create({ rootElement: '#one-child' });
+ Ember.run(function() {
+ Ember.Application.create({ rootElement: '#one-child' });
+ });
}, Error);
});
test("you cannot make a new application that is a duplicate of an existing application", function() {
raises(function() {
- Ember.Application.create({ rootElement: '#one' });
+ Ember.run(function() {
+ Ember.Application.create({ rootElement: '#one' });
+ });
}, Error);
});
test("you cannot make two default applications without a rootElement error", function() {
// Teardown existing
- application.destroy();
+ Ember.run(function() {
+ application.destroy();
+ });
- application = Ember.Application.create();
+ Ember.run(function() {
+ application = Ember.Application.create();
+ });
raises(function() {
- Ember.Application.create();
+ Ember.run(function() {
+ Ember.Application.create();
+ });
}, Error);
});
test("acts like a namespace", function() {
- var app = window.TestApp = Ember.Application.create({rootElement: '#two'});
+ var app;
+ Ember.run(function() {
+ app = window.TestApp = Ember.Application.create({rootElement: '#two'});
+ });
app.Foo = Ember.Object.extend();
equal(app.Foo.toString(), "TestApp.Foo", "Classes pick up their parent namespace");
app.destroy();
@@ -89,3 +111,27 @@ test("inject controllers into a state manager", function() {
equal(getPath(stateManager, 'fooController.stateManager'), stateManager, "the state manager is assigned");
equal(getPath(stateManager, 'barController.stateManager'), stateManager, "the state manager is assigned");
});
+
+module("Ember.Application initial route", function() {
+ Ember.run(function() {
+ app = Ember.Application.create({
+ rootElement: '#qunit-fixture'
+ });
+
+ app.stateManager = Ember.StateManager.create({
+ location: {
+ getURL: function() {
+ return '/';
+ }
+ },
+
+ start: Ember.State.extend({
+ index: Ember.State.extend({
+ route: '/'
+ })
+ })
+ });
+ });
+
+ equal(app.getPath('stateManager.currentState.path'), 'start.index', "The router moved the state into the right place");
+}); | true |
Other | emberjs | ember.js | b6978aadc1d0af5c02b5e8ee022d15b1cf6297d3.json | Update execjs to avoid deprecation warnings | Gemfile.lock | @@ -35,7 +35,7 @@ GEM
specs:
addressable (2.2.7)
colored (1.2)
- execjs (1.3.0)
+ execjs (1.3.2)
multi_json (~> 1.0)
faraday (0.7.6)
addressable (~> 2.2)
@@ -51,7 +51,7 @@ GEM
kicker (2.5.0)
rb-fsevent
mime-types (1.18)
- multi_json (1.3.2)
+ multi_json (1.3.5)
multipart-post (1.1.5)
nokogiri (1.5.2)
oauth2 (0.5.2) | false |
Other | emberjs | ember.js | dfad0c557334b651db5419cd94e5f50034d0671e.json | Improve view documentation | packages/ember-views/lib/views/view.js | @@ -232,7 +232,7 @@ var invokeForState = {
firstName: 'Barry'
})
excitedGreeting: function(){
- return this.getPath("contnet.firstName") + "!!!"
+ return this.getPath("content.firstName") + "!!!"
}
})
@@ -1098,10 +1098,9 @@ Ember.View = Ember.Object.extend(Ember.Evented,
},
/**
- Replaces the view's element to the specified parent element.
+ Replaces the content of the specified parent element with this view's element.
If the view does not have an HTML representation yet, `createElement()`
will be called automatically.
- If the parent element already has some content, it will be removed.
Note that this method just schedules the view to be appended; the DOM
element will not be appended to the given element until all bindings have
@@ -1190,7 +1189,11 @@ Ember.View = Ember.Object.extend(Ember.Evented,
return value !== undefined ? value : Ember.guidFor(this);
}).cacheable(),
- /** @private */
+ /**
+ @private
+
+ TODO: Perhaps this should be removed from the production build somehow.
+ */
_elementIdDidChange: Ember.beforeObserver(function() {
throw "Changing a view's elementId after creation is not allowed.";
}, 'elementId'), | false |
Other | emberjs | ember.js | a4e9d88d1ffac8fb86cebe8362d3c55be4dc9fb6.json | Add support for "input" event handlers
This is an HTML standard event, like "change".
https://developer.mozilla.org/en/DOM/window.oninput
http://www.whatwg.org/specs/web-apps/current-work/multipage/common-input-element-attributes.html#event-input-input | packages/ember-views/lib/system/event_dispatcher.js | @@ -63,6 +63,7 @@ Ember.EventDispatcher = Ember.Object.extend(
mouseenter : 'mouseEnter',
mouseleave : 'mouseLeave',
submit : 'submit',
+ input : 'input',
change : 'change',
dragstart : 'dragStart',
drag : 'drag', | false |
Other | emberjs | ember.js | d67634349c8500b2ce7e08e3f1c3355004565881.json | Update ExecJS to avoid deprecation warnings | Gemfile.lock | @@ -35,7 +35,7 @@ GEM
specs:
addressable (2.2.7)
colored (1.2)
- execjs (1.3.0)
+ execjs (1.3.2)
multi_json (~> 1.0)
faraday (0.7.6)
addressable (~> 2.2)
@@ -51,7 +51,7 @@ GEM
kicker (2.5.0)
rb-fsevent
mime-types (1.18)
- multi_json (1.3.2)
+ multi_json (1.3.5)
multipart-post (1.1.5)
nokogiri (1.5.2)
oauth2 (0.5.2) | false |
Other | emberjs | ember.js | 6a6db5b383d41d33c3c0c978f773122bf1007bc8.json | Fix JsDoc tags | packages/ember-states/lib/state_manager.js | @@ -353,7 +353,7 @@ require('ember-states/state');
**/
Ember.StateManager = Ember.State.extend(
-/** @scope Ember.State.prototype */ {
+/** @scope Ember.StateManager.prototype */ {
/**
When creating a new statemanager, look for a default state to transition
@@ -377,11 +377,11 @@ Ember.StateManager = Ember.State.extend(
currentState: null,
/**
- @property
-
If set to true, `errorOnUnhandledEvents` will cause an exception to be
raised if you attempt to send an event to a state manager that is not
handled by the current state or any of its parent states.
+
+ @property {Boolean}
*/
errorOnUnhandledEvent: true,
| true |
Other | emberjs | ember.js | 6a6db5b383d41d33c3c0c978f773122bf1007bc8.json | Fix JsDoc tags | packages/ember-viewstates/lib/state_manager.js | @@ -239,15 +239,15 @@ var get = Ember.get, set = Ember.set, getPath = Ember.getPath, fmt = Ember.Strin
`view` that references the `Ember.View` object that was interacted with.
**/
-
-Ember.StateManager.reopen({
+Ember.StateManager.reopen(
+/** @scope Ember.StateManager.prototype */ {
/**
- @property
-
If the current state is a view state or the descendent of a view state,
this property will be the view associated with it. If there is no
view state active in this state manager, this value will be null.
+
+ @property
*/
currentView: Ember.computed(function() {
var currentState = get(this, 'currentState'), | true |
Other | emberjs | ember.js | f32a10660a5571875a59d46e7144a3de8a7a8c0b.json | Fix issue with "/" route alongside "/*" | packages/ember-states/lib/routable.js | @@ -19,10 +19,17 @@ Ember._RouteMatcher = Ember.Object.extend({
state: null,
init: function() {
- var route = get(this, 'route'),
- escaped = escapeForRegex(route),
+ var route = this.route,
identifiers = [],
- count = 1;
+ count = 1,
+ escaped;
+
+ // Strip off leading slash if present
+ if (route[0] === '/') {
+ route = this.route = route.substr(1);
+ }
+
+ escaped = escapeForRegex(route);
var regex = escaped.replace(/:([a-z_]+)(?=$|\/)/gi, function(match, id) {
identifiers[count++] = id;
@@ -97,7 +104,13 @@ Ember.Routable = Ember.Mixin.create({
var matcher = get(this, 'routeMatcher'),
hash = get(manager, 'stateMeta').get(this);
- return path + '/' + matcher.generate(hash);
+ var generated = matcher.generate(hash);
+
+ if (generated !== "") {
+ return path + '/' + matcher.generate(hash);
+ } else {
+ return path;
+ }
},
isRoutable: Ember.computed(function() {
@@ -121,6 +134,10 @@ Ember.Routable = Ember.Mixin.create({
var childStates = get(this, 'childStates'), match;
+ childStates = childStates.sort(function(a, b) {
+ return getPath(b, 'route.length') - getPath(a, 'route.length');
+ });
+
var state = childStates.find(function(state) {
var matcher = get(state, 'routeMatcher');
if (match = matcher.match(path)) { return true; } | true |
Other | emberjs | ember.js | f32a10660a5571875a59d46e7144a3de8a7a8c0b.json | Fix issue with "/" route alongside "/*" | packages/ember-states/tests/routable_test.js | @@ -208,23 +208,43 @@ module("Routing Serialization and Deserialization", {
location: locationMock,
start: Ember.State.create({
ready: function(manager, post) {
- manager.transitionTo('post', { post: post });
+ manager.transitionTo('post.show', { post: post });
+ },
+
+ showIndex: function(manager) {
+ manager.transitionTo('post.index');
},
post: Ember.State.create({
- route: "posts/:post_id",
+ route: '/posts',
+
+ index: Ember.State.create({
+ route: '/',
+
+ showPost: function(manager, post) {
+ manager.transitionTo('post.show', { post: post });
+ }
+ }),
+
+ show: Ember.State.create({
+ route: "/:post_id",
+
+ setupContext: function(manager, context) {
+ equal(context.post.id, 2, "should be the same value regardless of entry point");
+ },
- setupContext: function(manager, context) {
- equal(context.post.id, 2, "should be the same value regardless of entry point");
- },
+ deserialize: function(manager, params) {
+ return { post: Post.find(params['post_id']) };
+ },
- deserialize: function(manager, params) {
- return { post: Post.find(params['post_id']) };
- },
+ serialize: function(manager, hash) {
+ return { post_id: hash.post.id };
+ },
- serialize: function(manager, hash) {
- return { post_id: hash.post.id };
- }
+ showIndex: function(manager) {
+ manager.transitionTo('index');
+ }
+ })
})
})
});
@@ -237,10 +257,23 @@ test("should invoke the deserialize method on a state when it is entered via a U
stateManager.route('/posts/2');
});
-test("should invoke the serialize method on a state when it is entered programmatically", function() {
- expect(2);
+test("should invoke the serialize method on a state when it is entered programmatically (initially deep)", function() {
+ expect(3);
stateManager.send('ready', Post.find(2));
equal(setUrl, '/posts/2', "The post is serialized");
+
+ stateManager.send('showIndex');
+ equal(setUrl, '/posts');
+});
+
+test("should invoke the serialize method on a state when it is entered programmatically (initially shallow)", function() {
+ expect(3);
+
+ stateManager.send('showIndex');
+ equal(setUrl, '/posts', "The post is serialized");
+
+ stateManager.send('showPost', Post.find(2));
+ equal(setUrl, '/posts/2');
});
| true |
Other | emberjs | ember.js | 4d3091c95dc3c3df07aaf19d12f5f87f901f18bf.json | Remove stray references to IndexSet | packages/ember-runtime/lib/mixins/mutable_array.js | @@ -106,7 +106,7 @@ Ember.MutableArray = Ember.Mixin.create(Ember.Array, Ember.MutableEnumerable,
colors.removeAt(2, 2); => ["green", "blue"]
colors.removeAt(4, 2); => Error: Index out of range
- @param {Number|Ember.IndexSet} start index, start of range, or index set
+ @param {Number} start index, start of range
@param {Number} len length of passing range
@returns {Object} receiver
*/ | true |
Other | emberjs | ember.js | 4d3091c95dc3c3df07aaf19d12f5f87f901f18bf.json | Remove stray references to IndexSet | packages/ember-runtime/tests/suites/mutable_array/removeAt.js | @@ -126,5 +126,3 @@ suite.test("[A,B,C,D].removeAt(1,2) => [A,D] + notify", function() {
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once');
});
-
-suite.notest("[A,B,C,D].removeAt(IndexSet<0,2-3>) => [B] + notify"); | true |
Other | emberjs | ember.js | 23dc092684edaba57ad2eeb2c5a75f7a2b570c03.json | Correct Enumerable documentation | packages/ember-runtime/lib/mixins/enumerable.js | @@ -727,15 +727,13 @@ Ember.Enumerable = Ember.Mixin.create( /** @lends Ember.Enumerable */ {
optional start offset for the content change. For unordered
enumerables, you should always pass -1.
- @param {Enumerable} added
- optional enumerable containing items that were added to the set. For
- ordered enumerables, this should be an ordered array of items. If no
- items were added you can pass null.
-
- @param {Enumerable} removes
- optional enumerable containing items that were removed from the set.
- For ordered enumerables, this should be an ordered array of items. If
- no items were removed you can pass null.
+ @param {Ember.Enumerable|Number} removing
+ An enumerable of the objects to be removed or the number of items to
+ be removed.
+
+ @param {Ember.Enumerable|Numbe} adding
+ An enumerable of the objects to be added or the number of items to be
+ added.
@returns {Object} receiver
*/ | false |
Other | emberjs | ember.js | 5dde927641c9152c53624a3ffaaa99d5c1777c9f.json | Add explicit value field (for documentation later) | packages/ember-handlebars/lib/controls/text_field.js | @@ -18,9 +18,10 @@ Ember.TextField = Ember.View.extend(Ember.TextSupport,
/** @scope Ember.TextField.prototype */ {
classNames: ['ember-text-field'],
-
tagName: "input",
attributeBindings: ['type', 'value', 'size'],
+
+ value: '',
type: "text",
size: null
}); | false |
Other | emberjs | ember.js | dd1851eea9fc6979570ba761cd1931c3a1ee7e57.json | Add support for #each foo in bar
This implementation takes on some new technical
debt, mostly caused by existing technical debt.
Because this is a very bad thing, we plan to work
on refactoring and paying down as much of the
templateData technical debt as possible tomorrow. | packages/ember-handlebars/lib/helpers/collection.js | @@ -172,24 +172,19 @@ Ember.Handlebars.registerHelper('collection', function(path, options) {
}
if (inverse && inverse !== Handlebars.VM.noop) {
- var emptyViewClass = Ember.View;
-
- if (hash.emptyViewClass) {
- emptyViewClass = Ember.View.detect(hash.emptyViewClass) ?
- hash.emptyViewClass : getPath(this, hash.emptyViewClass, options);
- }
+ var emptyViewClass = get(collectionPrototype, 'emptyViewClass');
hash.emptyView = emptyViewClass.extend({
template: inverse,
tagName: itemHash.tagName
});
}
- if (hash.preserveContext) {
+ if (hash.eachHelper === 'each') {
itemHash._templateContext = Ember.computed(function() {
return get(this, 'content');
}).property('content');
- delete hash.preserveContext;
+ delete hash.eachHelper;
}
hash.itemViewClass = Ember.Handlebars.ViewHelper.viewClassFromHTMLOptions(itemViewClass, { data: data, hash: itemHash }, this); | true |
Other | emberjs | ember.js | dd1851eea9fc6979570ba761cd1931c3a1ee7e57.json | Add support for #each foo in bar
This implementation takes on some new technical
debt, mostly caused by existing technical debt.
Because this is a very bad thing, we plan to work
on refactoring and paying down as much of the
templateData technical debt as possible tomorrow. | packages/ember-handlebars/lib/helpers/each.js | @@ -2,17 +2,57 @@ require("ember-handlebars/ext");
require("ember-views/views/collection_view");
require("ember-handlebars/views/metamorph_view");
+var get = Ember.get, set = Ember.set;
+
Ember.Handlebars.EachView = Ember.CollectionView.extend(Ember._Metamorph, {
- itemViewClass: Ember._MetamorphView
+ itemViewClass: Ember._MetamorphView,
+ emptyViewClass: Ember._MetamorphView,
+
+ createChildView: function(view, attrs) {
+ view = this._super(view, attrs);
+
+ // At the moment, if a container view subclass wants
+ // to insert keywords, it is responsible for cloning
+ // the keywords hash. This will be fixed momentarily.
+ var keyword = get(this, 'keyword');
+
+ if (keyword) {
+ var data = get(view, 'templateData');
+
+ data = Ember.copy(data);
+ data.keywords = view.cloneKeywords();
+ set(view, 'templateData', data);
+
+ var content = get(view, 'content');
+
+ // In this case, we do not bind, because the `content` of
+ // a #each item cannot change.
+ data.keywords[keyword] = content;
+ }
+
+ return view;
+ }
});
Ember.Handlebars.registerHelper('each', function(path, options) {
- options.hash.contentBinding = path;
- options.hash.preserveContext = true;
+ if (arguments.length === 4) {
+ Ember.assert("If you pass more than one argument to the each helper, it must be in the form #each foo in bar", arguments[1] === "in");
+
+ var keywordName = arguments[0];
+
+ options = arguments[3];
+ path = arguments[2];
+ options.hash.keyword = keywordName;
+ } else {
+ options.hash.eachHelper = 'each';
+ }
+
+ Ember.assert("You must pass a block to the each helper", options.fn && options.fn !== Handlebars.VM.noop);
+
+ options.hash.contentBinding = path;
// Set up emptyView as a metamorph with no tag
- options.hash.itemTagName = '';
- options.hash.emptyViewClass = Ember._MetamorphView;
+ //options.hash.emptyViewClass = Ember._MetamorphView;
return Ember.Handlebars.helpers.collection.call(this, 'Ember.Handlebars.EachView', options);
}); | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.