OLD | NEW |
---|---|
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 Loading... | |
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 [allowPackageColonUrls] is set. | |
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, |
Jennifer Messerly
2014/02/03 19:09:32
instead of allowPackageColonUrls, is there a way w
Siggi Cherem (dart-lang)
2014/02/04 00:20:35
We could. This also gave me another idea. I can ch
Jennifer Messerly
2014/02/04 00:37:40
Love it!
| |
128 {bool allowPackageColonUrls: false}) { | |
123 if (url == null || url == '') return null; | 129 if (url == null || url == '') return null; |
124 var uri = Uri.parse(url); | 130 var uri = Uri.parse(url); |
125 var urlBuilder = path.url; | 131 var urlBuilder = path.url; |
126 if (uri.host != '' || uri.scheme != '' || urlBuilder.isAbsolute(url)) { | 132 if (uri.host != '' || uri.scheme != '' || urlBuilder.isAbsolute(url)) { |
133 if (allowPackageColonUrls && uri.scheme == 'package') { | |
134 var index = uri.path.indexOf('/'); | |
135 if (index != -1) { | |
136 return new AssetId(uri.path.substring(0, index), | |
137 'lib${uri.path.substring(index)}'); | |
138 } | |
139 } | |
140 | |
127 logger.error('absolute paths not allowed: "$url"', span: span); | 141 logger.error('absolute paths not allowed: "$url"', span: span); |
128 return null; | 142 return null; |
129 } | 143 } |
130 | 144 |
131 var targetPath = urlBuilder.normalize( | 145 var targetPath = urlBuilder.normalize( |
132 urlBuilder.join(urlBuilder.dirname(source.path), url)); | 146 urlBuilder.join(urlBuilder.dirname(source.path), url)); |
133 var segments = urlBuilder.split(targetPath); | 147 var segments = urlBuilder.split(targetPath); |
134 var sourceSegments = urlBuilder.split(source.path); | 148 var sourceSegments = urlBuilder.split(source.path); |
135 assert (sourceSegments.length > 0); | 149 assert (sourceSegments.length > 0); |
136 var topFolder = sourceSegments[0]; | 150 var topFolder = sourceSegments[0]; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 return builder.relative(builder.join('/', id.path), | 235 return builder.relative(builder.join('/', id.path), |
222 from: builder.join('/', builder.dirname(sourceId.path))); | 236 from: builder.join('/', builder.dirname(sourceId.path))); |
223 } | 237 } |
224 | 238 |
225 | 239 |
226 /** Convert system paths to asset paths (asset paths are posix style). */ | 240 /** Convert system paths to asset paths (asset paths are posix style). */ |
227 String _systemToAssetPath(String assetPath) { | 241 String _systemToAssetPath(String assetPath) { |
228 if (path.Style.platform != path.Style.windows) return assetPath; | 242 if (path.Style.platform != path.Style.windows) return assetPath; |
229 return path.posix.joinAll(path.split(assetPath)); | 243 return path.posix.joinAll(path.split(assetPath)); |
230 } | 244 } |
OLD | NEW |