Skip to content

Commit

Permalink
Change ternary syntax to double colon sytax
Browse files Browse the repository at this point in the history
The syntax to define class names for truthy and falsy values changed from isEnabled?enabled:disabled to isEnabled:enabled:disabled
  • Loading branch information
pangratz committed Jul 14, 2012
1 parent b7aa61c commit 6309f24
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
10 changes: 5 additions & 5 deletions packages/ember-handlebars/tests/handlebars_test.js
Expand Up @@ -1155,7 +1155,7 @@ test("{{view}} should evaluate class bindings set to global paths", function() {
});

view = Ember.View.create({
template: Ember.Handlebars.compile('{{view Ember.TextField class="unbound" classBinding="App.isGreat:great App.directClass App.isApp App.isEnabled?enabled:disabled"}}')
template: Ember.Handlebars.compile('{{view Ember.TextField class="unbound" classBinding="App.isGreat:great App.directClass App.isApp App.isEnabled:enabled:disabled"}}')
});

appendView();
Expand Down Expand Up @@ -1187,7 +1187,7 @@ test("{{view}} should evaluate class bindings set in the current context", funct
isEditable: true,
directClass: "view-direct",
isEnabled: true,
template: Ember.Handlebars.compile('{{view Ember.TextField class="unbound" classBinding="isEditable:editable directClass isView isEnabled?enabled:disabled"}}')
template: Ember.Handlebars.compile('{{view Ember.TextField class="unbound" classBinding="isEditable:editable directClass isView isEnabled:enabled:disabled"}}')
});

appendView();
Expand Down Expand Up @@ -1218,7 +1218,7 @@ test("{{view}} should evaluate class bindings set with either classBinding or cl
});

view = Ember.View.create({
template: Ember.Handlebars.compile('{{view Ember.TextField class="unbound" classBinding="App.isGreat:great App.isEnabled?enabled:disabled" classNameBindings="App.isGreat:really-great App.isEnabled?really-enabled:really-disabled"}}')
template: Ember.Handlebars.compile('{{view Ember.TextField class="unbound" classBinding="App.isGreat:great App.isEnabled:enabled:disabled" classNameBindings="App.isGreat:really-great App.isEnabled:really-enabled:really-disabled"}}')
});

appendView();
Expand Down Expand Up @@ -1572,7 +1572,7 @@ test("should not allow XSS injection via {{bindAttr}} with class", function() {
});

test("should be able to bind class attribute using ternary operator in {{bindAttr}}", function() {
var template = Ember.Handlebars.compile('<img {{bindAttr class="content.isDisabled?disabled:enabled"}} />');
var template = Ember.Handlebars.compile('<img {{bindAttr class="content.isDisabled:disabled:enabled"}} />');
var content = Ember.Object.create({
isDisabled: true
});
Expand All @@ -1596,7 +1596,7 @@ test("should be able to bind class attribute using ternary operator in {{bindAtt
});

test("should be able to add multiple classes using {{bindAttr class}}", function() {
var template = Ember.Handlebars.compile('<div {{bindAttr class="content.isAwesomeSauce content.isAlsoCool content.isAmazing:amazing :is-super-duper content.isEnabled?enabled:disabled"}}></div>');
var template = Ember.Handlebars.compile('<div {{bindAttr class="content.isAwesomeSauce content.isAlsoCool content.isAmazing:amazing :is-super-duper content.isEnabled:enabled:disabled"}}></div>');
var content = Ember.Object.create({
isAwesomeSauce: true,
isAlsoCool: true,
Expand Down
9 changes: 4 additions & 5 deletions packages/ember-views/lib/views/view.js
Expand Up @@ -1972,23 +1972,22 @@ Ember.View.reopen({

Ember.View.reopenClass({
_parsePropertyPath: function(path) {
var split = path.split(/\?|:/),
var split = path.split(/:/),
propertyPath = split[0],
className,
falsyClassName;

// check if the property is defined as prop?trueClass:falseClass
// check if the property is defined as prop:class or prop:trueClass:falseClass
if (split.length > 1) {
className = split[1];
if (split.length === 3) { falsyClassName = split[2]; }
}

var classNames = "";
if (className) {
classNames += ':' + className;
if (falsyClassName) {
classNames = '?' + className + ':' + falsyClassName;
} else {
classNames = ':' + className;
classNames += ':' + falsyClassName;
}
}

Expand Down
Expand Up @@ -12,7 +12,7 @@ test("should apply bound class names to the element", function() {
var view = Ember.View.create({
classNameBindings: ['priority', 'isUrgent', 'isClassified:classified',
'canIgnore', 'messages.count', 'messages.resent:is-resent', 'isNumber:is-number',
'isEnabled?enabled:disabled'],
'isEnabled:enabled:disabled'],

priority: 'high',
isUrgent: true,
Expand Down Expand Up @@ -46,7 +46,7 @@ test("should add, remove, or change class names if changed after element is crea
var view = Ember.View.create({
classNameBindings: ['priority', 'isUrgent', 'isClassified:classified',
'canIgnore', 'messages.count', 'messages.resent:is-resent',
'isEnabled?enabled:disabled'],
'isEnabled:enabled:disabled'],

priority: 'high',
isUrgent: true,
Expand Down
Expand Up @@ -28,10 +28,10 @@ test("className is extracted", function() {
});

test("falsyClassName is extracted", function() {
var parsed = Ember.View._parsePropertyPath("content.simpleProperty?class:falsyClass");
var parsed = Ember.View._parsePropertyPath("content.simpleProperty:class:falsyClass");

equal(parsed.path, "content.simpleProperty", "path is parsed correctly");
equal(parsed.className, "class", "className is extracted");
equal(parsed.falsyClassName, "falsyClass", "falsyClassName is extracted");
equal(parsed.classNames, "?class:falsyClass", "there is a classNames");
equal(parsed.classNames, ":class:falsyClass", "there is a classNames");
});

0 comments on commit 6309f24

Please sign in to comment.