Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose {{concat}} helper publicly. #11264

Merged
merged 1 commit into from
Jun 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions packages/ember-htmlbars/lib/helpers/-concat.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
/** @private
This private helper is used by the legacy class bindings AST transformer
to concatenate class names together.
/**
Concatenates input params together.

Example:

```handlebars
{{some-component name=(concat firstName " " lastName)}}

{{! would pass name="<first name value> <last name value>" to the component}}
```

@public
@method concat
@for Ember.HTMLBars
*/
export default function concat(params, hash) {
return params.join(hash.separator);
export default function concat(params) {
return params.join('');
}
2 changes: 1 addition & 1 deletion packages/ember-htmlbars/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ if (Ember.FEATURES.isEnabled('ember-htmlbars-each-in')) {
}
registerHelper('-bind-attr-class', bindAttrClassHelper);
registerHelper('-normalize-class', normalizeClassHelper);
registerHelper('-concat', concatHelper);
registerHelper('concat', concatHelper);
registerHelper('-join-classes', joinClassesHelper);
registerHelper('-legacy-each-with-controller', legacyEachWithControllerHelper);
registerHelper('-legacy-each-with-keyword', legacyEachWithKeywordHelper);
Expand Down
87 changes: 87 additions & 0 deletions packages/ember-htmlbars/tests/helpers/concat-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import run from "ember-metal/run_loop";
import { Registry } from "ember-runtime/system/container";
import Component from "ember-views/views/component";
import compile from "ember-template-compiler/system/compile";

import { runAppend, runDestroy } from "ember-runtime/tests/utils";

var component, registry, container;

QUnit.module("ember-htmlbars: {{concat}} helper", {
setup() {
registry = new Registry();
container = registry.container();
registry.optionsForType('helper', { instantiate: false });
},

teardown() {
runDestroy(container);
runDestroy(component);
}
});

QUnit.test('concats provided params', function() {
component = Component.create({
container,

template: compile(`{{concat "foo" " " "bar" " " "baz"}}`)
});

runAppend(component);

equal(component.$().text(), 'foo bar baz');
});

QUnit.test('updates for bound params', function() {
component = Component.create({
container,

firstParam: 'one',
secondParam: 'two',

template: compile(`{{concat firstParam secondParam}}`)
});

runAppend(component);

equal(component.$().text(), 'onetwo');

run(function() {
component.set('firstParam', 'three');
});

equal(component.$().text(), 'threetwo');

run(function() {
component.set('secondParam', 'four');
});

equal(component.$().text(), 'threefour');
});

QUnit.test('can be used as a sub-expression', function() {
function eq([ actual, expected ]) {
return actual === expected;
}
eq.isHTMLBars = true;
registry.register('helper:x-eq', eq);

component = Component.create({
container,

firstParam: 'one',
secondParam: 'two',

template: compile(`{{#if (x-eq (concat firstParam secondParam) "onetwo")}}Truthy!{{else}}False{{/if}}`)
});

runAppend(component);

equal(component.$().text(), 'Truthy!');

run(function() {
component.set('firstParam', 'three');
});

equal(component.$().text(), 'False');
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ TransformOldClassBindingSyntax.prototype.transform = function TransformOldClassB

if (classPair) {
classValue.push(classPair.value);
classValue.push(b.string(' '));
} else {
classPair = b.pair('class', null);
node.hash.pairs.push(classPair);
Expand All @@ -54,8 +55,8 @@ TransformOldClassBindingSyntax.prototype.transform = function TransformOldClassB
}
});

let hash = b.hash([b.pair('separator', b.string(' '))]);
classPair.value = b.sexpr(b.string('-concat'), classValue, hash);
let hash = b.hash();
classPair.value = b.sexpr(b.string('concat'), classValue, hash);
});

return ast;
Expand Down Expand Up @@ -97,6 +98,7 @@ function buildSexprs(microsyntax, sexprs, b) {
}

sexprs.push(sexpr);
sexprs.push(b.string(' '));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function normalizeComponentAttributes(component, isAngleBracket, attrs) {
var existingStyle = normalized.style;

if (existingStyle) {
normalized.style = ['subexpr', '-concat', [existingStyle, hiddenStyle], ['separator', ' ']];
normalized.style = ['subexpr', 'concat', [existingStyle, ' ', hiddenStyle], [ ]];
} else {
normalized.style = hiddenStyle;
}
Expand Down