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

Commit

Permalink
fix(ng-pluralize): use ${..} to interpolate
Browse files Browse the repository at this point in the history
See: #528 (comment)

Closes #572
  • Loading branch information
technohippy authored and mhevery committed Feb 19, 2014
1 parent f5668e3 commit a630487
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
20 changes: 10 additions & 10 deletions lib/core/interpolate.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
part of angular.core;

String _startSymbol = '{{';
String _endSymbol = '}}';
int _startSymbolLength = _startSymbol.length;
int _endSymbolLength = _endSymbol.length;

class Interpolation {
final String template;
final List<String> seperators;
Expand Down Expand Up @@ -48,8 +43,13 @@ class Interpolate {
* have embedded expression in order to return an interpolation function.
* Strings with no embedded expression will return null for the
* interpolation function.
* - `startSymbol`: The symbol to start interpolation. '{{' by default.
* - `endSymbol`: The symbol to end interpolation. '}}' by default.
*/
Interpolation call(String template, [bool mustHaveExpression = false]) {
Interpolation call(String template, [bool mustHaveExpression = false,
String startSymbol = '{{', String endSymbol = '}}']) {
int startSymbolLength = startSymbol.length;
int endSymbolLength = endSymbol.length;
int startIndex;
int endIndex;
int index = 0;
Expand All @@ -61,13 +61,13 @@ class Interpolate {
List<Getter> watchExpressions = [];

while(index < length) {
if ( ((startIndex = template.indexOf(_startSymbol, index)) != -1) &&
((endIndex = template.indexOf(_endSymbol, startIndex + _startSymbolLength)) != -1) ) {
if ( ((startIndex = template.indexOf(startSymbol, index)) != -1) &&
((endIndex = template.indexOf(endSymbol, startIndex + startSymbolLength)) != -1) ) {
separators.add(template.substring(index, startIndex));
exp = template.substring(startIndex + _startSymbolLength, endIndex);
exp = template.substring(startIndex + startSymbolLength, endIndex);
Expression expression = _parse(exp);
watchExpressions.add(expression.eval);
index = endIndex + _endSymbolLength;
index = endIndex + endSymbolLength;
hasInterpolation = true;
} else {
// we did not find anything, so we have to add the remainder to the chunks array
Expand Down
10 changes: 5 additions & 5 deletions lib/directive/ng_pluralize.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ part of angular.directive;
*
* <ng-pluralize count="personCount" offset=2
* when="{'0': 'Nobody is viewing.',
* '1': '{{person1}} is viewing.',
* '2': '{{person1}} and {{person2}} are viewing.',
* 'one': '{{person1}}, {{person2}} and one other person are viewing.',
* 'other': '{{person1}}, {{person2}} and {} other people are viewing.'}">
* '1': '${person1} is viewing.',
* '2': '${person1} and ${person2} are viewing.',
* 'one': '${person1}, ${person2} and one other person are viewing.',
* 'other': '${person1}, ${person2} and {} other people are viewing.'}">
* </ng-pluralize>
*
* Notice that we are still using two plural categories(one, other), but we added
Expand Down Expand Up @@ -153,7 +153,7 @@ class NgPluralizeDirective {
}

_setAndWatch(expression) {
var interpolation = interpolate(expression);
var interpolation = interpolate(expression, false, '\${', '}');
interpolation.setter = (text) => element.text = text;
interpolation.setter(expression);
scope.$watchSet(interpolation.watchExpressions, interpolation.call);
Expand Down
16 changes: 8 additions & 8 deletions test/directive/ng_pluralize_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,18 @@ main() {
var element = _.compile(
"<ng-pluralize count='viewCount' offset='2' " +
"when=\"{'0': 'Nobody is viewing.'," +
"'1': '{{p1}} is viewing.'," +
"'2': '{{p1}} and {{p2}} are viewing.'," +
"'one': '{{p1}}, {{p2}} and one other person are viewing.'," +
"'other': '{{p1}}, {{p2}} and {} other people are viewing.'}\">" +
"'1': '\${p1} is viewing.'," +
"'2': '\${p1} and \${p2} are viewing.'," +
"'one': '\${p1}, \${p2} and one other person are viewing.'," +
"'other': '\${p1}, \${p2} and {} other people are viewing.'}\">" +
"</ng-pluralize>");
var elementAlt = _.compile(
"<ng-pluralize count='viewCount' offset='2' " +
"when-0='Nobody is viewing.'" +
"when-1='{{p1}} is viewing.'" +
"when-2='{{p1}} and {{p2}} are viewing.'" +
"when-one='{{p1}}, {{p2}} and one other person are viewing.'" +
"when-other='{{p1}}, {{p2}} and {} other people are viewing.'>" +
"when-1='\${p1} is viewing.'" +
"when-2='\${p1} and \${p2} are viewing.'" +
"when-one='\${p1}, \${p2} and one other person are viewing.'" +
"when-other='\${p1}, \${p2} and {} other people are viewing.'>" +
"</ng-pluralize>");
_.rootScope.p1 = 'Igor';
_.rootScope.p2 = 'Misko';
Expand Down

0 comments on commit a630487

Please sign in to comment.