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 | 80be0ac7c8ab46f6ed09d27ca87bf6877c20229b.json | Remove duplicate `props_helper` module
Utilize the more full-fledged `ember-runtime/tests/props_helper` module
instead. | packages/ember-runtime/tests/ext/function_test.js | @@ -1,4 +1,4 @@
-import {testBoth} from 'ember-runtime/tests/props_helper';
+import { testBoth } from "ember-metal/tests/props_helper";
QUnit.module('Function.prototype.observes() helper');
| true |
Other | emberjs | ember.js | 80be0ac7c8ab46f6ed09d27ca87bf6877c20229b.json | Remove duplicate `props_helper` module
Utilize the more full-fledged `ember-runtime/tests/props_helper` module
instead. | packages/ember-runtime/tests/mixins/array_test.js | @@ -4,9 +4,9 @@ import { set } from "ember-metal/property_set";
import { addObserver } from "ember-metal/observer";
import { observer as emberObserver } from "ember-metal/mixin";
import { computed } from "ember-metal/computed";
-import { testBoth } from 'ember-runtime/tests/props_helper';
-import { ArrayTests } from 'ember-runtime/tests/suites/array';
-import EmberObject from 'ember-runtime/system/object';
+import { testBoth } from "ember-metal/tests/props_helper";
+import { ArrayTests } from "ember-runtime/tests/suites/array";
+import EmberObject from "ember-runtime/system/object";
import EmberArray from "ember-runtime/mixins/array";
/* | true |
Other | emberjs | ember.js | 80be0ac7c8ab46f6ed09d27ca87bf6877c20229b.json | Remove duplicate `props_helper` module
Utilize the more full-fledged `ember-runtime/tests/props_helper` module
instead. | packages/ember-runtime/tests/mixins/observable_test.js | @@ -1,7 +1,7 @@
import { computed } from "ember-metal/computed";
import { addObserver } from "ember-metal/observer";
-import EmberObject from 'ember-runtime/system/object';
-import { testBoth } from 'ember-runtime/tests/props_helper';
+import EmberObject from "ember-runtime/system/object";
+import { testBoth } from "ember-metal/tests/props_helper";
QUnit.module('mixins/observable');
| true |
Other | emberjs | ember.js | 80be0ac7c8ab46f6ed09d27ca87bf6877c20229b.json | Remove duplicate `props_helper` module
Utilize the more full-fledged `ember-runtime/tests/props_helper` module
instead. | packages/ember-runtime/tests/props_helper.js | @@ -1,53 +0,0 @@
-import Ember from 'ember-metal/core';
-import {get as getFromEmberMetal, getWithDefault as getWithDefaultFromEmberMetal} from 'ember-metal/property_get';
-import {set as setFromEmberMetal} from 'ember-metal/property_set';
-
-// used by unit tests to test both accessor mode and non-accessor mode
-var testBoth = function(testname, callback) {
-
- function emberget(x,y) { return getFromEmberMetal(x,y); }
- function emberset(x,y,z) { return setFromEmberMetal(x,y,z); }
- function aget(x,y) { return x[y]; }
- function aset(x,y,z) { return (x[y] = z); }
-
- test(testname+' using getFromEmberMetal()/Ember.set()', function() {
- callback(emberget, emberset);
- });
-
- test(testname+' using accessors', function() {
- if (Ember.USES_ACCESSORS) callback(aget, aset);
- else ok('SKIPPING ACCESSORS');
- });
-};
-
-var testWithDefault = function(testname, callback) {
- function emberget(x,y) { return getFromEmberMetal(x,y); }
- function embergetwithdefault(x,y,z) { return getWithDefaultFromEmberMetal(x,y,z); }
- function getwithdefault(x,y,z) { return x.getWithDefault(y,z); }
- function emberset(x,y,z) { return setFromEmberMetal(x,y,z); }
- function aget(x,y) { return x[y]; }
- function aset(x,y,z) { return (x[y] = z); }
-
- test(testname+' using obj.get()', function() {
- callback(emberget, emberset);
- });
-
- test(testname+' using obj.getWithDefault()', function() {
- callback(getwithdefault, emberset);
- });
-
- test(testname+' using getFromEmberMetal()', function() {
- callback(emberget, emberset);
- });
-
- test(testname+' using Ember.getWithDefault()', function() {
- callback(embergetwithdefault, emberset);
- });
-
- test(testname+' using accessors', function() {
- if (Ember.USES_ACCESSORS) callback(aget, aset);
- else ok('SKIPPING ACCESSORS');
- });
-};
-
-export {testWithDefault, testBoth}; | true |
Other | emberjs | ember.js | 80be0ac7c8ab46f6ed09d27ca87bf6877c20229b.json | Remove duplicate `props_helper` module
Utilize the more full-fledged `ember-runtime/tests/props_helper` module
instead. | packages/ember-runtime/tests/system/object/computed_test.js | @@ -1,7 +1,7 @@
-import {computed} from "ember-metal/computed";
-import {get as emberGet} from "ember-metal/property_get";
-import {observer} from "ember-metal/mixin";
-import { testWithDefault } from 'ember-runtime/tests/props_helper';
+import { computed } from "ember-metal/computed";
+import { get as emberGet } from "ember-metal/property_get";
+import { observer } from "ember-metal/mixin";
+import { testWithDefault } from "ember-metal/tests/props_helper";
import EmberObject from "ember-runtime/system/object";
function K() { return this; } | true |
Other | emberjs | ember.js | 80be0ac7c8ab46f6ed09d27ca87bf6877c20229b.json | Remove duplicate `props_helper` module
Utilize the more full-fledged `ember-runtime/tests/props_helper` module
instead. | packages/ember-runtime/tests/system/object/destroy_test.js | @@ -8,8 +8,8 @@ import {
endPropertyChanges
} from "ember-metal/property_events";
import objectKeys from "ember-metal/keys";
-import { testBoth } from 'ember-runtime/tests/props_helper';
-import EmberObject from 'ember-runtime/system/object';
+import { testBoth } from "ember-metal/tests/props_helper";
+import EmberObject from "ember-runtime/system/object";
QUnit.module('ember-runtime/system/object/destroy_test');
| true |
Other | emberjs | ember.js | 80be0ac7c8ab46f6ed09d27ca87bf6877c20229b.json | Remove duplicate `props_helper` module
Utilize the more full-fledged `ember-runtime/tests/props_helper` module
instead. | packages/ember-runtime/tests/system/object/observer_test.js | @@ -1,7 +1,7 @@
import Ember from "ember-metal/core";
-import {observer} from "ember-metal/mixin";
+import { observer } from "ember-metal/mixin";
import run from "ember-metal/run_loop";
-import {testBoth} from 'ember-runtime/tests/props_helper';
+import { testBoth } from "ember-metal/tests/props_helper";
import EmberObject from "ember-runtime/system/object";
QUnit.module('EmberObject observer'); | true |
Other | emberjs | ember.js | 80be0ac7c8ab46f6ed09d27ca87bf6877c20229b.json | Remove duplicate `props_helper` module
Utilize the more full-fledged `ember-runtime/tests/props_helper` module
instead. | packages/ember-runtime/tests/system/object_proxy_test.js | @@ -1,7 +1,7 @@
-import {addObserver, removeObserver} from "ember-metal/observer";
-import {computed} from "ember-metal/computed";
-import {isWatching} from "ember-metal/watching";
-import {testBoth} from 'ember-runtime/tests/props_helper';
+import { addObserver, removeObserver } from "ember-metal/observer";
+import { computed } from "ember-metal/computed";
+import { isWatching } from "ember-metal/watching";
+import { testBoth } from "ember-metal/tests/props_helper";
import ObjectProxy from "ember-runtime/system/object_proxy";
QUnit.module("ObjectProxy"); | true |
Other | emberjs | ember.js | b2d86a3cfcca0d8b0974169fede63ed872b92fde.json | Include number of expected assertions
Without specifying the number of expected assertions, the callback might
never be evaluated, and the test might pass, acting as a false positive. | packages/ember-metal/tests/run_loop/run_bind_test.js | @@ -19,6 +19,7 @@ test('Ember.run.bind builds a run-loop wrapped callback handler', function() {
});
test('Ember.run.bind keeps the async callback arguments', function() {
+ expect(4);
var asyncCallback = function(increment, increment2, increment3) {
ok(run.currentRunLoop, 'expected a run-loop'); | false |
Other | emberjs | ember.js | a7e40622157fad6822d5f734c6325b99de811211.json | Remove Duplicate Test
`should be able to be inserted...` occurs twice in the test file. | packages/ember-routing-htmlbars/tests/helpers/link-to_test.js | @@ -28,17 +28,6 @@ QUnit.module("Handlebars {{link-to}} helper", {
});
-test("should be able to be inserted in DOM when the router is not present", function() {
- var template = "{{#link-to 'index'}}Go to Index{{/link-to}}";
- view = EmberView.create({
- template: compile(template)
- });
-
- appendView(view);
-
- equal(view.$().text(), 'Go to Index');
-});
-
test("should be able to be inserted in DOM when the router is not present", function() {
var template = "{{#link-to 'index'}}Go to Index{{/link-to}}";
view = EmberView.create({ | false |
Other | emberjs | ember.js | b2617c0284e335ee2718b28b24e0310521ef5c91.json | Improve test names | packages/ember-htmlbars/tests/attr_nodes/boolean_test.js | @@ -19,7 +19,7 @@ QUnit.module("ember-htmlbars: boolean attribute", {
}
});
-test("true property is output", function() {
+test("disabled property can be set true", function() {
view = EmberView.create({
context: {isDisabled: true},
template: compile("<input disabled={{isDisabled}}>")
@@ -32,7 +32,7 @@ test("true property is output", function() {
'boolean property is set true');
});
-test("blank string property is output", function() {
+test("disabled property can be set false with a blank string", function() {
view = EmberView.create({
context: {isDisabled: ''},
template: compile("<input disabled={{isDisabled}}>")
@@ -45,7 +45,7 @@ test("blank string property is output", function() {
'boolean property is set true');
});
-test("false property is removed", function() {
+test("disabled property can be set false", function() {
view = EmberView.create({
context: {isDisabled: false},
template: compile("<input disabled={{isDisabled}}>")
@@ -58,7 +58,7 @@ test("false property is removed", function() {
'boolean property is set false');
});
-test("string property is truthy", function() {
+test("disabled property can be set true with a string", function() {
view = EmberView.create({
context: {isDisabled: "oh, no a string"},
template: compile("<input disabled={{isDisabled}}>")
@@ -71,7 +71,7 @@ test("string property is truthy", function() {
'boolean property is set false');
});
-test("string liternal is truthy", function() {
+test("disabled attribute turns a value to a string", function() {
view = EmberView.create({
context: {isDisabled: false},
template: compile("<input disabled='{{isDisabled}}'>")
@@ -84,7 +84,7 @@ test("string liternal is truthy", function() {
'boolean property is set true');
});
-test("blank string is truthy", function() {
+test("disabled attribute preserves a blank string value", function() {
view = EmberView.create({
context: {isDisabled: ''},
template: compile("<input disabled='{{isDisabled}}'>") | true |
Other | emberjs | ember.js | b2617c0284e335ee2718b28b24e0310521ef5c91.json | Improve test names | packages/ember-htmlbars/tests/attr_nodes/class_test.js | @@ -19,7 +19,7 @@ QUnit.module("ember-htmlbars: class attribute", {
}
});
-test("property can set multiple classes", function() {
+test("class property can contain multiple classes", function() {
view = EmberView.create({
context: {classes: 'large blue'},
template: compile("<div class={{classes}}></div>")
@@ -32,7 +32,7 @@ test("property can set multiple classes", function() {
ok(view.$('.blue')[0], 'second class found');
});
-test("property can set remove class", function() {
+test("class property is removed when updated with a null value", function() {
view = EmberView.create({
context: {class: 'large'},
template: compile("<div class={{class}}></div>")
@@ -48,7 +48,7 @@ test("property can set remove class", function() {
"attribute is removed");
});
-test("attribute can use multiple props", function() {
+test("class attribute concats bound values", function() {
view = EmberView.create({
context: {size: 'large', color: 'blue'},
template: compile("<div class='{{size}} {{color}} round'></div>")
@@ -60,7 +60,7 @@ test("attribute can use multiple props", function() {
ok(view.$('.round')[0], 'third class found');
});
-test("attribute can use multiple props with subxpression", function() {
+test("class attribute accepts nested helpers, and updates", function() {
view = EmberView.create({
context: {
size: 'large',
@@ -84,7 +84,7 @@ test("attribute can use multiple props with subxpression", function() {
ok(view.$('.round')[0], 'third class found after change');
});
-test("multiple classed can yield from a single id", function() {
+test("class attribute can accept multipe classes from a single value, and update", function() {
view = EmberView.create({
context: {
size: 'large small' | true |
Other | emberjs | ember.js | b8aef4dce60e65c8044f4dae5f13e4b62b72efa1.json | Allow multiple classes per stream | packages/ember-htmlbars/lib/attr_nodes/quoted_class.js | @@ -62,6 +62,20 @@ QuotedClassAttrNode.prototype.scheduledRenderIfNeeded = function scheduledRender
}
};
+function pushString(list, string) {
+ var parts = string.split(' ');
+ var length = parts.length;
+ if (length === 1 && parts[0].length > 0) {
+ list.push(parts[0]);
+ } else {
+ for (var i=0;i<length;i++) {
+ if (parts[i].length > 0) {
+ list.push(parts[i]);
+ }
+ }
+ }
+}
+
QuotedClassAttrNode.prototype.render = function render(){
var removeList = [];
@@ -76,10 +90,10 @@ QuotedClassAttrNode.prototype.render = function render(){
if (this.classNodes[i].isDirty) {
this.classNodes[i].isDirty = false;
if (this.classNodes[i].lastValue) {
- removeList.push(this.classNodes[i].lastValue);
+ pushString(removeList, this.classNodes[i].lastValue);
}
if (this.classNodes[i].currentValue) {
- addList.push(this.classNodes[i].currentValue);
+ pushString(addList, this.classNodes[i].currentValue);
}
}
} | true |
Other | emberjs | ember.js | b8aef4dce60e65c8044f4dae5f13e4b62b72efa1.json | Allow multiple classes per stream | packages/ember-htmlbars/tests/attr_nodes/class_test.js | @@ -84,4 +84,23 @@ test("attribute can use multiple props with subxpression", function() {
ok(view.$('.round')[0], 'third class found after change');
});
+test("multiple classed can yield from a single id", function() {
+ view = EmberView.create({
+ context: {
+ size: 'large small'
+ },
+ template: compile("<div class='{{size}}'></div>")
+ });
+ appendView(view);
+
+ ok(view.$('.large')[0], 'first class found');
+ ok(view.$('.small')[0], 'second class found');
+
+ run(view, view.set, 'context.size', 'medium');
+
+ ok(view.$('.large').length === 0, 'old class not found');
+ ok(view.$('.small').length === 0, 'old class not found');
+ ok(view.$('.medium')[0], 'new class found');
+});
+
} | true |
Other | emberjs | ember.js | 1122e66b56b3aa6ef7cca57eaefc0cd1a6a63ff5.json | Remove some closures | packages/ember-htmlbars/lib/attr_nodes/quoted_class.js | @@ -11,10 +11,7 @@ function ClassNode(stream, renderable) {
this.lastValue = null;
this.currentValue = null;
this.isDirty = false;
- var node = this;
- stream.subscribe(function(){
- node.update();
- });
+ stream.subscribe(this.update, this);
this.update();
}
@@ -55,12 +52,14 @@ function QuotedClassAttrNode(element, attrName, attrValue, dom) {
QuotedClassAttrNode.prototype.renderIfNeeded = function renderIfNeeded(){
this.isDirty = true;
- run.schedule('render', this, function() {
- if (this.isDirty) {
- this.isDirty = false;
- this.render();
- }
- });
+ run.schedule('render', this, this.scheduledRenderIfNeeded);
+};
+
+QuotedClassAttrNode.prototype.scheduledRenderIfNeeded = function scheduledRenderIfNeeded(){
+ if (this.isDirty) {
+ this.isDirty = false;
+ this.render();
+ }
};
QuotedClassAttrNode.prototype.render = function render(){ | true |
Other | emberjs | ember.js | 1122e66b56b3aa6ef7cca57eaefc0cd1a6a63ff5.json | Remove some closures | packages/ember-htmlbars/lib/attr_nodes/simple.js | @@ -19,10 +19,7 @@ SimpleAttrNode.prototype.init = function init(element, attrName, simpleAttrValue
this.currentValue = null;
if (this.attrValue.isStream) {
- var attrNode = this;
- this.attrValue.subscribe(function(){
- attrNode.renderIfNeeded();
- });
+ this.attrValue.subscribe(this.renderIfNeeded, this);
this.renderIfNeeded();
} else {
this.currentValue = simpleAttrValue;
@@ -32,17 +29,19 @@ SimpleAttrNode.prototype.init = function init(element, attrName, simpleAttrValue
SimpleAttrNode.prototype.renderIfNeeded = function renderIfNeeded(){
this.isDirty = true;
- run.schedule('render', this, function() {
- if (this.isDirty) {
- this.isDirty = false;
- var value = this.attrValue.value();
- if (value !== this.currentValue) {
- this.lastValue = this.currentValue;
- this.currentValue = value;
- this.render();
- }
+ run.schedule('render', this, this.scheduledRenderIfNeeded);
+};
+
+SimpleAttrNode.prototype.scheduledRenderIfNeeded = function scheduledRenderIfNeeded(){
+ if (this.isDirty) {
+ this.isDirty = false;
+ var value = this.attrValue.value();
+ if (value !== this.currentValue) {
+ this.lastValue = this.currentValue;
+ this.currentValue = value;
+ this.render();
}
- });
+ }
};
SimpleAttrNode.prototype.render = function render(){ | true |
Other | emberjs | ember.js | 1122e66b56b3aa6ef7cca57eaefc0cd1a6a63ff5.json | Remove some closures | packages/ember-htmlbars/lib/helpers/bind-attr.js | @@ -226,9 +226,7 @@ function streamifyClassBindings(view, classBindingsString) {
var value = lazyValue.value();
return classStringForParsedPath(_parsedPath, value);
});
- lazyValue.subscribe(function(){
- classNameBound.notify();
- });
+ lazyValue.subscribe(classNameBound.notify, classNameBound);
streamified.push(classNameBound);
})(); // jshint ignore:line
} | true |
Other | emberjs | ember.js | a36af0579635b1255074dabc690eb3f0b48da238.json | Add a feature flag for attribute syntax | FEATURES.md | @@ -94,3 +94,10 @@ for a detailed explanation.
Added in [#9718](https://github.com/emberjs/ember.js/pull/9718).
+* `ember-htmlbars-attribute-syntax`
+
+ Adds the `class="{{color}}"` syntax to Ember HTMLBars templates.
+ Works with arbitrary attributes and properties.
+
+ Added in [#9721](https://github.com/emberjs/ember.js/pull/9721;w).
+ | true |
Other | emberjs | ember.js | a36af0579635b1255074dabc690eb3f0b48da238.json | Add a feature flag for attribute syntax | features.json | @@ -19,7 +19,8 @@
"ember-htmlbars": null,
"ember-htmlbars-block-params": null,
"ember-htmlbars-component-generation": null,
- "ember-htmlbars-inline-if-helper": null
+ "ember-htmlbars-inline-if-helper": null,
+ "ember-htmlbars-attribute-syntax": null
},
"debugStatements": [
"Ember.warn", | true |
Other | emberjs | ember.js | a36af0579635b1255074dabc690eb3f0b48da238.json | Add a feature flag for attribute syntax | packages/ember-htmlbars/lib/hooks/attribute.js | @@ -6,6 +6,21 @@
import attrNodeTypeFor from "ember-htmlbars/attr_nodes";
export default function attribute(element, attrName, quoted, view, attrValue, options, env) {
- var AttrNode = attrNodeTypeFor(attrName, element, quoted);
- new AttrNode(element, attrName, attrValue, env.dom);
+ var isAllowed = true;
+
+ if (!Ember.FEATURES.isEnabled('ember-htmlbars-attribute-syntax')) {
+ for (var i=0, l=attrValue.length; i<l; i++) {
+ if (attrValue[i].isStream) {
+ isAllowed = false;
+ break;
+ }
+ }
+ }
+
+ if (isAllowed) {
+ var AttrNode = attrNodeTypeFor(attrName, element, quoted);
+ new AttrNode(element, attrName, attrValue, env.dom);
+ } else {
+ throw new Error('Bound attributes are not yet supported in Ember.js');
+ }
} | true |
Other | emberjs | ember.js | a36af0579635b1255074dabc690eb3f0b48da238.json | Add a feature flag for attribute syntax | packages/ember-htmlbars/tests/attr_nodes/boolean_test.js | @@ -9,7 +9,7 @@ function appendView(view) {
run(function() { view.appendTo('#qunit-fixture'); });
}
-if (Ember.FEATURES.isEnabled('ember-htmlbars')) {
+if (Ember.FEATURES.isEnabled('ember-htmlbars-attribute-syntax')) {
QUnit.module("ember-htmlbars: boolean attribute", {
teardown: function(){ | true |
Other | emberjs | ember.js | a36af0579635b1255074dabc690eb3f0b48da238.json | Add a feature flag for attribute syntax | packages/ember-htmlbars/tests/attr_nodes/class_test.js | @@ -9,7 +9,7 @@ function appendView(view) {
run(function() { view.appendTo('#qunit-fixture'); });
}
-if (Ember.FEATURES.isEnabled('ember-htmlbars')) {
+if (Ember.FEATURES.isEnabled('ember-htmlbars-attribute-syntax')) {
QUnit.module("ember-htmlbars: class attribute", {
teardown: function(){ | true |
Other | emberjs | ember.js | a36af0579635b1255074dabc690eb3f0b48da238.json | Add a feature flag for attribute syntax | packages/ember-htmlbars/tests/attr_nodes/data_test.js | @@ -9,7 +9,8 @@ import { appendView, destroyView } from "ember-views/tests/view_helpers";
var view, originalSetAttribute, setAttributeCalls;
var dom = defaultEnv.dom;
-if (Ember.FEATURES.isEnabled('ember-htmlbars')) {
+if (Ember.FEATURES.isEnabled('ember-htmlbars-attribute-syntax')) {
+
QUnit.module("ember-htmlbars: data attribute", {
teardown: function(){
destroyView(view); | true |
Other | emberjs | ember.js | a36af0579635b1255074dabc690eb3f0b48da238.json | Add a feature flag for attribute syntax | packages/ember-htmlbars/tests/attr_nodes/href_test.js | @@ -9,7 +9,7 @@ function appendView(view) {
run(function() { view.appendTo('#qunit-fixture'); });
}
-if (Ember.FEATURES.isEnabled('ember-htmlbars')) {
+if (Ember.FEATURES.isEnabled('ember-htmlbars-attribute-syntax')) {
QUnit.module("ember-htmlbars: href attribute", {
teardown: function(){ | true |
Other | emberjs | ember.js | a36af0579635b1255074dabc690eb3f0b48da238.json | Add a feature flag for attribute syntax | packages/ember-htmlbars/tests/attr_nodes/nonmatching_reflection_test.js | @@ -9,7 +9,7 @@ function appendView(view) {
run(function() { view.appendTo('#qunit-fixture'); });
}
-if (Ember.FEATURES.isEnabled('ember-htmlbars')) {
+if (Ember.FEATURES.isEnabled('ember-htmlbars-attribute-syntax')) {
QUnit.module("ember-htmlbars: nonmatching reflection", {
teardown: function(){ | true |
Other | emberjs | ember.js | a36af0579635b1255074dabc690eb3f0b48da238.json | Add a feature flag for attribute syntax | packages/ember-htmlbars/tests/attr_nodes/svg_test.js | @@ -9,7 +9,7 @@ function appendView(view) {
run(function() { view.appendTo('#qunit-fixture'); });
}
-if (Ember.FEATURES.isEnabled('ember-htmlbars')) {
+if (Ember.FEATURES.isEnabled('ember-htmlbars-attribute-syntax')) {
QUnit.module("ember-htmlbars: svg attribute", {
teardown: function(){ | true |
Other | emberjs | ember.js | a36af0579635b1255074dabc690eb3f0b48da238.json | Add a feature flag for attribute syntax | packages/ember-htmlbars/tests/attr_nodes/value_test.js | @@ -9,7 +9,7 @@ function appendView(view) {
run(function() { view.appendTo('#qunit-fixture'); });
}
-if (Ember.FEATURES.isEnabled('ember-htmlbars')) {
+if (Ember.FEATURES.isEnabled('ember-htmlbars-attribute-syntax')) {
QUnit.module("ember-htmlbars: value attribute", {
teardown: function(){ | true |
Other | emberjs | ember.js | a87de7ac38a48b3da362fcf5b2dd64daf2a3c8aa.json | Port attrs and classes via bind-attr to AttrNode | packages/ember-htmlbars/lib/attr_nodes/legacy_bind.js | @@ -0,0 +1,53 @@
+/**
+@module ember
+@submodule ember-htmlbars
+*/
+
+import { fmt } from "ember-runtime/system/string";
+import { typeOf } from "ember-metal/utils";
+import isNone from 'ember-metal/is_none';
+import SimpleAttrNode from "./simple";
+import { create as o_create } from "ember-metal/platform";
+
+function LegacyBindAttrNode(element, attrName, attrValue, dom) {
+ this.init(element, attrName, attrValue, dom);
+}
+
+LegacyBindAttrNode.prototype = o_create(SimpleAttrNode.prototype);
+
+LegacyBindAttrNode.prototype.super$init = SimpleAttrNode.prototype.init;
+
+LegacyBindAttrNode.prototype.render = function init() {
+ var name = this.attrName;
+ var value = this.currentValue;
+ var type = typeOf(value);
+
+ Ember.assert(fmt("Attributes must be numbers, strings or booleans, not %@", [value]),
+ value === null || value === undefined || type === 'number' || type === 'string' || type === 'boolean');
+
+ // if this changes, also change the logic in ember-handlebars/lib/helpers/binding.js
+ if (name !== 'value' && (type === 'string' || (type === 'number' && !isNaN(value)))) {
+ this.dom.setAttribute(this.element, name, value);
+ } else if (name === 'value' || type === 'boolean') {
+ if (isNone(value) || value === false) {
+ // `null`, `undefined` or `false` should remove attribute
+ this.dom.removeAttribute(this.element, name);
+ // In IE8 `prop` couldn't remove attribute when name is `required`.
+ if (name === 'required') {
+ this.dom.setProperty(this.element, name, null);
+ } else {
+ this.dom.setProperty(this.element, name, '');
+ }
+ } else {
+ // value should always be properties
+ this.dom.setProperty(this.element, name, value);
+ }
+ } else if (!value) {
+ if (this.lastValue !== null) {
+ this.dom.removeAttribute(this.element, name);
+ }
+ }
+};
+
+export default LegacyBindAttrNode;
+ | true |
Other | emberjs | ember.js | a87de7ac38a48b3da362fcf5b2dd64daf2a3c8aa.json | Port attrs and classes via bind-attr to AttrNode | packages/ember-htmlbars/lib/helpers/bind-attr.js | @@ -6,12 +6,12 @@
import Ember from "ember-metal/core"; // Ember.assert
import { fmt } from "ember-runtime/system/string";
-import { typeOf } from "ember-metal/utils";
-import { forEach } from "ember-metal/array";
+import QuotedClassAttrNode from "ember-htmlbars/attr_nodes/quoted_class";
+import LegacyBindAttrNode from "ember-htmlbars/attr_nodes/legacy_bind";
import View from "ember-views/views/view";
+import Stream from "ember-metal/streams/stream";
import keys from "ember-metal/keys";
import helpers from "ember-htmlbars/helpers";
-import jQuery from "ember-views/system/jquery";
/**
`bind-attr` allows you to create a binding between DOM element attributes and
@@ -137,7 +137,7 @@ import jQuery from "ember-views/system/jquery";
@return {String} HTML string
*/
function bindAttrHelper(params, hash, options, env) {
- var element = jQuery(options.element);
+ var element = options.element;
Ember.assert("You must specify at least one hash argument to bind-attr", !!keys(hash).length);
@@ -146,55 +146,29 @@ function bindAttrHelper(params, hash, options, env) {
// Handle classes differently, as we can bind multiple classes
var classBindings = hash['class'];
if (classBindings != null) {
-
- var classResults = bindClasses(element, classBindings, view, options);
-
- View.applyAttributeBindings(element, 'class', classResults.join(' '));
-
+ var attrValue = streamifyClassBindings(view, classBindings);
+ new QuotedClassAttrNode(element, 'class', attrValue, env.dom);
delete hash['class'];
}
var attrKeys = keys(hash);
- // For each attribute passed, create an observer and emit the
- // current value of the property as an attribute.
- forEach.call(attrKeys, function(attr) {
- var path = hash[attr];
-
- var lazyValue;
-
+ var attr, path, lazyValue;
+ for (var i=0, l=attrKeys.length;i<l;i++) {
+ attr = attrKeys[i];
+ path = hash[attr];
if (path.isStream) {
lazyValue = path;
} else {
- Ember.assert(fmt("You must provide an expression as the value of bound attribute." +
- " You specified: %@=%@", [attr, path]), typeof path === 'string' || path.isStream);
-
+ Ember.assert(
+ fmt("You must provide an expression as the value of bound attribute." +
+ " You specified: %@=%@", [attr, path]),
+ typeof path === 'string'
+ );
lazyValue = view.getStream(path);
}
-
- var value = lazyValue.value();
- var type = typeOf(value);
-
- Ember.assert(fmt("Attributes must be numbers, strings or booleans, not %@", [value]),
- value === null || value === undefined || type === 'number' || type === 'string' || type === 'boolean');
-
-
- lazyValue.subscribe(view._wrapAsScheduled(function applyAttributeBindings() {
- var result = lazyValue.value();
-
- 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');
-
- View.applyAttributeBindings(element, attr, result);
- }));
-
- if (value && type === 'boolean') {
- value = attr;
- }
-
- View.applyAttributeBindings(element, attr, value);
- }, this);
+ new LegacyBindAttrNode(element, attr, lazyValue, env.dom);
+ }
}
/**
@@ -234,65 +208,33 @@ function bindAttrHelperDeprecated() {
element to update
@return {Array} An array of class names to add
*/
-function bindClasses(element, classBindings, view, options) {
- var ret = [];
- var newClass, value;
-
- // For each property passed, loop through and setup
- // an observer.
- forEach.call(classBindings.split(' '), function(binding) {
-
- // Variable in which the old class value is saved. The observer function
- // closes over this variable, so it knows which string to remove when
- // the property changes.
- var oldClass;
- var parsedPath = View._parsePropertyPath(binding);
- var path = parsedPath.path;
- var initialValue;
-
- if (path === '') {
- initialValue = true;
- } else {
- var lazyValue = view.getStream(path);
- initialValue = lazyValue.value();
-
- // Set up an observer on the context. If the property changes, toggle the
- // class name.
- lazyValue.subscribe(view._wrapAsScheduled(function applyClassNameBindings() {
- // Get the current value of the property
- var value = lazyValue.value();
- newClass = classStringForParsedPath(parsedPath, value);
-
- // If we had previously added a class to the element, remove it.
- if (oldClass) {
- element.removeClass(oldClass);
- }
-
- // If necessary, add a new class. Make sure we keep track of it so
- // it can be removed in the future.
- if (newClass) {
- element.addClass(newClass);
- oldClass = newClass;
- } else {
- oldClass = null;
- }
- }));
- }
-
- // We've already setup the observer; now we just need to figure out the
- // correct behavior right now on the first pass through.
- value = classStringForParsedPath(parsedPath, initialValue);
+function streamifyClassBindings(view, classBindingsString) {
+ var classBindings = classBindingsString.split(' ');
+ var streamified = [];
- if (value) {
- ret.push(value);
+ var parsedPath;
+ for (var i=0, l=classBindings.length;i<l;i++) {
+ parsedPath = View._parsePropertyPath(classBindings[i]);
- // Make sure we save the current value so that it can be removed if the
- // observer fires.
- oldClass = value;
+ if (parsedPath.path === '') {
+ streamified.push(classStringForParsedPath(parsedPath, true));
+ } else {
+ (function(){
+ var lazyValue = view.getStream(parsedPath.path);
+ var _parsedPath = parsedPath;
+ var classNameBound = new Stream(function(){
+ var value = lazyValue.value();
+ return classStringForParsedPath(_parsedPath, value);
+ });
+ lazyValue.subscribe(function(){
+ classNameBound.notify();
+ });
+ streamified.push(classNameBound);
+ })(); // jshint ignore:line
}
- });
-
- return ret;
+ }
+
+ return streamified;
}
function classStringForParsedPath(parsedPath, value) {
@@ -303,6 +245,5 @@ export default bindAttrHelper;
export {
bindAttrHelper,
- bindAttrHelperDeprecated,
- bindClasses
+ bindAttrHelperDeprecated
}; | true |
Other | emberjs | ember.js | a87de7ac38a48b3da362fcf5b2dd64daf2a3c8aa.json | Port attrs and classes via bind-attr to AttrNode | packages/ember-htmlbars/tests/helpers/bind_attr_test.js | @@ -329,11 +329,12 @@ test("should not allow XSS injection via {{bind-attr}} with class", function() {
foo: '" onmouseover="alert(\'I am in your classes hacking your app\');'
});
- appendView(view);
+ try {
+ appendView(view);
+ } catch (e) {
+ }
equal(view.$('img').attr('onmouseover'), undefined);
- // If the whole string is here, then it means we got properly escaped
- equal(view.$('img').attr('class'), '" onmouseover="alert(\'I am in your classes hacking your app\');');
});
test("should be able to bind class attribute using ternary operator in {{bind-attr}}", function() { | true |
Other | emberjs | ember.js | a87de7ac38a48b3da362fcf5b2dd64daf2a3c8aa.json | Port attrs and classes via bind-attr to AttrNode | packages/ember-views/lib/views/view.js | @@ -2273,6 +2273,7 @@ View.views = {};
// method.
View.childViewsProperty = childViewsProperty;
+// Used by Handlebars helpers, view element attributes
View.applyAttributeBindings = function(elem, name, value) {
var type = typeOf(value);
| true |
Other | emberjs | ember.js | 734b551f2b8407420c2a2e3497ddd9df71007d4a.json | Remove types in HTMLBars helpers | package.json | @@ -42,7 +42,7 @@
"git-repo-version": "0.0.1",
"glob": "~3.2.8",
"handlebars": "^2.0",
- "htmlbars": "0.1.12",
+ "htmlbars": "0.1.13",
"ncp": "~0.5.1",
"rimraf": "~2.2.8",
"rsvp": "~3.0.6" | true |
Other | emberjs | ember.js | 734b551f2b8407420c2a2e3497ddd9df71007d4a.json | Remove types in HTMLBars helpers | packages/ember-htmlbars/lib/helpers/binding.js | @@ -97,7 +97,7 @@ function bindHelper(params, hash, options, env) {
var property = params[0];
- if (options.paramTypes[0] === 'string') {
+ if (typeof property === 'string') {
property = this.getStream(property);
}
| true |
Other | emberjs | ember.js | 734b551f2b8407420c2a2e3497ddd9df71007d4a.json | Remove types in HTMLBars helpers | packages/ember-htmlbars/lib/helpers/collection.js | @@ -168,7 +168,6 @@ export function collectionHelper(params, hash, options, env) {
collectionClass = CollectionView;
}
- var hashTypes = options.hashTypes;
var itemHash = {};
var match;
@@ -192,8 +191,6 @@ export function collectionHelper(params, hash, options, env) {
delete hash.itemViewClass;
delete hash.itemView;
- delete hashTypes.itemViewClass;
- delete hashTypes.itemView;
// Go through options passed to the {{collection}} helper and extract options
// that configure item views instead of the collection itself. | true |
Other | emberjs | ember.js | 734b551f2b8407420c2a2e3497ddd9df71007d4a.json | Remove types in HTMLBars helpers | packages/ember-htmlbars/lib/helpers/input.js | @@ -188,18 +188,16 @@ import Ember from "ember-metal/core"; // Ember.assert
export function inputHelper(params, hash, options, env) {
Ember.assert('You can only pass attributes to the `input` helper, not arguments', params.length === 0);
- var types = options.hashTypes;
var onEvent = hash.on;
var inputType;
inputType = read(hash.type);
if (inputType === 'checkbox') {
delete hash.type;
- delete types.type;
Ember.assert("{{input type='checkbox'}} does not support setting `value=someBooleanValue`;" +
- " you must use `checked=someBooleanValue` instead.", options.hashTypes.value !== 'id');
+ " you must use `checked=someBooleanValue` instead.", !hash.hasOwnProperty('value'));
env.helpers.view.helperFunction.call(this, [Checkbox], hash, options, env);
} else { | true |
Other | emberjs | ember.js | 734b551f2b8407420c2a2e3497ddd9df71007d4a.json | Remove types in HTMLBars helpers | packages/ember-htmlbars/lib/helpers/loc.js | @@ -1,5 +1,6 @@
import Ember from 'ember-metal/core';
import { loc } from 'ember-runtime/system/string';
+import { isStream } from "ember-metal/streams/utils";
/**
@module ember
@@ -39,14 +40,14 @@ import { loc } from 'ember-runtime/system/string';
@see {Ember.String#loc}
*/
export function locHelper(params, hash, options, env) {
- Ember.assert('You cannot pass bindings to `loc` helper', function ifParamsContainBindings() {
+ Ember.assert('You cannot pass bindings to `loc` helper', (function ifParamsContainBindings() {
for (var i = 0, l = params.length; i < l; i++) {
- if (options.paramTypes[i] === 'id') {
+ if (isStream(params[i])) {
return false;
}
}
return true;
- });
+ })());
return loc.apply(this, params);
} | true |
Other | emberjs | ember.js | 734b551f2b8407420c2a2e3497ddd9df71007d4a.json | Remove types in HTMLBars helpers | packages/ember-htmlbars/lib/helpers/log.js | @@ -3,6 +3,7 @@
@submodule ember-htmlbars
*/
import Logger from "ember-metal/logger";
+import { read } from "ember-metal/streams/utils";
/**
`log` allows you to output the value of variables in the current rendering
@@ -21,12 +22,7 @@ export function logHelper(params, hash, options, env) {
var values = [];
for (var i = 0; i < params.length; i++) {
- if (options.paramTypes[i] === 'id') {
- var stream = params[i];
- values.push(stream.value());
- } else {
- values.push(params[i]);
- }
+ values.push(read(params[i]));
}
logger.apply(logger, values); | true |
Other | emberjs | ember.js | 734b551f2b8407420c2a2e3497ddd9df71007d4a.json | Remove types in HTMLBars helpers | packages/ember-htmlbars/lib/helpers/view.js | @@ -9,41 +9,41 @@ import EmberObject from "ember-runtime/system/object";
import { get } from "ember-metal/property_get";
import keys from "ember-metal/keys";
import { IS_BINDING } from "ember-metal/mixin";
-import { read } from "ember-metal/streams/utils";
+import { read, isStream } from "ember-metal/streams/utils";
import { readViewFactory } from "ember-views/streams/utils";
import View from "ember-views/views/view";
import SimpleStream from "ember-metal/streams/simple";
function makeBindings(hash, options, view) {
- var hashTypes = options.hashTypes;
-
for (var prop in hash) {
- var hashType = hashTypes[prop];
- var valueOrStream = hash[prop];
+ var value = hash[prop];
+
+ // Classes are processed separately
+ if (prop === 'class' && isStream(value)) {
+ hash.classBinding = value._label;
+ delete hash['class'];
+ continue;
+ }
- // classBinding is processed separately
if (prop === 'classBinding') {
continue;
}
if (IS_BINDING.test(prop)) {
- if (hashType === 'id') {
- // valueOrStream is a stream, streamifyArgs took care of it
+ if (isStream(value)) {
Ember.warn("You're attempting to render a view by passing " +
prop + " " +
"to a view helper without a quoted value, " +
"but this syntax is ambiguous. You should either surround " +
prop + "'s value in quotes or remove `Binding` " +
"from " + prop + ".");
- } else if (typeof valueOrStream === 'string') {
- hash[prop] = view._getBindingForStream(valueOrStream);
+ } else if (typeof value === 'string') {
+ hash[prop] = view._getBindingForStream(value);
}
} else {
- if (hashType === 'id' && prop !== 'id') {
- hash[prop + 'Binding'] = valueOrStream;
-
+ if (isStream(value) && prop !== 'id') {
+ hash[prop + 'Binding'] = value;
delete hash[prop];
- delete hashTypes[prop];
}
}
} | true |
Other | emberjs | ember.js | 734b551f2b8407420c2a2e3497ddd9df71007d4a.json | Remove types in HTMLBars helpers | packages/ember-htmlbars/lib/hooks/component.js | @@ -4,7 +4,6 @@
*/
import Ember from "ember-metal/core";
-import streamifyArgs from "ember-htmlbars/system/streamify-arguments";
import lookupHelper from "ember-htmlbars/system/lookup-helper";
export default function component(morph, tagName, view, hash, options, env) {
@@ -13,7 +12,6 @@ export default function component(morph, tagName, view, hash, options, env) {
Ember.assert('You specified `' + tagName + '` in your template, but a component for `' + tagName + '` could not be found.', !!helper);
- streamifyArgs(view, params, hash, options, env, helper);
return helper.helperFunction.call(view, params, hash, options, env);
}
| true |
Other | emberjs | ember.js | 734b551f2b8407420c2a2e3497ddd9df71007d4a.json | Remove types in HTMLBars helpers | packages/ember-htmlbars/lib/hooks/element.js | @@ -3,14 +3,12 @@
@submodule ember-htmlbars
*/
-import streamifyArgs from "ember-htmlbars/system/streamify-arguments";
import lookupHelper from "ember-htmlbars/system/lookup-helper";
export default function element(domElement, path, view, params, hash, options, env) { //jshint ignore:line
var helper = lookupHelper(path, view, env);
if (helper) {
- streamifyArgs(view, params, hash, options, env, helper);
return helper.helperFunction.call(view, params, hash, options, env);
} else {
return view.getStream(path); | true |
Other | emberjs | ember.js | 734b551f2b8407420c2a2e3497ddd9df71007d4a.json | Remove types in HTMLBars helpers | packages/ember-htmlbars/lib/hooks/get.js | @@ -0,0 +1,8 @@
+/**
+@module ember
+@submodule ember-htmlbars
+*/
+
+export default function get(view, path) {
+ return view.getStream(path);
+} | true |
Other | emberjs | ember.js | 734b551f2b8407420c2a2e3497ddd9df71007d4a.json | Remove types in HTMLBars helpers | packages/ember-htmlbars/lib/hooks/subexpr.js | @@ -3,14 +3,12 @@
@submodule ember-htmlbars
*/
-import streamifyArgs from "ember-htmlbars/system/streamify-arguments";
import lookupHelper from "ember-htmlbars/system/lookup-helper";
export default function subexpr(path, view, params, hash, options, env) {
var helper = lookupHelper(path, view, env);
if (helper) {
- streamifyArgs(view, params, hash, options, env, helper);
return helper.helperFunction.call(view, params, hash, options, env);
} else {
return view.getStream(path); | true |
Other | emberjs | ember.js | 734b551f2b8407420c2a2e3497ddd9df71007d4a.json | Remove types in HTMLBars helpers | packages/ember-htmlbars/lib/main.js | @@ -4,6 +4,7 @@ import component from "ember-htmlbars/hooks/component";
import element from "ember-htmlbars/hooks/element";
import subexpr from "ember-htmlbars/hooks/subexpr";
import attribute from "ember-htmlbars/hooks/attribute";
+import get from "ember-htmlbars/hooks/get";
import set from "ember-htmlbars/hooks/set";
import { DOMHelper } from "morph";
import template from "ember-htmlbars/system/template";
@@ -88,6 +89,7 @@ export var defaultEnv = {
dom: new DOMHelper(),
hooks: {
+ get: get,
set: set,
content: content,
element: element, | true |
Other | emberjs | ember.js | 734b551f2b8407420c2a2e3497ddd9df71007d4a.json | Remove types in HTMLBars helpers | packages/ember-htmlbars/lib/system/sanitize-for-helper.js | @@ -1,23 +0,0 @@
-/**
-@module ember
-@submodule ember-htmlbars
-*/
-
-/**
- Sanitize options so that all helpers have `types`, `hash`, and `hashTypes`.
-
- @private
- @method sanitizeOptionsForHelper
- @param {Object} options The options hash provided by the template engine.
-*/
-export function sanitizeOptionsForHelper(options) {
- if (!options.paramTypes) {
- options.paramTypes = [];
- }
-
- if (!options.hashTypes) {
- options.hashTypes = {};
- }
-
- return options;
-} | true |
Other | emberjs | ember.js | 734b551f2b8407420c2a2e3497ddd9df71007d4a.json | Remove types in HTMLBars helpers | packages/ember-htmlbars/lib/system/streamify-arguments.js | @@ -1,27 +0,0 @@
-/**
-@module ember
-@submodule ember-htmlbars
-*/
-
-import { sanitizeOptionsForHelper } from "ember-htmlbars/system/sanitize-for-helper";
-
-export default function streamifyArgs(view, params, hash, options, env, helper) {
- sanitizeOptionsForHelper(options);
- helper.preprocessArguments(view, params, hash, options, env);
-
- // Convert ID params to streams
- for (var i = 0, l = params.length; i < l; i++) {
- if (options.paramTypes[i] === 'id') {
- params[i] = view.getStream(params[i]);
- }
- }
-
- // Convert hash ID values to streams
- var hashTypes = options.hashTypes;
- for (var key in hash) {
- if (hashTypes[key] === 'id' && key !== 'classBinding' && key !== 'class') {
- hash[key] = view.getStream(hash[key]);
- }
- }
-}
- | true |
Other | emberjs | ember.js | 734b551f2b8407420c2a2e3497ddd9df71007d4a.json | Remove types in HTMLBars helpers | packages/ember-htmlbars/tests/integration/binding_integration_test.js | @@ -175,8 +175,6 @@ test('should accept bindings as a string or an Ember.Binding', function() {
EmberHandlebars.registerHelper('boogie', function(id, options) {
options.hash = options.hash || {};
- options.hashTypes = options.hashTypes || {};
-
options.hash.bindingTestBinding = Binding.oneWay('context.' + id);
options.hash.stringTestBinding = id;
| true |
Other | emberjs | ember.js | 734b551f2b8407420c2a2e3497ddd9df71007d4a.json | Remove types in HTMLBars helpers | packages/ember-htmlbars/tests/system/sanitize-for-helper_test.js | @@ -1,51 +0,0 @@
-import { sanitizeOptionsForHelper } from "ember-htmlbars/system/sanitize-for-helper";
-
-var options;
-QUnit.module('ember-htmlbars: sanitize-for-helper', {
- setup: function() {
- options = {};
- },
-
- teardown: function() {
- ok(options.paramTypes, 'paramTypes is present');
- ok(options.hashTypes, 'hashTypes is present');
- }
-});
-
-test('will not override `paramTypes` if present', function() {
- expect(3);
-
- var paramTypes = [];
- options.paramTypes = paramTypes;
-
- sanitizeOptionsForHelper(options);
-
- equal(options.paramTypes, paramTypes, 'paramTypes is not changed when present');
-});
-
-test('will add `paramTypes` if not present', function() {
- expect(3);
-
- sanitizeOptionsForHelper(options);
-
- deepEqual(options.paramTypes, [], 'paramTypes is added when not present');
-});
-
-test('will not override `hashTypes` if present', function() {
- expect(3);
-
- var hashTypes = {};
- options.hashTypes = hashTypes;
-
- sanitizeOptionsForHelper(options);
-
- equal(options.hashTypes, hashTypes, 'hashTypes is not changed when present');
-});
-
-test('will add `hashTypes` if not present', function() {
- expect(3);
-
- sanitizeOptionsForHelper(options);
-
- deepEqual(options.hashTypes, {}, 'hashTypes is added when not present');
-}); | true |
Other | emberjs | ember.js | 734b551f2b8407420c2a2e3497ddd9df71007d4a.json | Remove types in HTMLBars helpers | packages/ember-routing-htmlbars/lib/helpers/link-to.js | @@ -5,7 +5,7 @@
import Ember from "ember-metal/core"; // assert
import { LinkView } from "ember-routing-views/views/link";
-import { read } from "ember-metal/streams/utils";
+import { read, isStream } from "ember-metal/streams/utils";
import ControllerMixin from "ember-runtime/mixins/controller";
// We need the HTMLBars view helper from ensure ember-htmlbars.
@@ -275,8 +275,6 @@ import 'ember-htmlbars';
@see {Ember.LinkView}
*/
function linkToHelper(params, hash, options, env) {
- var hashTypes = options.hashTypes;
- var paramTypes = options.paramTypes;
var shouldEscape = !hash.unescaped;
var queryParamsObject;
@@ -290,23 +288,14 @@ function linkToHelper(params, hash, options, env) {
if (hash.disabledWhen) {
hash.disabled = hash.disabledWhen;
- hashTypes.disabled = hashTypes.disabledWhen;
-
delete hash.disabledWhen;
- delete hashTypes.disabledWhen;
}
if (!options.render) {
var linkTitle = params.shift();
- var linkTitleType = paramTypes.shift();
-
- if (linkTitleType === 'id') {
- hash.linkTitle = linkTitle = linkTitle;
- // making the type `id` (which is what it is) results
- // in the stream being unwrapped by the binding system
- // so lets leave it something else, so our LinkView
- // gets the actual stream
- options.hashTypes.linkTitle = 'raw';
+
+ if (isStream(linkTitle)) {
+ hash.linkTitle = { stream: linkTitle };
}
options.render = function() {
@@ -322,7 +311,7 @@ function linkToHelper(params, hash, options, env) {
}
for (var i = 0; i < params.length; i++) {
- if (paramTypes[i] === 'id') {
+ if (isStream(params[i])) {
var lazyValue = params[i];
if (!lazyValue._isController) { | true |
Other | emberjs | ember.js | 734b551f2b8407420c2a2e3497ddd9df71007d4a.json | Remove types in HTMLBars helpers | packages/ember-routing-htmlbars/lib/helpers/outlet.js | @@ -78,7 +78,7 @@ export function outletHelper(params, hash, options, env) {
Ember.assert(
"Using {{outlet}} with an unquoted name is not supported.",
- params.length === 0 || options.paramTypes[0] === 'string'
+ params.length === 0 || typeof params[0] === 'string'
);
var property = params[0] || 'main';
@@ -97,7 +97,7 @@ export function outletHelper(params, hash, options, env) {
Ember.assert(
"Using a quoteless view parameter with {{outlet}} is not supported." +
" Please update to quoted usage '{{outlet ... view=\"" + viewName + "\"}}.",
- options.hashTypes.view === 'string'
+ typeof hash.view === 'string'
);
Ember.assert(
"The view name you supplied '" + viewName + "' did not resolve to a view.",
@@ -106,10 +106,8 @@ export function outletHelper(params, hash, options, env) {
}
viewClass = viewName ? this.container.lookupFactory(viewFullName) : hash.viewClass || OutletView;
- options.paramTypes = ['id'];
hash.currentViewBinding = '_view.outletSource._outlets.' + property;
- options.hashTypes.currentViewBinding = 'string';
options.helperName = options.helperName || 'outlet';
| true |
Other | emberjs | ember.js | 734b551f2b8407420c2a2e3497ddd9df71007d4a.json | Remove types in HTMLBars helpers | packages/ember-routing-htmlbars/lib/helpers/render.js | @@ -11,6 +11,7 @@ import {
default as generateController
} from "ember-routing/system/generate_controller";
import { ViewHelper } from "ember-htmlbars/helpers/view";
+import { isStream } from "ember-metal/streams/utils";
/**
Calling ``{{render}}`` from within a template will insert another
@@ -93,12 +94,12 @@ export function renderHelper(params, hash, options, env) {
Ember.assert(
"The first argument of {{render}} must be quoted, e.g. {{render \"sidebar\"}}.",
- options.paramTypes[0] === 'string'
+ typeof name === 'string'
);
Ember.assert(
"The second argument of {{render}} must be a path, e.g. {{render \"post\" post}}.",
- params.length < 2 || options.paramTypes[1] === 'id'
+ params.length < 2 || isStream(params[1])
);
| true |
Other | emberjs | ember.js | 734b551f2b8407420c2a2e3497ddd9df71007d4a.json | Remove types in HTMLBars helpers | packages/ember-routing-views/lib/views/link.js | @@ -14,7 +14,7 @@ import keys from "ember-metal/keys";
import { isSimpleClick } from "ember-views/system/utils";
import EmberComponent from "ember-views/views/component";
import { routeArgs } from "ember-routing/utils";
-import { read } from "ember-metal/streams/utils";
+import { read, subscribe } from "ember-metal/streams/utils";
var numberOfContextsAcceptedByHandler = function(handler, handlerInfos) {
var req = 0;
@@ -219,14 +219,12 @@ var LinkView = Ember.LinkView = EmberComponent.extend({
var scheduledParamsChanged = this._wrapAsScheduled(this._paramsChanged);
if (this.linkTitle) {
- this.linkTitle.subscribe(scheduledRerender, this);
+ var linkTitle = this.linkTitle.stream || this.linkTitle;
+ subscribe(linkTitle, scheduledRerender, this);
}
for (var i = 0; i < params.length; i++) {
- var param = params[i];
- if (param && param.isStream) {
- param.subscribe(scheduledParamsChanged, this);
- }
+ subscribe(params[i], scheduledParamsChanged, this);
}
var queryParamsObject = this.queryParamsObject;
@@ -237,10 +235,7 @@ var LinkView = Ember.LinkView = EmberComponent.extend({
continue;
}
- var value = values[k];
- if (value && value.isStream) {
- value.subscribe(scheduledParamsChanged, this);
- }
+ subscribe(values[k], scheduledParamsChanged, this);
}
}
}, | true |
Other | emberjs | ember.js | 6ebca89f578125c617e9b0770d694730649c2d5e.json | Add HTMLBars version of makeBoundHelper.
Much simplified. Behold... | packages/ember-htmlbars/lib/main.js | @@ -9,6 +9,7 @@ import { DOMHelper } from "morph";
import template from "ember-htmlbars/system/template";
import compile from "ember-htmlbars/system/compile";
import makeViewHelper from "ember-htmlbars/system/make-view-helper";
+import makeBoundHelper from "ember-htmlbars/system/make_bound_helper";
import {
registerHelper,
@@ -86,7 +87,8 @@ if (Ember.FEATURES.isEnabled('ember-htmlbars')) {
registerHelper: registerHelper,
template: template,
compile: compile,
- makeViewHelper: makeViewHelper
+ makeViewHelper: makeViewHelper,
+ makeBoundHelper: makeBoundHelper
};
} | true |
Other | emberjs | ember.js | 6ebca89f578125c617e9b0770d694730649c2d5e.json | Add HTMLBars version of makeBoundHelper.
Much simplified. Behold... | packages/ember-htmlbars/lib/system/make_bound_helper.js | @@ -0,0 +1,99 @@
+/**
+@module ember
+@submodule ember-htmlbars
+*/
+
+import Ember from "ember-metal/core"; // Ember.FEATURES, Ember.assert, Ember.Handlebars, Ember.lookup
+import { IS_BINDING } from "ember-metal/mixin";
+import { appendSimpleBoundView } from "ember-views/views/simple_bound_view";
+import Helper from "ember-htmlbars/system/helper";
+
+import Stream from "ember-metal/streams/stream";
+import {
+ readArray,
+ readHash,
+ subscribe
+} from "ember-metal/streams/utils";
+
+/**
+ Create a bound helper. Accepts a function that receives the ordered and hash parameters
+ from the template. If a bound property was provided in the template it will be resolved to its
+ value and any changes to the bound property cause the helper function to be re-ran with the updated
+ values.
+
+ * `params` - An array of resolved ordered parameters.
+ * `hash` - An object containing the hash parameters.
+
+ For example:
+
+ * With an unqouted ordered parameter:
+
+ ```javascript
+ {{x-capitalize foo}}
+ ```
+
+ Assuming `foo` was set to `"bar"`, the bound helper would receive `["bar"]` as its first argument, and
+ an empty hash as its second.
+
+ * With a quoted ordered parameter:
+
+ ```javascript
+ {{x-capitalize "foo"}}
+ ```
+
+ The bound helper would receive `["foo"]` as its first argument, and an empty hash as its second.
+
+ * With an unquoted hash parameter:
+
+ ```javascript
+ {{x-repeat "foo" count=repeatCount}}
+ ```
+
+ Assuming that `repeatCount` resolved to 2, the bound helper would receive `["foo"]` as its first argument,
+ and { count: 2 } as its second.
+
+ @method makeBoundHelper
+ @for Ember.HTMLBars
+ @param {Function} function
+ @since 1.10.0
+*/
+export default function makeBoundHelper(fn) {
+ function helperFunc(params, hash, options, env) {
+ var view = this;
+
+ Ember.assert("makeBoundHelper generated helpers do not support use with blocks", !options.render);
+
+ for (var prop in hash) {
+ if (IS_BINDING.test(prop)) {
+ hash[prop.slice(0, -7)] = view._getBindingForStream(hash[prop]);
+
+ delete hash[prop];
+ }
+ }
+
+ function valueFn() {
+ return fn.call(view, readArray(params), readHash(hash), options, env);
+ }
+
+ if (env.data.isUnbound) {
+ return valueFn();
+ } else {
+ var lazyValue = new Stream(valueFn);
+
+ appendSimpleBoundView(this, options.morph, lazyValue);
+
+ var param;
+ for (var i = 0, l = params.length; i < l; i++) {
+ param = params[i];
+ subscribe(param, lazyValue.notify, lazyValue);
+ }
+
+ for (prop in hash) {
+ param = hash[prop];
+ subscribe(param, lazyValue.notify, lazyValue);
+ }
+ }
+ }
+
+ return new Helper(helperFunc);
+} | true |
Other | emberjs | ember.js | 6ebca89f578125c617e9b0770d694730649c2d5e.json | Add HTMLBars version of makeBoundHelper.
Much simplified. Behold... | packages/ember-htmlbars/tests/system/make_bound_helper_test.js | @@ -0,0 +1,219 @@
+import EmberView from "ember-views/views/view";
+import run from "ember-metal/run_loop";
+import Container from "container";
+import makeBoundHelper from "ember-htmlbars/system/make_bound_helper";
+import compile from "ember-htmlbars/system/compile";
+
+var view, container;
+
+function appendView(view) {
+ run(view, 'appendTo', '#qunit-fixture');
+}
+
+function registerRepeatHelper() {
+ container.register('helper:x-repeat', makeBoundHelper(function(params, hash, options, env) {
+ return new Array(hash.times + 1).join( params[0] );
+ }));
+}
+
+if (Ember.FEATURES.isEnabled('ember-htmlbars')) {
+
+QUnit.module("ember-htmlbars: makeBoundHelper", {
+ setup: function() {
+ container = new Container();
+ container.optionsForType('helper', { instantiate: false });
+ },
+
+ teardown: function() {
+ if (view) {
+ run(view, 'destroy');
+ }
+
+ container.destroy();
+ }
+});
+
+test("should update bound helpers when properties change", function() {
+ container.register('helper:x-capitalize', makeBoundHelper(function(params, hash, options, env) {
+ return params[0].toUpperCase();
+ }));
+
+ view = EmberView.create({
+ container: container,
+ controller: {name: "Brogrammer"},
+ template: compile("{{x-capitalize name}}")
+ });
+
+ appendView(view);
+
+ equal(view.$().text(), 'BROGRAMMER', "helper output is correct");
+
+ run(view, 'set', 'controller.name', 'wes');
+
+ equal(view.$().text(), 'WES', "helper output updated");
+});
+
+test("should update bound helpers when hash properties change", function() {
+ registerRepeatHelper();
+
+ view = EmberView.create({
+ container: container,
+ controller: {
+ phrase: "Yo",
+ repeatCount: 1
+ },
+ template: compile("{{x-repeat phrase times=repeatCount}}")
+ });
+
+ appendView(view);
+
+ equal(view.$().text(), 'Yo', "initial helper output is correct");
+
+ run(view, 'set', 'controller.repeatCount', 5);
+
+ equal(view.$().text(), 'YoYoYoYoYo', "helper output updated");
+});
+
+test("bound helpers should support keywords", function() {
+ container.register('helper:x-capitalize', makeBoundHelper(function(params, hash, options, env) {
+ return params[0].toUpperCase();
+ }));
+
+ view = EmberView.create({
+ container: container,
+ text: 'ab',
+ template: compile("{{x-capitalize view.text}}")
+ });
+
+ appendView(view);
+
+ equal(view.$().text(), 'AB', "helper output is correct");
+});
+
+test("bound helpers should support bound options", function() {
+ registerRepeatHelper();
+
+ view = EmberView.create({
+ container: container,
+ controller: {
+ text: 'ab',
+ numRepeats: 3
+ },
+ template: compile('{{x-repeat text timesBinding="numRepeats"}}')
+ });
+
+ appendView(view);
+
+ equal(view.$().text(), 'ababab', "helper output is correct");
+
+ run(view, 'set', 'controller.numRepeats', 4);
+
+ equal(view.$().text(), 'abababab', "helper correctly re-rendered after bound option was changed");
+
+ run(function() {
+ view.set('controller.numRepeats', 2);
+ view.set('controller.text', "YES");
+ });
+
+ equal(view.$().text(), 'YESYES', "helper correctly re-rendered after both bound option and property changed");
+});
+
+test("bound helpers should support multiple bound properties", function() {
+
+ container.register('helper:x-combine', makeBoundHelper(function(params, hash, options, env) {
+ return params.join('');
+ }));
+
+ view = EmberView.create({
+ container: container,
+ controller: {
+ thing1: 'ZOID',
+ thing2: 'BERG'
+ },
+ template: compile('{{x-combine thing1 thing2}}')
+ });
+
+ appendView(view);
+
+ equal(view.$().text(), 'ZOIDBERG', "helper output is correct");
+
+ run(view, 'set', 'controller.thing2', "NERD");
+
+ equal(view.$().text(), 'ZOIDNERD', "helper correctly re-rendered after second bound helper property changed");
+
+ run(function() {
+ view.set('controller.thing1', 'WOOT');
+ view.set('controller.thing2', 'YEAH');
+ });
+
+ equal(view.$().text(), 'WOOTYEAH', "helper correctly re-rendered after both bound helper properties changed");
+});
+
+test("bound helpers can be invoked with zero args", function() {
+ container.register('helper:x-troll', makeBoundHelper(function(params, hash) {
+ return hash.text || "TROLOLOL";
+ }));
+
+ view = EmberView.create({
+ container: container,
+ controller: {
+ trollText: "yumad"
+ },
+ template: compile('{{x-troll}} and {{x-troll text="bork"}}')
+ });
+
+ appendView(view);
+
+ equal(view.$().text(), 'TROLOLOL and bork', "helper output is correct");
+});
+
+test("bound helpers should not be invoked with blocks", function() {
+ registerRepeatHelper();
+ view = EmberView.create({
+ container: container,
+ controller: {},
+ template: compile("{{#x-repeat}}Sorry, Charlie{{/x-repeat}}")
+ });
+
+ expectAssertion(function() {
+ appendView(view);
+ }, /makeBoundHelper generated helpers do not support use with blocks/i);
+});
+
+test("shouldn't treat raw numbers as bound paths", function() {
+ container.register('helper:x-sum', makeBoundHelper(function(params) {
+ return params[0] + params[1];
+ }));
+
+ view = EmberView.create({
+ container: container,
+ controller: {aNumber: 1},
+ template: compile("{{x-sum aNumber 1}} {{x-sum 0 aNumber}} {{x-sum 5 6}}")
+ });
+
+ appendView(view);
+
+ equal(view.$().text(), '2 1 11', "helper output is correct");
+
+ run(view, 'set', 'controller.aNumber', 5);
+
+ equal(view.$().text(), '6 5 11', "helper still updates as expected");
+});
+
+test("should have correct argument types", function() {
+ container.register('helper:get-type', makeBoundHelper(function(params) {
+ return typeof params[0];
+ }));
+
+ view = EmberView.create({
+ container: container,
+ controller: {},
+ template: compile('{{get-type null}}, {{get-type undefProp}}, {{get-type "string"}}, {{get-type 1}}, {{get-type this}}')
+ });
+
+ appendView(view);
+
+ equal(view.$().text(), 'undefined, undefined, string, number, object', "helper output is correct");
+});
+
+} | true |
Other | emberjs | ember.js | 800b09465da06f54996893ea8e744bc3d3569cf3.json | Remove lingering templateData | packages/ember-handlebars/lib/helpers/binding.js | @@ -62,7 +62,6 @@ function bind(property, options, preserveContext, shouldDisplay, valueNormalizer
lazyValue: lazyValue,
previousContext: currentContext,
isEscaped: !options.hash.unescaped,
- templateData: options.data,
templateHash: options.hash,
helperName: options.helperName
}; | true |
Other | emberjs | ember.js | 800b09465da06f54996893ea8e744bc3d3569cf3.json | Remove lingering templateData | packages/ember-handlebars/lib/helpers/view.js | @@ -137,7 +137,6 @@ export var ViewHelper = EmberObject.create({
var viewOptions = this.propertiesFromHTMLOptions(options, thisContext);
var currentView = data.view;
- viewOptions.templateData = data;
var newViewProto = newView.proto();
if (fn) {
@@ -168,7 +167,6 @@ export var ViewHelper = EmberObject.create({
var viewOptions = this.propertiesFromHTMLOptions(options, thisContext);
var currentView = data.view;
- viewOptions.templateData = data;
if (fn) {
Ember.assert("You cannot provide a template block if you also specified a templateName", | true |
Other | emberjs | ember.js | 800b09465da06f54996893ea8e744bc3d3569cf3.json | Remove lingering templateData | packages/ember-htmlbars/lib/helpers/binding.js | @@ -49,7 +49,6 @@ function bind(property, hash, options, env, preserveContext, shouldDisplay, valu
lazyValue: lazyValue,
previousContext: get(this, 'context'),
isEscaped: !hash.unescaped,
- templateData: env.data,
templateHash: hash,
helperName: options.helperName
}; | true |
Other | emberjs | ember.js | 800b09465da06f54996893ea8e744bc3d3569cf3.json | Remove lingering templateData | packages/ember-htmlbars/lib/helpers/view.js | @@ -126,7 +126,6 @@ export var ViewHelper = EmberObject.create({
var viewOptions = this.propertiesFromHTMLOptions(hash, options, env);
var currentView = data.view;
- viewOptions.templateData = data;
var newViewProto = newView.proto();
if (fn) {
@@ -159,7 +158,6 @@ export var ViewHelper = EmberObject.create({
var viewOptions = this.propertiesFromHTMLOptions(hash, options, env);
var currentView = data.view;
- viewOptions.templateData = data;
if (fn) {
Ember.assert("You cannot provide a template block if you also specified a templateName", | true |
Other | emberjs | ember.js | 800b09465da06f54996893ea8e744bc3d3569cf3.json | Remove lingering templateData | packages/ember-htmlbars/tests/helpers/with_test.js | @@ -230,37 +230,6 @@ test("it should support #with this as qux", function() {
});
});
-QUnit.module("Handlebars {{#with foo}} insideGroup");
-
-test("it should render without fail [DEPRECATED]", function() {
- var View = EmberView.extend({
- template: compile("{{#view view.childView}}{{#with person}}{{name}}{{/with}}{{/view}}"),
- controller: EmberObject.create({ person: { name: "Ivan IV Vasilyevich" } }),
- childView: EmberView.extend({
- render: function(){
- this.set('templateData.insideGroup', true);
- return this._super.apply(this, arguments);
- }
- })
- });
-
- var view = View.create();
- expectDeprecation(function(){
- appendView(view);
- }, 'Using the context switching form of `{{with}}` is deprecated. Please use the keyword form (`{{with foo as bar}}`) instead. See http://emberjs.com/guides/deprecations/#toc_more-consistent-handlebars-scope for more details.');
- equal(view.$().text(), "Ivan IV Vasilyevich", "should be properly scoped");
-
- run(function() {
- set(view, 'controller.person.name', "Ivan the Terrible");
- });
-
- equal(view.$().text(), "Ivan the Terrible", "should update");
-
- run(function() {
- view.destroy();
- });
-});
-
QUnit.module("Handlebars {{#with foo}} with defined controller");
test("it should wrap context with object controller [DEPRECATED]", function() { | true |
Other | emberjs | ember.js | 800b09465da06f54996893ea8e744bc3d3569cf3.json | Remove lingering templateData | packages/ember-htmlbars/tests/integration/group_test.js | @@ -1,299 +0,0 @@
-/*jshint newcap:false*/
-
-import run from "ember-metal/run_loop";
-import jQuery from "ember-views/system/jquery";
-import EmberView from "ember-views/views/view";
-import _MetamorphView from "ember-views/views/metamorph_view";
-import EmberHandlebars from "ember-handlebars-compiler";
-import ArrayProxy from "ember-runtime/system/array_proxy";
-import { A } from "ember-runtime/system/native_array";
-import Container from "ember-runtime/system/container";
-import { set } from "ember-metal/property_set";
-import Component from "ember-views/views/component";
-import htmlbarsCompile from "ember-htmlbars/system/compile";
-
-var compile;
-if (Ember.FEATURES.isEnabled('ember-htmlbars')) {
- compile = htmlbarsCompile;
-} else {
- compile = EmberHandlebars.compile;
-}
-
-var trim = jQuery.trim;
-var container, view;
-
-function appendView() {
- run(function() { view.appendTo('#qunit-fixture'); });
-}
-
-QUnit.module("ember-htmlbars: group flag", {
- setup: function() {
- container = new Container();
- container.register('view:default', _MetamorphView);
- container.register('view:toplevel', EmberView.extend());
- },
-
- teardown: function() {
- run(function() {
- if (view) {
- view.destroy();
- }
- if (container) {
- container.destroy();
- }
- container = view = null;
- });
- run.cancelTimers();
- }
-});
-
-function createGroupedView(template, context) {
- var options = {
- container: container,
- context: context,
- template: compile(template),
- templateData: {insideGroup: true, keywords: {}}
- };
- run(function() {
- view = EmberView.create(options);
- });
-}
-
-test("should properly modify behavior inside the block", function() {
- createGroupedView("{{msg}}", {msg: 'ohai'});
- appendView();
-
- equal(view.$().text(), 'ohai', 'Original value was rendered');
-
- run(function() {
- view.set('context.msg', 'ohbai');
- });
- equal(view.$().text(), 'ohbai', 'Updated value was rendered');
-
- run(function() {
- view.set('context.msg', null);
- });
- equal(view.$().text(), '', 'null value properly rendered as a blank');
-
- run(function() {
- view.set('context.msg', undefined);
- });
- equal(view.$().text(), '', 'undefined value properly rendered as a blank');
-});
-
-test("property changes inside views should only rerender their view", function() {
- createGroupedView(
- '{{#view}}{{msg}}{{/view}}',
- {msg: 'ohai'}
- );
- var rerenderWasCalled = false;
- view.reopen({
- rerender: function() { rerenderWasCalled = true; this._super(); }
- });
- appendView();
- equal(trim(view.$().text()), 'ohai', 'Original value was rendered');
-
- run(function() {
- view.set('context.msg', 'ohbai');
- });
- ok(!rerenderWasCalled, "The GroupView rerender method was not called");
- equal(trim(view.$().text()), 'ohbai', "The updated value was rendered");
-});
-
-test("should work with bind-attr", function() {
- createGroupedView(
- '<button {{bind-attr class="innerClass"}}>ohai</button>',
- {innerClass: 'magic'}
- );
- appendView();
- equal(view.$('.magic').length, 1);
-
- run(function() {
- view.set('context.innerClass', 'bindings');
- });
- equal(view.$('.bindings').length, 1);
-
- run(function() {
- view.rerender();
- });
- equal(view.$('.bindings').length, 1);
-});
-
-test("should work with the #if helper", function() {
- createGroupedView(
- '{{#if something}}hooray{{else}}boo{{/if}}',
- {something: true}
- );
- appendView();
-
- equal(trim(view.$().text()), 'hooray', 'Truthy text was rendered');
-
- run(function() {
- view.set('context.something', false);
- });
- equal(trim(view.$().text()), 'boo', "The falsy value was rendered");
-});
-
-test("#each with no content", function() {
- expect(0);
- createGroupedView(
- "{{#each item in missing}}{{item}}{{/each}}"
- );
- appendView();
-});
-
-test("#each's content can be changed right before a destroy", function() {
- expect(0);
-
- createGroupedView(
- "{{#each number in numbers}}{{number}}{{/each}}",
- {numbers: A([1,2,3])}
- );
- appendView();
-
- run(function() {
- view.set('context.numbers', A([3,2,1]));
- view.destroy();
- });
-});
-
-test("#each can be nested", function() {
- createGroupedView(
- "{{#each number in numbers}}{{number}}{{/each}}",
- {numbers: A([1, 2, 3])}
- );
- appendView();
- equal(view.$().text(), '123', "The content was rendered");
-
- run(function() {
- view.get('context.numbers').pushObject(4);
- });
-
- equal(view.$().text(), '1234', "The array observer properly updated the rendered output");
-
- run(function() {
- view.set('context.numbers', A(['a', 'b', 'c']));
- });
-
- equal(view.$().text(), 'abc', "Replacing the array properly updated the rendered output");
-});
-
-test("#each can be used with an ArrayProxy", function() {
- createGroupedView(
- "{{#each number in numbers}}{{number}}{{/each}}",
- {numbers: ArrayProxy.create({content: A([1, 2, 3])})}
- );
- appendView();
- equal(view.$().text(), '123', "The content was rendered");
-});
-
-test("should allow `#each item in array` format", function() {
- var yehuda = {name: 'Yehuda'};
- createGroupedView(
- '{{#each person in people}}{{person.name}}{{/each}}',
- {people: A([yehuda, {name: 'Tom'}])}
- );
- appendView();
- equal(view.$().text(), 'YehudaTom', "The content was rendered");
-
- run(function() {
- set(yehuda, 'name', 'Erik');
- });
- equal(view.$().text(), 'ErikTom', "The updated object value was rendered");
-
- run(function() {
- view.get('context.people').pushObject({name: 'Alex'});
- view.get('context.people').removeObject(yehuda);
- });
- equal(view.$().text(), 'TomAlex', "The updated array content was rendered");
-
- run(function() {
- view.set('context.people', A([{name: 'Sarah'},{name: 'Gavin'}]));
- });
- equal(view.$().text(), 'SarahGavin', "The replaced array content was rendered");
-});
-
-test("an #each can be nested with a view inside", function() {
- var yehuda = {name: 'Yehuda'};
- createGroupedView(
- '{{#each person in people}}{{#view}}{{person.name}}{{/view}}{{/each}}',
- {people: A([yehuda, {name: 'Tom'}])}
- );
- appendView();
- equal(view.$().text(), 'YehudaTom', "The content was rendered");
-
- run(function() {
- set(yehuda, 'name', 'Erik');
- });
-
- equal(view.$().text(), 'ErikTom', "The updated object's view was rerendered");
-});
-
-test("an #each can be nested with a component inside", function() {
- var yehuda = {name: 'Yehuda'};
- container.register('view:test', Component.extend());
- createGroupedView(
- '{{#each person in people}}{{#view "test"}}{{person.name}}{{/view}}{{/each}}',
- {people: A([yehuda, {name: 'Tom'}])}
- );
-
- appendView();
- equal(view.$().text(), 'YehudaTom', "The content was rendered");
-
- run(function() {
- set(yehuda, 'name', 'Erik');
- });
-
- equal(view.$().text(), 'ErikTom', "The updated object's view was rerendered");
-});
-
-test("#each with groupedRows=true behaves like a normal bound #each", function() {
- createGroupedView(
- '{{#each number in numbers groupedRows=true}}{{number}}{{/each}}',
- {numbers: A([1, 2, 3])}
- );
- appendView();
- equal(view.$().text(), '123');
-
- run(function() {
- view.get('context.numbers').pushObject(4);
- });
-
- equal(view.$().text(), '1234');
-});
-
-test("#each with itemViewClass behaves like a normal bound #each", function() {
- container.register('view:nothing-special-view', Ember.View);
- createGroupedView(
- '{{#each person in people itemViewClass="nothing-special-view"}}{{person.name}}{{/each}}',
- {people: A([{name: 'Erik'}, {name: 'Peter'}])}
- );
- appendView();
- equal(view.$('.ember-view').length, 2, "Correct number of views are output");
- equal(view.$().text(), 'ErikPeter');
-
- run(function() {
- view.get('context.people').pushObject({name: 'Tom'});
- });
-
- equal(view.$('.ember-view').length, 3, "Correct number of views are output");
- // IE likes to add newlines
- equal(trim(view.$().text()), 'ErikPeterTom');
-});
-
-test("should escape HTML in normal mustaches", function() {
- createGroupedView(
- '{{msg}}', {msg: 'you need to be more <b>bold</b>'}
- );
- appendView();
- equal(view.$('b').length, 0, "does not create an element");
- equal(view.$().text(), 'you need to be more <b>bold</b>', "inserts entities, not elements");
-});
-
-test("should not escape HTML in triple mustaches", function() {
- createGroupedView(
- '{{{msg}}}', {msg: 'you need to be more <b>bold</b>'}
- );
- appendView();
- equal(view.$('b').length, 1, "creates an element");
-}); | true |
Other | emberjs | ember.js | 800b09465da06f54996893ea8e744bc3d3569cf3.json | Remove lingering templateData | packages/ember-views/lib/views/component.js | @@ -185,8 +185,7 @@ var Component = View.extend(TargetActionSupport, ComponentTemplateDeprecation, {
_contextView: parentView,
_morph: morph,
context: get(parentView, 'context'),
- controller: get(parentView, 'controller'),
- templateData: { keywords: {} }
+ controller: get(parentView, 'controller')
});
}
}, | true |
Other | emberjs | ember.js | 800b09465da06f54996893ea8e744bc3d3569cf3.json | Remove lingering templateData | packages/ember-views/lib/views/container_view.js | @@ -328,23 +328,19 @@ var ContainerView = View.extend(MutableArray, {
childViewsDidChange: function(views, start, removed, added) {
if (added > 0) {
var changedViews = views.slice(start, start+added);
- this.initializeViews(changedViews, this, get(this, 'templateData'));
+ this.initializeViews(changedViews, this);
this.currentState.childViewsDidChange(this, views, start, added);
}
this.propertyDidChange('childViews');
},
- initializeViews: function(views, parentView, templateData) {
+ initializeViews: function(views, parentView) {
forEach(views, function(view) {
set(view, '_parentView', parentView);
if (!view.container && parentView) {
set(view, 'container', parentView.container);
}
-
- if (!get(view, 'templateData')) {
- set(view, 'templateData', templateData);
- }
});
},
| true |
Other | emberjs | ember.js | 800b09465da06f54996893ea8e744bc3d3569cf3.json | Remove lingering templateData | packages/ember-views/lib/views/view.js | @@ -1875,8 +1875,6 @@ var View = CoreView.extend({
attrs._parentView = this;
if (CoreView.detect(view)) {
- attrs.templateData = attrs.templateData || get(this, 'templateData');
-
attrs.container = this.container;
view = view.create(attrs);
@@ -1891,18 +1889,12 @@ var View = CoreView.extend({
Ember.assert("Could not find view: '" + fullName + "'", !!ViewKlass);
- attrs.templateData = get(this, 'templateData');
view = ViewKlass.create(attrs);
} else {
Ember.assert('You must pass instance or subclass of View', view.isView);
- attrs.container = this.container;
-
- if (!get(view, 'templateData')) {
- attrs.templateData = get(this, 'templateData');
- }
+ attrs.container = this.container;
setProperties(view, attrs);
-
}
return view; | true |
Other | emberjs | ember.js | 800b09465da06f54996893ea8e744bc3d3569cf3.json | Remove lingering templateData | packages/ember-views/tests/views/view/template_test.js | @@ -162,7 +162,6 @@ test("should provide a controller to the template if a controller is specified o
template: function(buffer, options) {
options.data.view.appendChild(EmberView.create({
controller: controller2,
- templateData: options.data,
template: function(context, options) {
contextForView = context;
optionsDataKeywordsControllerForChildView = options.data.view._keywords.controller.value();
@@ -188,7 +187,6 @@ test("should provide a controller to the template if a controller is specified o
template: function(buffer, options) {
options.data.view.appendChild(EmberView.create({
- templateData: options.data,
template: function(context, options) {
contextForControllerlessView = context;
optionsDataKeywordsControllerForChildView = options.data.view._keywords.controller.value(); | true |
Other | emberjs | ember.js | 15aaa9e41e11e5f9bf6fa702467d1fc03dbabbd7.json | Implement block params | features.json | @@ -17,6 +17,7 @@
"ember-routing-fire-activate-deactivate-events": true,
"ember-testing-pause-test": true,
"ember-htmlbars": null,
+ "ember-htmlbars-block-params": null,
"ember-htmlbars-component-generation": null
},
"debugStatements": [ | true |
Other | emberjs | ember.js | 15aaa9e41e11e5f9bf6fa702467d1fc03dbabbd7.json | Implement block params | package.json | @@ -42,7 +42,7 @@
"git-repo-version": "0.0.1",
"glob": "~3.2.8",
"handlebars": "^2.0",
- "htmlbars": "0.1.7",
+ "htmlbars": "0.1.8",
"ncp": "~0.5.1",
"rimraf": "~2.2.8",
"rsvp": "~3.0.6" | true |
Other | emberjs | ember.js | 15aaa9e41e11e5f9bf6fa702467d1fc03dbabbd7.json | Implement block params | packages/ember-htmlbars/lib/helpers/yield.js | @@ -103,5 +103,5 @@ export function yieldHelper(params, hash, options, env) {
Ember.assert("You called yield in a template that was not a layout", !!view);
- view._yield(null, env, options.morph);
+ view._yield(null, env, options.morph, params);
} | true |
Other | emberjs | ember.js | 15aaa9e41e11e5f9bf6fa702467d1fc03dbabbd7.json | Implement block params | packages/ember-htmlbars/lib/hooks.js | @@ -1,4 +1,5 @@
import Ember from "ember-metal/core";
+import EmberError from "ember-metal/error";
import run from "ember-metal/run_loop";
import lookupHelper from "ember-htmlbars/system/lookup-helper";
import concat from "ember-htmlbars/system/concat";
@@ -24,6 +25,17 @@ function streamifyArgs(view, params, hash, options, env, helper) {
}
}
+export function set(view, name, value) {
+ if (Ember.FEATURES.isEnabled('ember-htmlbars-block-params')) {
+ view._keywords[name] = value;
+ } else {
+ throw new EmberError(
+ "You must enable the ember-htmlbars-block-params feature " +
+ "flag to use the block params feature in Ember."
+ );
+ }
+}
+
export function content(morph, path, view, params, hash, options, env) {
var helper = lookupHelper(path, view, env);
if (!helper) { | true |
Other | emberjs | ember.js | 15aaa9e41e11e5f9bf6fa702467d1fc03dbabbd7.json | Implement block params | packages/ember-htmlbars/lib/main.js | @@ -1,5 +1,6 @@
import Ember from "ember-metal/core";
import {
+ set,
content,
element,
subexpr,
@@ -94,6 +95,7 @@ export var defaultEnv = {
dom: new DOMHelper(),
hooks: {
+ set: set,
content: content,
element: element,
subexpr: subexpr, | true |
Other | emberjs | ember.js | 15aaa9e41e11e5f9bf6fa702467d1fc03dbabbd7.json | Implement block params | packages/ember-htmlbars/tests/integration/block_params_test.js | @@ -0,0 +1,132 @@
+import Container from 'container/container';
+import run from "ember-metal/run_loop";
+import ComponentLookup from 'ember-views/component_lookup';
+import View from "ember-views/views/view";
+import compile from "ember-htmlbars/system/compile";
+import helpers from "ember-htmlbars/helpers";
+import { registerHelper } from "ember-htmlbars/helpers";
+
+var container, view;
+
+function appendView(view) {
+ run(function() { view.appendTo('#qunit-fixture'); });
+}
+
+function aliasHelper(params, hash, options, env) {
+ this.appendChild(View, {
+ isVirtual: true,
+ _morph: options.morph,
+ template: options.render,
+ _blockArguments: params
+ });
+}
+
+if (Ember.FEATURES.isEnabled('ember-htmlbars-block-params')) {
+
+QUnit.module("ember-htmlbars: block params", {
+ setup: function() {
+ registerHelper('alias', aliasHelper);
+
+ container = new Container();
+ container.optionsForType('component', { singleton: false });
+ container.optionsForType('view', { singleton: false });
+ container.optionsForType('template', { instantiate: false });
+ container.optionsForType('helper', { instantiate: false });
+ container.register('component-lookup:main', ComponentLookup);
+ },
+ teardown: function() {
+ delete helpers.alias;
+
+ run(container, 'destroy');
+
+ if (view) {
+ run(function() {
+ view.destroy();
+ });
+ }
+ }
+});
+
+test("basic block params usage", function() {
+ view = View.create({
+ committer: { name: "rwjblue" },
+ template: compile('{{#alias view.committer.name as |name|}}name: {{name}}, length: {{name.length}}{{/alias}}')
+ });
+
+ appendView(view);
+
+ equal(view.$().text(), "name: rwjblue, length: 7");
+
+ run(function() {
+ view.set('committer.name', "krisselden");
+ });
+
+ equal(view.$().text(), "name: krisselden, length: 10");
+});
+
+test("nested block params shadow correctly", function() {
+ view = View.create({
+ context: { name: "ebryn" },
+ committer1: { name: "trek" },
+ committer2: { name: "machty" },
+ template: compile(
+ '{{name}}' +
+ '{{#alias view.committer1.name as |name|}}' +
+ '[{{name}}' +
+ '{{#alias view.committer2.name as |name|}}' +
+ '[{{name}}]' +
+ '{{/alias}}' +
+ '{{name}}]' +
+ '{{/alias}}' +
+ '{{name}}' +
+ '{{#alias view.committer2.name as |name|}}' +
+ '[{{name}}' +
+ '{{#alias view.committer1.name as |name|}}' +
+ '[{{name}}]' +
+ '{{/alias}}' +
+ '{{name}}]' +
+ '{{/alias}}' +
+ '{{name}}'
+ )
+ });
+
+ appendView(view);
+
+ equal(view.$().text(), "ebryn[trek[machty]trek]ebryn[machty[trek]machty]ebryn");
+});
+
+test("components can yield values", function() {
+ container.register('template:components/x-alias', compile('{{yield param.name}}'));
+
+ view = View.create({
+ container: container,
+ context: { name: "ebryn" },
+ committer1: { name: "trek" },
+ committer2: { name: "machty" },
+ template: compile(
+ '{{name}}' +
+ '{{#x-alias param=view.committer1 as |name|}}' +
+ '[{{name}}' +
+ '{{#x-alias param=view.committer2 as |name|}}' +
+ '[{{name}}]' +
+ '{{/x-alias}}' +
+ '{{name}}]' +
+ '{{/x-alias}}' +
+ '{{name}}' +
+ '{{#x-alias param=view.committer2 as |name|}}' +
+ '[{{name}}' +
+ '{{#x-alias param=view.committer1 as |name|}}' +
+ '[{{name}}]' +
+ '{{/x-alias}}' +
+ '{{name}}]' +
+ '{{/x-alias}}' +
+ '{{name}}'
+ )
+ });
+
+ appendView(view);
+
+ equal(view.$().text(), "ebryn[trek[machty]trek]ebryn[machty[trek]machty]ebryn");
+});
+
+} | true |
Other | emberjs | ember.js | 15aaa9e41e11e5f9bf6fa702467d1fc03dbabbd7.json | Implement block params | packages/ember-views/lib/views/component.js | @@ -169,7 +169,7 @@ var Component = View.extend(TargetActionSupport, ComponentTemplateDeprecation, {
this._keywords.view.setSource(this);
},
- _yield: function(context, options, morph) {
+ _yield: function(context, options, morph, blockArguments) {
var view = options.data.view;
var parentView = this._parentView;
var template = get(this, 'template');
@@ -181,6 +181,7 @@ var Component = View.extend(TargetActionSupport, ComponentTemplateDeprecation, {
isVirtual: true,
tagName: '',
template: template,
+ _blockArguments: blockArguments,
_contextView: parentView,
_morph: morph,
context: get(parentView, 'context'), | true |
Other | emberjs | ember.js | 15aaa9e41e11e5f9bf6fa702467d1fc03dbabbd7.json | Implement block params | packages/ember-views/lib/views/view.js | @@ -807,7 +807,7 @@ var View = CoreView.extend({
if (template) {
var useHTMLBars = false;
if (Ember.FEATURES.isEnabled('ember-htmlbars')) {
- useHTMLBars = template.length === 3;
+ useHTMLBars = template.length >= 3;
}
if (useHTMLBars) {
@@ -821,6 +821,8 @@ var View = CoreView.extend({
}
},
+ _blockArguments: EMPTY_ARRAY,
+
templateForName: function(name, type) {
if (!name) { return; }
Ember.assert("templateNames are not allowed to contain periods: "+name, name.indexOf('.') === -1);
@@ -1096,12 +1098,12 @@ var View = CoreView.extend({
var useHTMLBars = false;
if (Ember.FEATURES.isEnabled('ember-htmlbars')) {
- useHTMLBars = template.length === 3;
+ useHTMLBars = template.length >= 3;
}
if (useHTMLBars) {
var env = Ember.merge(buildHTMLBarsDefaultEnv(), options);
- output = template(this, env, buffer.innerContextualElement());
+ output = template(this, env, buffer.innerContextualElement(), this._blockArguments);
} else {
output = template(context, options);
} | true |
Other | emberjs | ember.js | df4e1723ae290cd38876fd4e50b6157208db84d3.json | Add tests for attribute hook/helper.
* Add tests to confirm we are using `setAttribute` for some level of
escaping (equivalent to what we have today with `{{bind-attr}}`).
* Updated to ensure that rerenders happen in the `render` queue.
* Added dirty tracking to not needlessly update attributes.
* Move `attribute` and `concat` to separate `helpers/` files.
* Changed `lookupHelper` to be a default export. | packages/ember-htmlbars/lib/helpers/attribute.js | @@ -0,0 +1,29 @@
+import run from "ember-metal/run_loop";
+
+export function attributeHelper(params, hash, options, env) {
+ var dom = env.dom;
+ var name = params[0];
+ var value = params[1];
+
+ var isDirty, lastRenderedValue;
+
+ value.subscribe(function(lazyValue) {
+ isDirty = true;
+
+ run.schedule('render', this, function() {
+ var value = lazyValue.value();
+
+ if (isDirty) {
+ isDirty = false;
+ if (value !== lastRenderedValue) {
+ lastRenderedValue = value;
+ dom.setAttribute(options.element, name, value);
+ }
+ }
+ });
+ });
+
+ lastRenderedValue = value.value();
+
+ dom.setAttribute(options.element, name, lastRenderedValue);
+} | true |
Other | emberjs | ember.js | df4e1723ae290cd38876fd4e50b6157208db84d3.json | Add tests for attribute hook/helper.
* Add tests to confirm we are using `setAttribute` for some level of
escaping (equivalent to what we have today with `{{bind-attr}}`).
* Updated to ensure that rerenders happen in the `render` queue.
* Added dirty tracking to not needlessly update attributes.
* Move `attribute` and `concat` to separate `helpers/` files.
* Changed `lookupHelper` to be a default export. | packages/ember-htmlbars/lib/helpers/concat.js | @@ -0,0 +1,19 @@
+import Stream from "ember-metal/streams/stream";
+import {readArray} from "ember-metal/streams/read";
+
+export function concatHelper(params, hash, options, env) {
+ var stream = new Stream(function() {
+ return readArray(params).join('');
+ });
+
+ for (var i = 0, l = params.length; i < l; i++) {
+ var param = params[i];
+
+ if (param && param.isStream) {
+ param.subscribe(stream.notifyAll, stream);
+ }
+ }
+
+ return stream;
+}
+ | true |
Other | emberjs | ember.js | df4e1723ae290cd38876fd4e50b6157208db84d3.json | Add tests for attribute hook/helper.
* Add tests to confirm we are using `setAttribute` for some level of
escaping (equivalent to what we have today with `{{bind-attr}}`).
* Updated to ensure that rerenders happen in the `render` queue.
* Added dirty tracking to not needlessly update attributes.
* Move `attribute` and `concat` to separate `helpers/` files.
* Changed `lookupHelper` to be a default export. | packages/ember-htmlbars/lib/helpers/unbound.js | @@ -1,4 +1,4 @@
-import { lookupHelper } from 'ember-htmlbars/system/lookup-helper';
+import lookupHelper from 'ember-htmlbars/system/lookup-helper';
import { read } from 'ember-metal/streams/read';
import EmberError from "ember-metal/error";
import merge from "ember-metal/merge"; | true |
Other | emberjs | ember.js | df4e1723ae290cd38876fd4e50b6157208db84d3.json | Add tests for attribute hook/helper.
* Add tests to confirm we are using `setAttribute` for some level of
escaping (equivalent to what we have today with `{{bind-attr}}`).
* Updated to ensure that rerenders happen in the `render` queue.
* Added dirty tracking to not needlessly update attributes.
* Move `attribute` and `concat` to separate `helpers/` files.
* Changed `lookupHelper` to be a default export. | packages/ember-htmlbars/lib/hooks.js | @@ -1,5 +1,5 @@
import Ember from "ember-metal/core";
-import { lookupHelper } from "ember-htmlbars/system/lookup-helper";
+import lookupHelper from "ember-htmlbars/system/lookup-helper";
import { sanitizeOptionsForHelper } from "ember-htmlbars/system/sanitize-for-helper";
function streamifyArgs(view, params, hash, options, env, helper) { | true |
Other | emberjs | ember.js | df4e1723ae290cd38876fd4e50b6157208db84d3.json | Add tests for attribute hook/helper.
* Add tests to confirm we are using `setAttribute` for some level of
escaping (equivalent to what we have today with `{{bind-attr}}`).
* Updated to ensure that rerenders happen in the `render` queue.
* Added dirty tracking to not needlessly update attributes.
* Move `attribute` and `concat` to separate `helpers/` files.
* Changed `lookupHelper` to be a default export. | packages/ember-htmlbars/lib/main.js | @@ -14,6 +14,8 @@ import {
helper,
default as helpers
} from "ember-htmlbars/helpers";
+import { attributeHelper} from "ember-htmlbars/helpers/attribute";
+import { concatHelper } from "ember-htmlbars/helpers/concat";
import { bindHelper } from "ember-htmlbars/helpers/binding";
import { viewHelper } from "ember-htmlbars/helpers/view";
import { yieldHelper } from "ember-htmlbars/helpers/yield";
@@ -56,6 +58,8 @@ import "ember-htmlbars/system/bootstrap";
// Ember.Handlebars global if htmlbars is enabled
import "ember-htmlbars/compat";
+registerHelper('attribute', attributeHelper);
+registerHelper('concat', concatHelper);
registerHelper('bindHelper', bindHelper);
registerHelper('bind', bindHelper);
registerHelper('view', viewHelper); | true |
Other | emberjs | ember.js | df4e1723ae290cd38876fd4e50b6157208db84d3.json | Add tests for attribute hook/helper.
* Add tests to confirm we are using `setAttribute` for some level of
escaping (equivalent to what we have today with `{{bind-attr}}`).
* Updated to ensure that rerenders happen in the `render` queue.
* Added dirty tracking to not needlessly update attributes.
* Move `attribute` and `concat` to separate `helpers/` files.
* Changed `lookupHelper` to be a default export. | packages/ember-htmlbars/lib/system/lookup-helper.js | @@ -2,46 +2,11 @@ import Ember from "ember-metal/core";
import Cache from "ember-metal/cache";
import makeViewHelper from "ember-htmlbars/system/make-view-helper";
import HandlebarsCompatibleHelper from "ember-htmlbars/compat/helper";
-import Stream from "ember-metal/streams/stream";
-import {readArray} from "ember-metal/streams/read";
-import Helper from "ember-htmlbars/system/helper";
export var ISNT_HELPER_CACHE = new Cache(1000, function(key) {
return key.indexOf('-') === -1;
});
-export function attribute(params, hash, options, env) {
- var dom = env.dom;
- var name = params[0];
- var value = params[1];
-
- value.subscribe(function(lazyValue) {
- dom.setAttribute(options.element, name, lazyValue.value());
- });
-
- dom.setAttribute(options.element, name, value.value());
-}
-
-var attributeHelper = new Helper(attribute);
-
-export function concat(params, hash, options, env) {
- var stream = new Stream(function() {
- return readArray(params).join('');
- });
-
- for (var i = 0, l = params.length; i < l; i++) {
- var param = params[i];
-
- if (param && param.isStream) {
- param.subscribe(stream.notifyAll, stream);
- }
- }
-
- return stream;
-}
-
-var concatHelper = new Helper(concat);
-
/**
Used to lookup/resolve handlebars helpers. The lookup order is:
@@ -57,15 +22,7 @@ var concatHelper = new Helper(concat);
@param {String} name the name of the helper to lookup
@return {Handlebars Helper}
*/
-export function lookupHelper(name, view, env) {
- if (name === 'concat') {
- return concatHelper;
- }
-
- if (name === 'attribute') {
- return attributeHelper;
- }
-
+export default function lookupHelper(name, view, env) {
if (env.helpers[name]) {
return env.helpers[name];
} | true |
Other | emberjs | ember.js | df4e1723ae290cd38876fd4e50b6157208db84d3.json | Add tests for attribute hook/helper.
* Add tests to confirm we are using `setAttribute` for some level of
escaping (equivalent to what we have today with `{{bind-attr}}`).
* Updated to ensure that rerenders happen in the `render` queue.
* Added dirty tracking to not needlessly update attributes.
* Move `attribute` and `concat` to separate `helpers/` files.
* Changed `lookupHelper` to be a default export. | packages/ember-htmlbars/tests/helpers/attribute_test.js | @@ -0,0 +1,154 @@
+import EmberView from "ember-views/views/view";
+import run from "ember-metal/run_loop";
+import EmberObject from "ember-runtime/system/object";
+import { compile } from "htmlbars-compiler/compiler";
+import { equalInnerHTML } from "htmlbars-test-helpers";
+import { defaultEnv } from "ember-htmlbars";
+
+var view, originalSetAttribute, setAttributeCalls;
+var dom = defaultEnv.dom;
+
+function appendView(view) {
+ run(function() { view.appendTo('#qunit-fixture'); });
+}
+
+if (Ember.FEATURES.isEnabled('ember-htmlbars')) {
+ QUnit.module("ember-htmlbars: attribute", {
+ teardown: function(){
+ if (view) {
+ run(view, view.destroy);
+ }
+ }
+ });
+
+ test("property is output", function() {
+ view = EmberView.create({
+ context: {name: 'erik'},
+ template: compile("<div data-name={{name}}>Hi!</div>")
+ });
+ appendView(view);
+
+ equalInnerHTML(view.element, '<div data-name="erik">Hi!</div>', "attribute is output");
+ });
+
+ test("property value is directly added to attribute", function() {
+ view = EmberView.create({
+ context: {name: '"" data-foo="blah"'},
+ template: compile("<div data-name={{name}}>Hi!</div>")
+ });
+ appendView(view);
+
+ equalInnerHTML(view.element, '<div data-name=""" data-foo="blah"">Hi!</div>', "attribute is output");
+ });
+
+ test("path is output", function() {
+ view = EmberView.create({
+ context: {name: {firstName: 'erik'}},
+ template: compile("<div data-name={{name.firstName}}>Hi!</div>")
+ });
+ appendView(view);
+
+ equalInnerHTML(view.element, '<div data-name="erik">Hi!</div>', "attribute is output");
+ });
+
+ test("changed property updates", function() {
+ var context = EmberObject.create({name: 'erik'});
+ view = EmberView.create({
+ context: context,
+ template: compile("<div data-name={{name}}>Hi!</div>")
+ });
+ appendView(view);
+
+ equalInnerHTML(view.element, '<div data-name="erik">Hi!</div>', "precond - attribute is output");
+
+ run(context, context.set, 'name', 'mmun');
+
+ equalInnerHTML(view.element, '<div data-name="mmun">Hi!</div>', "attribute is updated output");
+ });
+
+ test("updates are scheduled in the render queue", function() {
+ expect(4);
+
+ var context = EmberObject.create({name: 'erik'});
+ view = EmberView.create({
+ context: context,
+ template: compile("<div data-name={{name}}>Hi!</div>")
+ });
+ appendView(view);
+
+ equalInnerHTML(view.element, '<div data-name="erik">Hi!</div>', "precond - attribute is output");
+
+ run(function() {
+ run.schedule('render', function() {
+ equalInnerHTML(view.element, '<div data-name="erik">Hi!</div>', "precond - attribute is not updated sync");
+ });
+
+ context.set('name', 'mmun');
+
+ run.schedule('render', function() {
+ equalInnerHTML(view.element, '<div data-name="mmun">Hi!</div>', "attribute is updated output");
+ });
+ });
+
+ equalInnerHTML(view.element, '<div data-name="mmun">Hi!</div>', "attribute is updated output");
+ });
+
+ QUnit.module('ember-htmlbars: {{attribute}} helper -- setAttribute', {
+ setup: function() {
+ originalSetAttribute = dom.setAttribute;
+ dom.setAttribute = function(element, name, value) {
+ setAttributeCalls.push([name, value]);
+
+ originalSetAttribute.call(dom, element, name, value);
+ };
+
+ setAttributeCalls = [];
+ },
+
+ teardown: function() {
+ dom.setAttribute = originalSetAttribute;
+
+ if (view) {
+ run(view, view.destroy);
+ }
+ }
+ });
+
+ test('calls setAttribute for new values', function() {
+ var context = EmberObject.create({name: 'erik'});
+ view = EmberView.create({
+ context: context,
+ template: compile("<div data-name={{name}}>Hi!</div>")
+ });
+ appendView(view);
+
+ run(context, context.set, 'name', 'mmun');
+
+ var expected = [
+ ['data-name', 'erik'],
+ ['data-name', 'mmun']
+ ];
+
+ deepEqual(setAttributeCalls, expected);
+ });
+
+ test('does not call setAttribute if the same value is set', function() {
+ var context = EmberObject.create({name: 'erik'});
+ view = EmberView.create({
+ context: context,
+ template: compile("<div data-name={{name}}>Hi!</div>")
+ });
+ appendView(view);
+
+ run(function() {
+ context.set('name', 'mmun');
+ context.set('name', 'erik');
+ });
+
+ var expected = [
+ ['data-name', 'erik']
+ ];
+
+ deepEqual(setAttributeCalls, expected);
+ });
+} | true |
Other | emberjs | ember.js | df4e1723ae290cd38876fd4e50b6157208db84d3.json | Add tests for attribute hook/helper.
* Add tests to confirm we are using `setAttribute` for some level of
escaping (equivalent to what we have today with `{{bind-attr}}`).
* Updated to ensure that rerenders happen in the `render` queue.
* Added dirty tracking to not needlessly update attributes.
* Move `attribute` and `concat` to separate `helpers/` files.
* Changed `lookupHelper` to be a default export. | packages/ember-htmlbars/tests/system/lookup-helper_test.js | @@ -1,8 +1,4 @@
-import {
- concat,
- attribute,
- lookupHelper
-} from "ember-htmlbars/system/lookup-helper";
+import lookupHelper from "ember-htmlbars/system/lookup-helper";
import ComponentLookup from "ember-views/component_lookup";
import Container from "container";
import Component from "ember-views/views/component";
@@ -24,18 +20,6 @@ function generateContainer() {
QUnit.module('ember-htmlbars: lookupHelper hook');
-test('returns concat when helper is `concat`', function() {
- var actual = lookupHelper('concat');
-
- equal(actual.helperFunction, concat, 'concat is a hard-coded helper');
-});
-
-test('returns attribute when helper is `attribute`', function() {
- var actual = lookupHelper('attribute');
-
- equal(actual.helperFunction, attribute, 'attribute is a hard-coded helper');
-});
-
test('looks for helpers in the provided `env.helpers`', function() {
var env = generateEnv({
'flubarb': function() { } | true |
Other | emberjs | ember.js | 73499f627f1c6151dc05ce38f82f1b4b8db578e4.json | Add asObject compat mode for ember-htmlbars. | packages/ember-htmlbars/lib/compat/precompile.js | @@ -1,3 +1,8 @@
-import { compile } from "htmlbars-compiler/compiler";
+import { compile, compileSpec } from "htmlbars-compiler/compiler";
-export default compile;
+export default function(string) {
+ var asObject = arguments[1] === undefined ? true : arguments[1];
+ var compileFunc = asObject ? compile : compileSpec;
+
+ return compileFunc(string);
+} | true |
Other | emberjs | ember.js | 73499f627f1c6151dc05ce38f82f1b4b8db578e4.json | Add asObject compat mode for ember-htmlbars. | packages/ember-htmlbars/tests/compat/precompile_test.js | @@ -4,27 +4,32 @@ var parse = EmberHandlebars.parse;
var template = 'Hello World';
var result;
-QUnit.module("Ember.Handlebars.precompileType");
+QUnit.module("ember-htmlbars: Ember.Handlebars.precompile");
-if (!Ember.FEATURES.isEnabled('ember-htmlbars')) {
- // precompile does not accept the same args with ember-htmlbars/system/compile
- // Do we need to support `asObject` param?
+var templateType;
+if (Ember.FEATURES.isEnabled('ember-htmlbars')) {
+ templateType = 'function';
+} else {
+ templateType = 'object';
+}
test("precompile creates an object when asObject isn't defined", function(){
result = precompile(template);
- equal(typeof(result), "object");
+ equal(typeof(result), templateType);
});
test("precompile creates an object when asObject is true", function(){
result = precompile(template, true);
- equal(typeof(result), "object");
+ equal(typeof(result), templateType);
});
test("precompile creates a string when asObject is false", function(){
result = precompile(template, false);
equal(typeof(result), "string");
});
+if (!Ember.FEATURES.isEnabled('ember-htmlbars')) {
+
test("precompile creates an object when passed an AST", function(){
var ast = parse(template);
result = precompile(ast); | true |
Other | emberjs | ember.js | 0ee52696fce0407bd73d34dd51e5813c1b0085f5.json | Move component invocation test into ember-htmlbars. | packages/ember-htmlbars/tests/integration/component_invocation_test.js | @@ -3,9 +3,16 @@ import Container from 'container/container';
import run from "ember-metal/run_loop";
import jQuery from "ember-views/system/jquery";
import EmberHandlebars from 'ember-handlebars-compiler';
+import htmlbarsCompile from "ember-htmlbars/system/compile";
import ComponentLookup from 'ember-views/component_lookup';
-var compile = EmberHandlebars.compile;
+var compile;
+if (Ember.FEATURES.isEnabled('ember-htmlbars')) {
+ compile = htmlbarsCompile;
+} else {
+ compile = EmberHandlebars.compile;
+}
+
var container, view;
QUnit.module('component - invocation', { | false |
Other | emberjs | ember.js | 65800fe09483bed3fc8adadd0678ee343f05a3e5.json | Allow usage of a string path with {{bind}} helper. | packages/ember-htmlbars/lib/helpers/binding.js | @@ -99,12 +99,16 @@ function bindHelper(params, hash, options, env) {
var property = params[0];
+ if (options.types[0] === 'string') {
+ property = this.getStream(property);
+ }
+
if (options.render) {
options.helperName = 'bind';
Ember.deprecate("The block form of bind, {{#bind foo}}{{/bind}}, has been deprecated and will be removed.");
bind.call(this, property, hash, options, env, false, exists);
} else {
- simpleBind.call(this, params, hash, options, env);
+ simpleBind.call(this, [property], hash, options, env);
}
}
| true |
Other | emberjs | ember.js | 65800fe09483bed3fc8adadd0678ee343f05a3e5.json | Allow usage of a string path with {{bind}} helper. | packages/ember-htmlbars/tests/helpers/bind_test.js | @@ -67,6 +67,25 @@ test("it should render the current value of a path on the context", function() {
equal(view.$().text(), "MWEEER", "value can be updated");
});
+test("it should render the current value of a string path on the context", function() {
+ view = EmberView.create({
+ template: compile('{{bind "foo.bar"}}'),
+ context: EmberObject.create({
+ foo: {
+ bar: "BORK"
+ }
+ })
+ });
+
+ appendView(view);
+
+ equal(view.$().text(), "BORK", "initial value is rendered");
+
+ run(view, view.set, 'context.foo.bar', 'MWEEER');
+
+ equal(view.$().text(), "MWEEER", "value can be updated");
+});
+
QUnit.module("ember-htmlbars: {{bind}} with a container, block forms", {
setup: function() {
container = new Container(); | true |
Other | emberjs | ember.js | 2ac6f1219e664a95d656f4656b63ac51aca65c97.json | Add Ember.Handlebars.get in ember-htmlbars/compat. | packages/ember-handlebars/lib/ext.js | @@ -21,27 +21,10 @@ import {
readArray,
readHash
} from "ember-metal/streams/read";
+import handlebarsGet from "ember-htmlbars/compat/handlebars-get";
var slice = [].slice;
-/**
- Lookup both on root and on window. If the path starts with
- a keyword, the corresponding object will be looked up in the
- template's data hash and used to resolve the path.
-
- @method get
- @for Ember.Handlebars
- @param {Object} root The object to look up the property on
- @param {String} path The path to be lookedup
- @param {Object} options The template's option hash
- @deprecated
-*/
-function handlebarsGet(root, path, options) {
- Ember.deprecate('Usage of Ember.Handlebars.get is deprecated, use a Component or Ember.Handlebars.makeBoundHelper instead.');
-
- return options.data.view.getStream(path).value();
-}
-
/**
handlebarsGetView resolves a view based on strings passed into a template.
For example: | true |
Other | emberjs | ember.js | 2ac6f1219e664a95d656f4656b63ac51aca65c97.json | Add Ember.Handlebars.get in ember-htmlbars/compat. | packages/ember-htmlbars/lib/compat/handlebars-get.js | @@ -0,0 +1,17 @@
+/**
+ Lookup both on root and on window. If the path starts with
+ a keyword, the corresponding object will be looked up in the
+ template's data hash and used to resolve the path.
+
+ @method get
+ @for Ember.Handlebars
+ @param {Object} root The object to look up the property on
+ @param {String} path The path to be lookedup
+ @param {Object} options The template's option hash
+ @deprecated
+*/
+export default function handlebarsGet(root, path, options) {
+ Ember.deprecate('Usage of Ember.Handlebars.get is deprecated, use a Component or Ember.Handlebars.makeBoundHelper instead.');
+
+ return options.data.view.getStream(path).value();
+} | true |
Other | emberjs | ember.js | 2ac6f1219e664a95d656f4656b63ac51aca65c97.json | Add Ember.Handlebars.get in ember-htmlbars/compat. | packages/ember-htmlbars/tests/compat/handlebars_get_test.js | @@ -3,18 +3,27 @@ import _MetamorphView from "ember-views/views/metamorph_view";
import EmberView from "ember-views/views/view";
import run from "ember-metal/run_loop";
import EmberHandlebars from "ember-handlebars";
-import { handlebarsGet } from "ember-handlebars/ext";
+import handlebarsGet from "ember-htmlbars/compat/handlebars-get";
import Container from "ember-runtime/system/container";
-var compile = EmberHandlebars.compile;
+import EmberHandlebars from "ember-handlebars";
+import htmlbarsCompile from "ember-htmlbars/system/compile";
+
+var compile;
+if (Ember.FEATURES.isEnabled('ember-htmlbars')) {
+ compile = htmlbarsCompile;
+} else {
+ compile = EmberHandlebars.compile;
+}
+
var originalLookup = Ember.lookup;
var TemplateTests, container, lookup, view;
function appendView() {
run(view, 'appendTo', '#qunit-fixture');
}
-QUnit.module("Ember.Handlebars.get", {
+QUnit.module("ember-htmlbars: Ember.Handlebars.get", {
setup: function() {
Ember.lookup = lookup = {};
container = new Container(); | true |
Other | emberjs | ember.js | aceb1d6bd1cf3a40649241112f81a811eb7c1373.json | Add HTMLBars version of `makeBoundHelper`. | packages/ember-htmlbars/lib/compat/make-bound-helper.js | @@ -0,0 +1,121 @@
+import Ember from "ember-metal/core"; // Ember.FEATURES, Ember.assert, Ember.Handlebars, Ember.lookup
+import { IS_BINDING } from "ember-metal/mixin";
+import simpleBind from "ember-htmlbars/system/simple-bind";
+import merge from "ember-metal/merge";
+import Helper from "ember-htmlbars/system/helper";
+
+import Stream from "ember-metal/streams/stream";
+import {
+ readArray,
+ readHash
+} from "ember-metal/streams/read";
+
+/**
+ A helper function used by `registerBoundHelper`. Takes the
+ provided Handlebars helper function fn and returns it in wrapped
+ bound helper form.
+
+ The main use case for using this outside of `registerBoundHelper`
+ is for registering helpers on the container:
+
+ ```js
+ var boundHelperFn = Ember.Handlebars.makeBoundHelper(function(word) {
+ return word.toUpperCase();
+ });
+
+ container.register('helper:my-bound-helper', boundHelperFn);
+ ```
+
+ In the above example, if the helper function hadn't been wrapped in
+ `makeBoundHelper`, the registered helper would be unbound.
+
+ @method makeBoundHelper
+ @for Ember.Handlebars
+ @param {Function} function
+ @param {String} dependentKeys*
+ @since 1.2.0
+*/
+export default function makeBoundHelper(fn, compatMode) {
+ var dependentKeys = [];
+ for (var i = 1; i < arguments.length; i++) {
+ dependentKeys.push(arguments[i]);
+ }
+
+ function helperFunc(params, hash, options, env) {
+ var view = this;
+ var numParams = params.length;
+
+ Ember.assert("registerBoundHelper-generated helpers do not support use with Handlebars blocks.", !options.render);
+
+ for (var prop in hash) {
+ if (IS_BINDING.test(prop)) {
+ hash[prop.slice(0, -7)] = view.getStream(hash[prop]);
+ delete hash[prop];
+ }
+ }
+
+ function valueFn() {
+ var args = readArray(params);
+
+ args.push({
+ hash: readHash(hash),
+ data: { properties: options._raw.params }
+ });
+ return fn.apply(view, args);
+ }
+
+ if (env.data.isUnbound) {
+ return valueFn();
+ } else {
+ var lazyValue = new Stream(valueFn);
+ var bindOptions = {
+ escaped: !hash.unescaped,
+ morph: options.morph
+ };
+
+ simpleBind.call(this, [lazyValue], {}, bindOptions);
+
+ var param;
+
+ for (i = 0; i < numParams; i++) {
+ param = params[i];
+ if (param && param.isStream) {
+ param.subscribe(lazyValue.notify, lazyValue);
+ }
+ }
+
+ for (prop in hash) {
+ param = hash[prop];
+ if (param && param.isStream) {
+ param.subscribe(lazyValue.notify, lazyValue);
+ }
+ }
+
+ if (numParams > 0) {
+ var firstParam = params[0];
+ // Only bother with subscriptions if the first argument
+ // is a stream itself, and not a primitive.
+ if (firstParam && firstParam.isStream) {
+ var onDependentKeyNotify = function onDependentKeyNotify(stream) {
+ stream.value();
+ lazyValue.notify();
+ };
+ for (i = 0; i < dependentKeys.length; i++) {
+ var childParam = firstParam.get(dependentKeys[i]);
+ childParam.value();
+ childParam.subscribe(onDependentKeyNotify);
+ }
+ }
+ }
+ }
+ }
+
+ function preprocessArguments(view, params, hash, options, env) {
+ options._raw = {
+ params: params.slice(),
+ hash: merge({}, hash)
+ };
+ }
+
+ return new Helper(helperFunc, preprocessArguments);
+} | true |
Other | emberjs | ember.js | aceb1d6bd1cf3a40649241112f81a811eb7c1373.json | Add HTMLBars version of `makeBoundHelper`. | packages/ember-htmlbars/lib/compat/register-bound-helper.js | @@ -0,0 +1,125 @@
+/**
+@module ember
+@submodule ember-htmlbars
+*/
+
+import helpers from "ember-htmlbars/helpers";
+import makeBoundHelper from "ember-htmlbars/compat/make-bound-helper";
+
+var slice = [].slice;
+
+/**
+ Register a bound handlebars helper. Bound helpers behave similarly to regular
+ handlebars helpers, with the added ability to re-render when the underlying data
+ changes.
+
+ ## Simple example
+
+ ```javascript
+ Ember.Handlebars.registerBoundHelper('capitalize', function(value) {
+ return Ember.String.capitalize(value);
+ });
+ ```
+
+ The above bound helper can be used inside of templates as follows:
+
+ ```handlebars
+ {{capitalize name}}
+ ```
+
+ In this case, when the `name` property of the template's context changes,
+ the rendered value of the helper will update to reflect this change.
+
+ ## Example with options
+
+ Like normal handlebars helpers, bound helpers have access to the options
+ passed into the helper call.
+
+ ```javascript
+ Ember.Handlebars.registerBoundHelper('repeat', function(value, options) {
+ var count = options.hash.count;
+ var a = [];
+ while(a.length < count) {
+ a.push(value);
+ }
+ return a.join('');
+ });
+ ```
+
+ This helper could be used in a template as follows:
+
+ ```handlebars
+ {{repeat text count=3}}
+ ```
+
+ ## Example with bound options
+
+ Bound hash options are also supported. Example:
+
+ ```handlebars
+ {{repeat text count=numRepeats}}
+ ```
+
+ In this example, count will be bound to the value of
+ the `numRepeats` property on the context. If that property
+ changes, the helper will be re-rendered.
+
+ ## Example with extra dependencies
+
+ The `Ember.Handlebars.registerBoundHelper` method takes a variable length
+ third parameter which indicates extra dependencies on the passed in value.
+ This allows the handlebars helper to update when these dependencies change.
+
+ ```javascript
+ Ember.Handlebars.registerBoundHelper('capitalizeName', function(value) {
+ return value.get('name').toUpperCase();
+ }, 'name');
+ ```
+
+ ## Example with multiple bound properties
+
+ `Ember.Handlebars.registerBoundHelper` supports binding to
+ multiple properties, e.g.:
+
+ ```javascript
+ Ember.Handlebars.registerBoundHelper('concatenate', function() {
+ var values = Array.prototype.slice.call(arguments, 0, -1);
+ return values.join('||');
+ });
+ ```
+
+ Which allows for template syntax such as `{{concatenate prop1 prop2}}` or
+ `{{concatenate prop1 prop2 prop3}}`. If any of the properties change,
+ the helper will re-render. Note that dependency keys cannot be
+ using in conjunction with multi-property helpers, since it is ambiguous
+ which property the dependent keys would belong to.
+
+ ## Use with unbound helper
+
+ The `{{unbound}}` helper can be used with bound helper invocations
+ to render them in their unbound form, e.g.
+
+ ```handlebars
+ {{unbound capitalize name}}
+ ```
+
+ In this example, if the name property changes, the helper
+ will not re-render.
+
+ ## Use with blocks not supported
+
+ Bound helpers do not support use with Handlebars blocks or
+ the addition of child views of any kind.
+
+ @method registerBoundHelper
+ @for Ember.Handlebars
+ @param {String} name
+ @param {Function} function
+ @param {String} dependentKeys*
+*/
+export default function registerBoundHelper(name, fn) {
+ var boundHelperArgs = slice.call(arguments, 1);
+ var boundFn = makeBoundHelper.apply(this, boundHelperArgs);
+
+ helpers[name] = boundFn;
+} | true |
Other | emberjs | ember.js | aceb1d6bd1cf3a40649241112f81a811eb7c1373.json | Add HTMLBars version of `makeBoundHelper`. | packages/ember-htmlbars/lib/helpers.js | @@ -75,9 +75,7 @@ export function helper(name, value) {
if (View.detect(value)) {
helpers[name] = makeViewHelper(value);
} else {
- // HTMLBars TODO: Support bound helpers
- // EmberHandlebars.registerBoundHelper.apply(null, arguments);
- throw new Error('unimplemented');
+ throw new Error('registerBoundHelper not implemented yet.');
}
}
| true |
Other | emberjs | ember.js | aceb1d6bd1cf3a40649241112f81a811eb7c1373.json | Add HTMLBars version of `makeBoundHelper`. | packages/ember-htmlbars/lib/helpers/binding.js | @@ -7,9 +7,9 @@ import isNone from 'ember-metal/is_none';
import run from "ember-metal/run_loop";
import { get } from "ember-metal/property_get";
import SimpleStream from "ember-metal/streams/simple";
+import simpleBind from "ember-htmlbars/system/simple-bind";
import BoundView from "ember-views/views/bound_view";
-import SimpleBoundView from "ember-views/views/simple_bound_view";
function exists(value) {
return !isNone(value);
@@ -71,22 +71,6 @@ function bind(property, hash, options, env, preserveContext, shouldDisplay, valu
}));
}
-function simpleBind(params, options, env) {
- var lazyValue = params[0];
-
- var view = new SimpleBoundView(
- lazyValue, options.escaped
- );
-
- view._parentView = this;
- view._morph = options.morph;
- this.appendChild(view);
-
- lazyValue.subscribe(this._wrapAsScheduled(function() {
- run.scheduleOnce('render', view, 'rerender');
- }));
-}
-
/**
`bind` can be used to display a value, then update that value if it
changes. For example, if you wanted to print the `title` property of
@@ -120,12 +104,11 @@ function bindHelper(params, hash, options, env) {
Ember.deprecate("The block form of bind, {{#bind foo}}{{/bind}}, has been deprecated and will be removed.");
bind.call(this, property, hash, options, env, false, exists);
} else {
- simpleBind.call(this, params, options, env);
+ simpleBind.call(this, params, hash, options, env);
}
}
export {
bind,
- simpleBind,
bindHelper
}; | true |
Other | emberjs | ember.js | aceb1d6bd1cf3a40649241112f81a811eb7c1373.json | Add HTMLBars version of `makeBoundHelper`. | packages/ember-htmlbars/lib/system/simple-bind.js | @@ -0,0 +1,16 @@
+import run from "ember-metal/run_loop";
+import SimpleBoundView from "ember-views/views/simple_bound_view";
+
+export default function simpleBind(params, hash, options, env) {
+ var lazyValue = params[0];
+
+ var view = new SimpleBoundView(lazyValue, options.escaped);
+
+ view._parentView = this;
+ view._morph = options.morph;
+ this.appendChild(view);
+
+ lazyValue.subscribe(this._wrapAsScheduled(function() {
+ run.scheduleOnce('render', view, 'rerender');
+ }));
+} | true |
Other | emberjs | ember.js | aceb1d6bd1cf3a40649241112f81a811eb7c1373.json | Add HTMLBars version of `makeBoundHelper`. | packages/ember-htmlbars/tests/compat/make_bound_helper_test.js | @@ -10,7 +10,23 @@ import { get } from "ember-metal/property_get";
import { set } from "ember-metal/property_set";
import EmberHandlebars from "ember-handlebars-compiler";
-var compile = EmberHandlebars.compile;
+import htmlbarsHelpers from "ember-htmlbars/helpers";
+import htmlbarsRegisterBoundHelper from "ember-htmlbars/compat/register-bound-helper";
+
+import EmberHandlebars from "ember-handlebars";
+import htmlbarsCompile from "ember-htmlbars/system/compile";
+
+var compile, helpers, helper;
+if (Ember.FEATURES.isEnabled('ember-htmlbars')) {
+ compile = htmlbarsCompile;
+ helpers = htmlbarsHelpers;
+ helper = htmlbarsRegisterBoundHelper;
+} else {
+ compile = EmberHandlebars.compile;
+ helpers = EmberHandlebars.helpers;
+ helper = EmberHandlebars.helper;
+}
+
var view;
@@ -21,7 +37,7 @@ function appendView() {
}
function registerRepeatHelper() {
- EmberHandlebars.helper('repeat', function(value, options) {
+ helper('repeat', function(value, options) {
var count = options.hash.count;
var a = [];
while(a.length < count) {
@@ -31,7 +47,7 @@ function registerRepeatHelper() {
});
}
-QUnit.module("Handlebars bound helpers", {
+QUnit.module("ember-htmlbars: makeBoundHelper", {
setup: function() {
},
teardown: function() {
@@ -60,7 +76,7 @@ test("primitives should work correctly [DEPRECATED]", function() {
});
test("should update bound helpers when properties change", function() {
- EmberHandlebars.helper('capitalize', function(value) {
+ helper('capitalize', function(value) {
return value.toUpperCase();
});
@@ -81,7 +97,7 @@ test("should update bound helpers when properties change", function() {
});
test("should allow for computed properties with dependencies", function() {
- EmberHandlebars.helper('capitalizeName', function(value) {
+ helper('capitalizeName', function(value) {
return get(value, 'name').toUpperCase();
}, 'name');
@@ -120,7 +136,7 @@ test("bound helpers should support options", function() {
});
test("bound helpers should support keywords", function() {
- EmberHandlebars.helper('capitalize', function(value) {
+ helper('capitalize', function(value) {
return value.toUpperCase();
});
@@ -135,7 +151,7 @@ test("bound helpers should support keywords", function() {
});
test("bound helpers should support global paths [DEPRECATED]", function() {
- EmberHandlebars.helper('capitalize', function(value) {
+ helper('capitalize', function(value) {
return value.toUpperCase();
});
@@ -153,7 +169,7 @@ test("bound helpers should support global paths [DEPRECATED]", function() {
});
test("bound helper should support this keyword", function() {
- EmberHandlebars.helper('capitalize', function(value) {
+ helper('capitalize', function(value) {
return get(value, 'text').toUpperCase();
});
@@ -224,13 +240,13 @@ test("bound helpers should support unquoted values as bound options", function()
test("bound helpers should support multiple bound properties", function() {
- EmberHandlebars.helper('concat', function() {
+ helper('combine', function() {
return [].slice.call(arguments, 0, -1).join('');
});
view = EmberView.create({
controller: EmberObject.create({thing1: 'ZOID', thing2: 'BERG'}),
- template: compile('{{concat thing1 thing2}}')
+ template: compile('{{combine thing1 thing2}}')
});
appendView();
@@ -254,7 +270,7 @@ test("bound helpers should support multiple bound properties", function() {
});
test("bound helpers should expose property names in options.data.properties", function() {
- EmberHandlebars.helper('echo', function() {
+ helper('echo', function() {
var options = arguments[arguments.length - 1];
var values = [].slice.call(arguments, 0, -1);
var a = [];
@@ -282,7 +298,7 @@ test("bound helpers should expose property names in options.data.properties", fu
});
test("bound helpers can be invoked with zero args", function() {
- EmberHandlebars.helper('troll', function(options) {
+ helper('troll', function(options) {
return options.hash.text || "TROLOLOL";
});
@@ -320,7 +336,7 @@ test("should observe dependent keys passed to registerBoundHelper", function() {
})
});
- EmberHandlebars.registerBoundHelper('fullName', function(value){
+ helper('fullName', function(value){
return [
value.get('firstName'),
value.get('lastName'),
@@ -343,12 +359,12 @@ test("should observe dependent keys passed to registerBoundHelper", function() {
equal(view.$().text(), 'Tom Owen 1692', 'render the helper after path change');
} finally {
- delete EmberHandlebars.helpers['fullName'];
+ delete helpers['fullName'];
}
});
test("shouldn't treat raw numbers as bound paths", function() {
- EmberHandlebars.helper('sum', function(a, b) {
+ helper('sum', function(a, b) {
return a + b;
});
@@ -368,14 +384,14 @@ test("shouldn't treat raw numbers as bound paths", function() {
test("shouldn't treat quoted strings as bound paths", function() {
var helperCount = 0;
- EmberHandlebars.helper('concat', function(a, b, opt) {
+ helper('combine', function(a, b, opt) {
helperCount++;
return a + b;
});
view = EmberView.create({
controller: EmberObject.create({word: "jerkwater", loo: "unused"}),
- template: compile("{{concat word 'loo'}} {{concat '' word}} {{concat 'will' \"didi\"}}")
+ template: compile("{{combine word 'loo'}} {{combine '' word}} {{combine 'will' \"didi\"}}")
});
appendView();
@@ -391,7 +407,7 @@ test("shouldn't treat quoted strings as bound paths", function() {
});
test("bound helpers can handle nulls in array (with primitives) [DEPRECATED]", function() {
- EmberHandlebars.helper('reverse', function(val) {
+ helper('reverse', function(val) {
return val ? val.split('').reverse().join('') : "NOPE";
});
@@ -417,7 +433,7 @@ test("bound helpers can handle nulls in array (with primitives) [DEPRECATED]", f
});
test("bound helpers can handle nulls in array (with objects)", function() {
- EmberHandlebars.helper('print-foo', function(val) {
+ helper('print-foo', function(val) {
return val ? get(val, 'foo') : "NOPE";
});
@@ -441,7 +457,7 @@ test("bound helpers can handle nulls in array (with objects)", function() {
test("bound helpers can handle `this` keyword when it's a non-object", function() {
- EmberHandlebars.helper("shout", function(value) {
+ helper("shout", function(value) {
return value + '!';
});
@@ -468,13 +484,13 @@ test("bound helpers can handle `this` keyword when it's a non-object", function(
});
test("should have correct argument types", function() {
- EmberHandlebars.helper('getType', function(value) {
+ helper('getType', function(value) {
return typeof value;
});
view = EmberView.create({
controller: EmberObject.create(),
- template: EmberHandlebars.compile('{{getType null}}, {{getType undefProp}}, {{getType "string"}}, {{getType 1}}, {{getType}}')
+ template: compile('{{getType null}}, {{getType undefProp}}, {{getType "string"}}, {{getType 1}}, {{getType}}')
});
appendView(); | true |
Other | emberjs | ember.js | aceb1d6bd1cf3a40649241112f81a811eb7c1373.json | Add HTMLBars version of `makeBoundHelper`. | packages/ember-htmlbars/tests/helpers/unbound_test.js | @@ -15,17 +15,22 @@ import {
import Container from 'ember-runtime/system/container';
-import { makeBoundHelper } from 'ember-handlebars/ext';
+import {
+ makeBoundHelper as handlebarsMakeBoundHelper
+} from 'ember-handlebars/ext';
+import htmlbarsMakeBoundHelper from "ember-htmlbars/compat/make-bound-helper";
-var compile, helpers, registerBoundHelper;
+var compile, helpers, registerBoundHelper, makeBoundHelper;
if (Ember.FEATURES.isEnabled('ember-htmlbars')) {
compile = htmlbarsCompile;
registerBoundHelper = registerHTMLBarsHelper;
+ makeBoundHelper = htmlbarsMakeBoundHelper;
helpers = htmlbarsHelpers;
} else {
compile = EmberHandlebars.compile;
registerBoundHelper = EmberHandlebars.registerBoundHelper;
helpers = EmberHandlebars.helpers;
+ makeBoundHelper = handlebarsMakeBoundHelper;
}
function appendView(view) { | true |
Other | emberjs | ember.js | aceb1d6bd1cf3a40649241112f81a811eb7c1373.json | Add HTMLBars version of `makeBoundHelper`. | packages/ember/tests/helpers/helper_registration_test.js | @@ -3,14 +3,17 @@ import "ember";
import EmberHandlebars from "ember-handlebars";
import htmlbarsCompile from "ember-htmlbars/system/compile";
import htmlbarsHelpers from "ember-htmlbars/helpers";
+import htmlbarsMakeBoundHelper from "ember-htmlbars/compat/make-bound-helper";
-var compile, helpers;
+var compile, helpers, makeBoundHelper;
if (Ember.FEATURES.isEnabled('ember-htmlbars')) {
compile = htmlbarsCompile;
helpers = htmlbarsHelpers;
+ makeBoundHelper = htmlbarsMakeBoundHelper;
} else {
compile = EmberHandlebars.compile;
helpers = EmberHandlebars.helpers;
+ makeBoundHelper = EmberHandlebars.makeBoundHelper;
}
var App, container;
@@ -70,7 +73,6 @@ test("Unbound dashed helpers registered on the container can be late-invoked", f
ok(!helpers['x-borf'], "Container-registered helper doesn't wind up on global helpers hash");
});
-if (!Ember.FEATURES.isEnabled('ember-htmlbars')) {
// need to make `makeBoundHelper` for HTMLBars
test("Bound helpers registered on the container can be late-invoked", function() {
@@ -80,13 +82,17 @@ test("Bound helpers registered on the container can be late-invoked", function()
container.register('controller:application', Ember.Controller.extend({
foo: "alex"
}));
- container.register('helper:x-reverse', Ember.Handlebars.makeBoundHelper(reverseHelper));
+ container.register('helper:x-reverse', makeBoundHelper(reverseHelper));
});
equal(Ember.$('#wrapper').text(), "-- xela", "The bound helper was invoked from the container");
ok(!helpers['x-reverse'], "Container-registered helper doesn't wind up on global helpers hash");
});
+if (!Ember.FEATURES.isEnabled('ember-htmlbars')) {
+
+ // we have unit tests for this in ember-htmlbars/tests/system/lookup-helper
+ // and we are not going to recreate the handlebars helperMissing concept
test("Undashed helpers registered on the container can not (presently) be invoked", function() {
var realHelperMissing = helpers.helperMissing;
@@ -104,7 +110,7 @@ test("Undashed helpers registered on the container can not (presently) be invoke
container.register('helper:omg', function() {
return "OMG";
});
- container.register('helper:yorp', Ember.Handlebars.makeBoundHelper(function() {
+ container.register('helper:yorp', makeBoundHelper(function() {
return "YORP";
}));
}); | true |
Other | emberjs | ember.js | 82ce12a0e9a117141e0d8242f676747075ce7458.json | Add several tests to HTMLBars feature flag | packages/ember-htmlbars/tests/helpers/bind_attr_test.js | @@ -407,9 +407,6 @@ test("should be able to bind classes to globals with {{bind-attr class}} (DEPREC
ok(view.$('img').hasClass('is-open'), "sets classname to the dasherized value of the global property");
});
-// HTMLBars TODO: Needs {{#each}} helper
-if (!Ember.FEATURES.isEnabled('ember-htmlbars')) {
-
test("should be able to bind-attr to 'this' in an {{#each}} block [DEPRECATED]", function() {
expectDeprecation('Using the context switching form of {{each}} is deprecated. Please use the keyword form (`{{#each foo in bar}}`) instead. See http://emberjs.com/guides/deprecations/#toc_more-consistent-handlebars-scope for more details.');
@@ -465,8 +462,6 @@ test("should be able to bind-attr to var in {{#each var in list}} block", functi
ok(/three\.gif$/.test(images[1].src));
});
-}
-
test("should teardown observers from bind-attr on rerender", function() {
view = EmberView.create({
template: compile('<span {{bind-attr class="view.foo" name=view.foo}}>wat</span>'), | true |
Other | emberjs | ember.js | 82ce12a0e9a117141e0d8242f676747075ce7458.json | Add several tests to HTMLBars feature flag | packages/ember-htmlbars/tests/helpers/yield_test.js | @@ -81,8 +81,6 @@ test("block should work properly even when templates are not hard-coded", functi
});
-if (!Ember.FEATURES.isEnabled('ember-htmlbars')) {
-
test("templates should yield to block, when the yield is embedded in a hierarchy of virtual views", function() {
var TimesView = EmberView.extend({
layout: compile('<div class="times">{{#each item in view.index}}{{yield}}{{/each}}</div>'),
@@ -109,8 +107,6 @@ test("templates should yield to block, when the yield is embedded in a hierarchy
equal(view.$('div#container div.times-item').length, 5, 'times-item is embedded within wrapping container 5 times, as expected');
});
-}
-
test("templates should yield to block, when the yield is embedded in a hierarchy of non-virtual views", function() {
var NestingView = EmberView.extend({
layout: compile('{{#view tagName="div" classNames="nesting"}}{{yield}}{{/view}}') | true |
Other | emberjs | ember.js | 83209e5d909152cd13649b77b4b769d84445e1bc.json | Move argument special casing to the helpers.
Paves the way for Handlbars compat version of `registerHelper` and
`makeBoundHelper`. Also, cleans up troubling bits of `streamifyArgs`. | packages/ember-htmlbars/lib/helpers/each.js | @@ -189,6 +189,17 @@ function eachHelper(params, hash, options, env) {
return env.helpers.collection.call(this, [EachView], hash, options, env);
}
+eachHelper._preprocessArguments = function(view, params, hash, options, env) {
+ if (params.length === 3 && params[1] === "in") {
+ params.splice(0, 3, {
+ from: params[2],
+ to: params[0],
+ stream: view.getStream(params[2])
+ });
+ options.types.splice(0, 3, 'keyword');
+ }
+};
+
export {
EachView,
eachHelper | true |
Other | emberjs | ember.js | 83209e5d909152cd13649b77b4b769d84445e1bc.json | Move argument special casing to the helpers.
Paves the way for Handlbars compat version of `registerHelper` and
`makeBoundHelper`. Also, cleans up troubling bits of `streamifyArgs`. | packages/ember-htmlbars/lib/helpers/with.js | @@ -93,6 +93,18 @@ export function withHelper(params, hash, options, env) {
bind.call(this, source, hash, options, env, preserveContext, exists, undefined, undefined, WithView);
}
+withHelper._preprocessArguments = function(view, params, hash, options, env) {
+ if (params.length === 3 && params[1] === "as") {
+ params.splice(0, 3, {
+ from: params[0],
+ to: params[2],
+ stream: view.getStream(params[0])
+ });
+
+ options.types.splice(0, 3, 'keyword');
+ }
+};
+
function exists(value) {
return !isNone(value);
} | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.