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

Commit a630487

Browse files
technohippymhevery
authored andcommitted
fix(ng-pluralize): use ${..} to interpolate
See: #528 (comment) Closes #572
1 parent f5668e3 commit a630487

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

lib/core/interpolate.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
part of angular.core;
22

3-
String _startSymbol = '{{';
4-
String _endSymbol = '}}';
5-
int _startSymbolLength = _startSymbol.length;
6-
int _endSymbolLength = _endSymbol.length;
7-
83
class Interpolation {
94
final String template;
105
final List<String> seperators;
@@ -48,8 +43,13 @@ class Interpolate {
4843
* have embedded expression in order to return an interpolation function.
4944
* Strings with no embedded expression will return null for the
5045
* interpolation function.
46+
* - `startSymbol`: The symbol to start interpolation. '{{' by default.
47+
* - `endSymbol`: The symbol to end interpolation. '}}' by default.
5148
*/
52-
Interpolation call(String template, [bool mustHaveExpression = false]) {
49+
Interpolation call(String template, [bool mustHaveExpression = false,
50+
String startSymbol = '{{', String endSymbol = '}}']) {
51+
int startSymbolLength = startSymbol.length;
52+
int endSymbolLength = endSymbol.length;
5353
int startIndex;
5454
int endIndex;
5555
int index = 0;
@@ -61,13 +61,13 @@ class Interpolate {
6161
List<Getter> watchExpressions = [];
6262

6363
while(index < length) {
64-
if ( ((startIndex = template.indexOf(_startSymbol, index)) != -1) &&
65-
((endIndex = template.indexOf(_endSymbol, startIndex + _startSymbolLength)) != -1) ) {
64+
if ( ((startIndex = template.indexOf(startSymbol, index)) != -1) &&
65+
((endIndex = template.indexOf(endSymbol, startIndex + startSymbolLength)) != -1) ) {
6666
separators.add(template.substring(index, startIndex));
67-
exp = template.substring(startIndex + _startSymbolLength, endIndex);
67+
exp = template.substring(startIndex + startSymbolLength, endIndex);
6868
Expression expression = _parse(exp);
6969
watchExpressions.add(expression.eval);
70-
index = endIndex + _endSymbolLength;
70+
index = endIndex + endSymbolLength;
7171
hasInterpolation = true;
7272
} else {
7373
// we did not find anything, so we have to add the remainder to the chunks array

lib/directive/ng_pluralize.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ part of angular.directive;
6363
*
6464
* <ng-pluralize count="personCount" offset=2
6565
* when="{'0': 'Nobody is viewing.',
66-
* '1': '{{person1}} is viewing.',
67-
* '2': '{{person1}} and {{person2}} are viewing.',
68-
* 'one': '{{person1}}, {{person2}} and one other person are viewing.',
69-
* 'other': '{{person1}}, {{person2}} and {} other people are viewing.'}">
66+
* '1': '${person1} is viewing.',
67+
* '2': '${person1} and ${person2} are viewing.',
68+
* 'one': '${person1}, ${person2} and one other person are viewing.',
69+
* 'other': '${person1}, ${person2} and {} other people are viewing.'}">
7070
* </ng-pluralize>
7171
*
7272
* Notice that we are still using two plural categories(one, other), but we added
@@ -153,7 +153,7 @@ class NgPluralizeDirective {
153153
}
154154

155155
_setAndWatch(expression) {
156-
var interpolation = interpolate(expression);
156+
var interpolation = interpolate(expression, false, '\${', '}');
157157
interpolation.setter = (text) => element.text = text;
158158
interpolation.setter(expression);
159159
scope.$watchSet(interpolation.watchExpressions, interpolation.call);

test/directive/ng_pluralize_spec.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,18 @@ main() {
147147
var element = _.compile(
148148
"<ng-pluralize count='viewCount' offset='2' " +
149149
"when=\"{'0': 'Nobody is viewing.'," +
150-
"'1': '{{p1}} is viewing.'," +
151-
"'2': '{{p1}} and {{p2}} are viewing.'," +
152-
"'one': '{{p1}}, {{p2}} and one other person are viewing.'," +
153-
"'other': '{{p1}}, {{p2}} and {} other people are viewing.'}\">" +
150+
"'1': '\${p1} is viewing.'," +
151+
"'2': '\${p1} and \${p2} are viewing.'," +
152+
"'one': '\${p1}, \${p2} and one other person are viewing.'," +
153+
"'other': '\${p1}, \${p2} and {} other people are viewing.'}\">" +
154154
"</ng-pluralize>");
155155
var elementAlt = _.compile(
156156
"<ng-pluralize count='viewCount' offset='2' " +
157157
"when-0='Nobody is viewing.'" +
158-
"when-1='{{p1}} is viewing.'" +
159-
"when-2='{{p1}} and {{p2}} are viewing.'" +
160-
"when-one='{{p1}}, {{p2}} and one other person are viewing.'" +
161-
"when-other='{{p1}}, {{p2}} and {} other people are viewing.'>" +
158+
"when-1='\${p1} is viewing.'" +
159+
"when-2='\${p1} and \${p2} are viewing.'" +
160+
"when-one='\${p1}, \${p2} and one other person are viewing.'" +
161+
"when-other='\${p1}, \${p2} and {} other people are viewing.'>" +
162162
"</ng-pluralize>");
163163
_.rootScope.p1 = 'Igor';
164164
_.rootScope.p2 = 'Misko';

0 commit comments

Comments
 (0)