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.transform.common; | 6 library polymer.src.transform.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 21 matching lines...) Expand all Loading... | |
32 } | 32 } |
33 } | 33 } |
34 return document; | 34 return document; |
35 } | 35 } |
36 | 36 |
37 /** Additional options used by polymer transformers */ | 37 /** Additional options used by polymer transformers */ |
38 class TransformOptions { | 38 class TransformOptions { |
39 String currentPackage; | 39 String currentPackage; |
40 List<String> entryPoints; | 40 List<String> entryPoints; |
41 | 41 |
42 TransformOptions([this.currentPackage, this.entryPoints]); | 42 TransformOptions([this.currentPackage, entryPoints]) |
43 : entryPoints = entryPoints == null ? null | |
44 : entryPoints.map(_systemToAssetPath).toList(); | |
43 | 45 |
44 /** Whether an asset with [id] is an entry point HTML file. */ | 46 /** Whether an asset with [id] is an entry point HTML file. */ |
45 bool isHtmlEntryPoint(AssetId id) { | 47 bool isHtmlEntryPoint(AssetId id) { |
46 if (id.extension != '.html') return false; | 48 if (id.extension != '.html') return false; |
47 | 49 |
48 // Note: [id.path] is a relative path from the root of a package. | 50 // Note: [id.path] is a relative path from the root of a package. |
49 if (!id.path.startsWith('web/') && | 51 if (currentPackage == null || entryPoints == null) { |
Siggi Cherem (dart-lang)
2013/09/12 22:11:29
this change is not needed, but I think it's better
| |
50 !id.path.startsWith('test/')) return false; | 52 return id.path.startsWith('web/') || id.path.startsWith('test/'); |
53 } | |
51 | 54 |
52 if (currentPackage == null || entryPoints == null) return true; | |
53 return id.package == currentPackage && entryPoints.contains(id.path); | 55 return id.package == currentPackage && entryPoints.contains(id.path); |
54 } | 56 } |
55 } | 57 } |
56 | 58 |
57 /** Mixin for polymer transformers. */ | 59 /** Mixin for polymer transformers. */ |
58 abstract class PolymerTransformer { | 60 abstract class PolymerTransformer { |
59 TransformOptions get options; | 61 TransformOptions get options; |
60 | 62 |
61 Future<Document> readPrimaryAsHtml(Transform transform) { | 63 Future<Document> readPrimaryAsHtml(Transform transform) { |
62 var asset = transform.primaryInput; | 64 var asset = transform.primaryInput; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 // Use relative urls only if it's possible. | 143 // Use relative urls only if it's possible. |
142 if (id.package != sourceId.package) { | 144 if (id.package != sourceId.package) { |
143 logger.error("don't know how to refer to $id from $sourceId"); | 145 logger.error("don't know how to refer to $id from $sourceId"); |
144 return null; | 146 return null; |
145 } | 147 } |
146 | 148 |
147 var builder = path.url; | 149 var builder = path.url; |
148 return builder.relative(builder.join('/', id.path), | 150 return builder.relative(builder.join('/', id.path), |
149 from: builder.join('/', builder.dirname(sourceId.path))); | 151 from: builder.join('/', builder.dirname(sourceId.path))); |
150 } | 152 } |
153 | |
154 | |
155 /** Convert system paths to asset paths (asset paths are posix style). */ | |
156 String _systemToAssetPath(String assetPath) { | |
157 if (path.Style.platform != path.Style.windows) return assetPath; | |
158 return path.posix.joinAll(path.split(assetPath)); | |
159 } | |
OLD | NEW |