Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: third_party/pkg/angular/lib/core/interpolate.dart

Issue 124053002: Adding Angular and dependent packages for testing (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 part of angular.core;
2
3 String _startSymbol = '{{';
4 String _endSymbol = '}}';
5 num _startSymbolLength = _startSymbol.length;
6 num _endSymbolLength = _endSymbol.length;
7
8 class Interpolation {
9 final String template;
10 final List<String> seperators;
11 final List<ParsedGetter> watchExpressions;
12 Function setter = (_) => _;
13
14 Interpolation(this.template, this.seperators, this.watchExpressions);
15
16 String call(List parts, [_, __]) {
17 var str = [];
18 for(var i = 0, ii = parts.length; i < ii; i++) {
19 str.add(seperators[i]);
20 var value = parts[i];
21 str.add(value == null ? '' : '$value');
22 }
23 str.add(seperators.last);
24 return setter(str.join(''));
25 }
26 }
27
28 /**
29 * Compiles a string with markup into an interpolation function. This service
30 * is used by the HTML [Compiler] service for data binding.
31 *
32 *
33 * var $interpolate = ...; // injected
34 * var exp = $interpolate('Hello {{name}}!');
35 * expect(exp({name:'Angular'}).toEqual('Hello Angular!');
36 */
37 @NgInjectableService()
38 class Interpolate {
39 final Parser _parse;
40
41 Interpolate(this._parse);
42
43 /**
44 * Compile markup text into interpolation function.
45 *
46 * - `text`: The markup text to interpolate in form `foo {{expr}} bar`.
47 * - `mustHaveExpression`: if set to true then the interpolation string must
48 * have embedded expression in order to return an interpolation function.
49 * Strings with no embedded expression will return null for the
50 * interpolation function.
51 */
52 Interpolation call(String template, [bool mustHaveExpression = false]) {
53 int startIndex;
54 int endIndex;
55 int index = 0;
56 int length = template.length;
57 bool hasInterpolation = false;
58 String exp;
59 List<String> separators = [];
60 List<ParsedGetter> watchExpressions = [];
61
62 while(index < length) {
63 if ( ((startIndex = template.indexOf(_startSymbol, index)) != -1) &&
64 ((endIndex = template.indexOf(_endSymbol, startIndex + _startSymbolLe ngth)) != -1) ) {
65 separators.add(template.substring(index, startIndex));
66 exp = template.substring(startIndex + _startSymbolLength, endIndex);
67 watchExpressions.add((_parse(exp)..exp = exp).eval);
68 index = endIndex + _endSymbolLength;
69 hasInterpolation = true;
70 } else {
71 // we did not find anything, so we have to add the remainder to the chun ks array
72 separators.add(template.substring(index));
73 index = length;
74 }
75 }
76 if (separators.length == watchExpressions.length) {
77 separators.add('');
78 }
79 if (!mustHaveExpression || hasInterpolation) {
80 return new Interpolation(template, separators, watchExpressions);
81 }
82 }
83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698