| 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 | 9 |
| 10 import 'package:barback/barback.dart'; | 10 import 'package:barback/barback.dart'; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 71 |
| 72 Future<Document> readAsHtml(AssetId id, Transform transform) { | 72 Future<Document> readAsHtml(AssetId id, Transform transform) { |
| 73 var primaryId = transform.primaryInput.id; | 73 var primaryId = transform.primaryInput.id; |
| 74 var url = (id.package == primaryId.package) ? id.path | 74 var url = (id.package == primaryId.package) ? id.path |
| 75 : assetUrlFor(id, primaryId, transform.logger, allowAssetUrl: true); | 75 : assetUrlFor(id, primaryId, transform.logger, allowAssetUrl: true); |
| 76 return transform.readInputAsString(id).then((content) { | 76 return transform.readInputAsString(id).then((content) { |
| 77 return _parseHtml(content, url, transform.logger, | 77 return _parseHtml(content, url, transform.logger, |
| 78 checkDocType: options.isHtmlEntryPoint(id)); | 78 checkDocType: options.isHtmlEntryPoint(id)); |
| 79 }); | 79 }); |
| 80 } | 80 } |
| 81 |
| 82 Future<bool> assetExists(AssetId id, Transform transform) => |
| 83 transform.getInput(id).then((_) => true).catchError((_) => false); |
| 81 } | 84 } |
| 82 | 85 |
| 83 /** Create an [AssetId] for a [url] seen in the [source] asset. */ | 86 /** Create an [AssetId] for a [url] seen in the [source] asset. */ |
| 84 // TODO(sigmund): delete once this is part of barback (dartbug.com/12610) | 87 // TODO(sigmund): delete once this is part of barback (dartbug.com/12610) |
| 85 AssetId resolve(AssetId source, String url, TransformLogger logger, Span span) { | 88 AssetId resolve(AssetId source, String url, TransformLogger logger, Span span) { |
| 86 if (url == null || url == '') return null; | 89 if (url == null || url == '') return null; |
| 87 var uri = Uri.parse(url); | 90 var uri = Uri.parse(url); |
| 88 var urlBuilder = path.url; | 91 var urlBuilder = path.url; |
| 89 if (uri.host != '' || uri.scheme != '' || urlBuilder.isAbsolute(url)) { | 92 if (uri.host != '' || uri.scheme != '' || urlBuilder.isAbsolute(url)) { |
| 90 logger.error('absolute paths not allowed: "$url"', span); | 93 logger.error('absolute paths not allowed: "$url"', span); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 return builder.relative(builder.join('/', id.path), | 153 return builder.relative(builder.join('/', id.path), |
| 151 from: builder.join('/', builder.dirname(sourceId.path))); | 154 from: builder.join('/', builder.dirname(sourceId.path))); |
| 152 } | 155 } |
| 153 | 156 |
| 154 | 157 |
| 155 /** Convert system paths to asset paths (asset paths are posix style). */ | 158 /** Convert system paths to asset paths (asset paths are posix style). */ |
| 156 String _systemToAssetPath(String assetPath) { | 159 String _systemToAssetPath(String assetPath) { |
| 157 if (path.Style.platform != path.Style.windows) return assetPath; | 160 if (path.Style.platform != path.Style.windows) return assetPath; |
| 158 return path.posix.joinAll(path.split(assetPath)); | 161 return path.posix.joinAll(path.split(assetPath)); |
| 159 } | 162 } |
| OLD | NEW |