-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
108 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(''); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters