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

Unified 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, 12 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 side-by-side diff with in-line comments
Download patch
Index: third_party/pkg/angular/lib/core/interpolate.dart
diff --git a/third_party/pkg/angular/lib/core/interpolate.dart b/third_party/pkg/angular/lib/core/interpolate.dart
new file mode 100644
index 0000000000000000000000000000000000000000..27b43053fb397243ff07c6be9fb92eeee8b1cfb4
--- /dev/null
+++ b/third_party/pkg/angular/lib/core/interpolate.dart
@@ -0,0 +1,83 @@
+part of angular.core;
+
+String _startSymbol = '{{';
+String _endSymbol = '}}';
+num _startSymbolLength = _startSymbol.length;
+num _endSymbolLength = _endSymbol.length;
+
+class Interpolation {
+ final String template;
+ final List<String> seperators;
+ final List<ParsedGetter> watchExpressions;
+ Function setter = (_) => _;
+
+ Interpolation(this.template, this.seperators, this.watchExpressions);
+
+ String call(List parts, [_, __]) {
+ var str = [];
+ for(var i = 0, ii = parts.length; i < ii; i++) {
+ str.add(seperators[i]);
+ var value = parts[i];
+ str.add(value == null ? '' : '$value');
+ }
+ str.add(seperators.last);
+ return setter(str.join(''));
+ }
+}
+
+/**
+ * Compiles a string with markup into an interpolation function. This service
+ * is used by the HTML [Compiler] service for data binding.
+ *
+ *
+ * var $interpolate = ...; // injected
+ * var exp = $interpolate('Hello {{name}}!');
+ * expect(exp({name:'Angular'}).toEqual('Hello Angular!');
+ */
+@NgInjectableService()
+class Interpolate {
+ final Parser _parse;
+
+ Interpolate(this._parse);
+
+ /**
+ * Compile markup text into interpolation function.
+ *
+ * - `text`: The markup text to interpolate in form `foo {{expr}} bar`.
+ * - `mustHaveExpression`: if set to true then the interpolation string must
+ * have embedded expression in order to return an interpolation function.
+ * Strings with no embedded expression will return null for the
+ * interpolation function.
+ */
+ Interpolation call(String template, [bool mustHaveExpression = false]) {
+ int startIndex;
+ int endIndex;
+ int index = 0;
+ int length = template.length;
+ bool hasInterpolation = false;
+ String exp;
+ List<String> separators = [];
+ List<ParsedGetter> watchExpressions = [];
+
+ while(index < length) {
+ 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);
+ watchExpressions.add((_parse(exp)..exp = exp).eval);
+ index = endIndex + _endSymbolLength;
+ hasInterpolation = true;
+ } else {
+ // we did not find anything, so we have to add the remainder to the chunks array
+ separators.add(template.substring(index));
+ index = length;
+ }
+ }
+ if (separators.length == watchExpressions.length) {
+ separators.add('');
+ }
+ if (!mustHaveExpression || hasInterpolation) {
+ return new Interpolation(template, separators, watchExpressions);
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698