Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

fix(interpolate): Interpolation should use toString instead of json.stringify #64

Merged
merged 1 commit into from
Aug 1, 2013
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
4 changes: 2 additions & 2 deletions lib/interpolate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ num endSymbolLength = endSymbol.length;
class Interpolate {
Parser $parse;
ExceptionHandler $exceptionHandler;

Interpolate(Parser this.$parse, ExceptionHandler this.$exceptionHandler);

ParsedFn call(String text, [bool mustHaveExpression = false]) {
Expand Down Expand Up @@ -54,7 +54,7 @@ class Interpolate {
if (chunk == null) {
chunk = '';
} else if (!(chunk is String)) {
chunk = toJson(chunk);
chunk = '$chunk';
}
}
concat.add(chunk);
Expand Down
9 changes: 9 additions & 0 deletions test/interpolate_spec.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import "_specs.dart";

class ToStringableObject {
toString() => 'World';
}

main() {
describe('\$interpolate', () {

Expand Down Expand Up @@ -48,6 +52,11 @@ main() {
expect($interpolate("Hello {{'World' + foo()}}")($rootScope)).toEqual('Hello World');
}));

it('should use toString to conver objects to string', inject((Interpolate $interpolate, Scope $rootScope) {
$rootScope.obj = new ToStringableObject();
expect($interpolate("Hello, {{obj}}!")($rootScope)).toEqual('Hello, World!');
}));


describe('parseBindings', () {
it('should Parse Text With No Bindings', inject((Interpolate $interpolate) {
Expand Down