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

Side by Side Diff: pkg/polymer/lib/src/build/common.dart

Issue 151893003: Use a transformer to initialize custom elements and call initMethod. This is the (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** Common methods used by transfomers. */ 5 /** Common methods used by transfomers. */
6 library polymer.src.build.common; 6 library polymer.src.build.common;
7 7
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:math' show min, max; 9 import 'dart:math' show min, max;
10 10
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 checkDocType: samePackage && options.isHtmlEntryPoint(id)); 110 checkDocType: samePackage && options.isHtmlEntryPoint(id));
111 }); 111 });
112 } 112 }
113 113
114 Future<bool> assetExists(AssetId id, Transform transform) => 114 Future<bool> assetExists(AssetId id, Transform transform) =>
115 transform.getInput(id).then((_) => true).catchError((_) => false); 115 transform.getInput(id).then((_) => true).catchError((_) => false);
116 116
117 String toString() => 'polymer ($runtimeType)'; 117 String toString() => 'polymer ($runtimeType)';
118 } 118 }
119 119
120 /** Create an [AssetId] for a [url] seen in the [source] asset. */ 120 /**
121 * Create an [AssetId] for a [url] seen in the [source] asset. By default this
122 * is used to resolve relative urls that occur in HTML assets, including
123 * cross-package urls of the form "packages/foo/bar.html". Dart-style "package:"
124 * urls are not resolved unless [source] is Dart file (has a .dart extension).
125 */
121 // TODO(sigmund): delete once this is part of barback (dartbug.com/12610) 126 // TODO(sigmund): delete once this is part of barback (dartbug.com/12610)
122 AssetId resolve(AssetId source, String url, TransformLogger logger, Span span) { 127 AssetId resolve(AssetId source, String url, TransformLogger logger, Span span) {
123 if (url == null || url == '') return null; 128 if (url == null || url == '') return null;
124 var uri = Uri.parse(url); 129 var uri = Uri.parse(url);
125 var urlBuilder = path.url; 130 var urlBuilder = path.url;
126 if (uri.host != '' || uri.scheme != '' || urlBuilder.isAbsolute(url)) { 131 if (uri.host != '' || uri.scheme != '' || urlBuilder.isAbsolute(url)) {
132 if (source.extension == '.dart' && uri.scheme == 'package') {
133 var index = uri.path.indexOf('/');
134 if (index != -1) {
135 return new AssetId(uri.path.substring(0, index),
136 'lib${uri.path.substring(index)}');
137 }
138 }
139
127 logger.error('absolute paths not allowed: "$url"', span: span); 140 logger.error('absolute paths not allowed: "$url"', span: span);
128 return null; 141 return null;
129 } 142 }
130 143
131 var targetPath = urlBuilder.normalize( 144 var targetPath = urlBuilder.normalize(
132 urlBuilder.join(urlBuilder.dirname(source.path), url)); 145 urlBuilder.join(urlBuilder.dirname(source.path), url));
133 var segments = urlBuilder.split(targetPath); 146 var segments = urlBuilder.split(targetPath);
134 var sourceSegments = urlBuilder.split(source.path); 147 var sourceSegments = urlBuilder.split(source.path);
135 assert (sourceSegments.length > 0); 148 assert (sourceSegments.length > 0);
136 var topFolder = sourceSegments[0]; 149 var topFolder = sourceSegments[0];
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 return builder.relative(builder.join('/', id.path), 234 return builder.relative(builder.join('/', id.path),
222 from: builder.join('/', builder.dirname(sourceId.path))); 235 from: builder.join('/', builder.dirname(sourceId.path)));
223 } 236 }
224 237
225 238
226 /** Convert system paths to asset paths (asset paths are posix style). */ 239 /** Convert system paths to asset paths (asset paths are posix style). */
227 String _systemToAssetPath(String assetPath) { 240 String _systemToAssetPath(String assetPath) {
228 if (path.Style.platform != path.Style.windows) return assetPath; 241 if (path.Style.platform != path.Style.windows) return assetPath;
229 return path.posix.joinAll(path.split(assetPath)); 242 return path.posix.joinAll(path.split(assetPath));
230 } 243 }
OLDNEW
« no previous file with comments | « pkg/polymer/example/canonicalization3/lib/b.dart ('k') | pkg/polymer/lib/src/build/script_compactor.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698