| 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 library barback.transformer; | 5 library barback.transformer; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'asset_id.dart'; | 9 import 'asset_id.dart'; |
| 10 import 'transform.dart'; | 10 import 'transform.dart'; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 /// | 52 /// |
| 53 /// A concrete example is dart2js. When you run dart2js, it will traverse | 53 /// A concrete example is dart2js. When you run dart2js, it will traverse |
| 54 /// all of the imports in your Dart source files and use the contents of all | 54 /// all of the imports in your Dart source files and use the contents of all |
| 55 /// of those to generate the final JS. However you still run dart2js "on" a | 55 /// of those to generate the final JS. However you still run dart2js "on" a |
| 56 /// single file: the entrypoint Dart file that has your `main()` method. | 56 /// single file: the entrypoint Dart file that has your `main()` method. |
| 57 /// This entrypoint file would be the primary input. | 57 /// This entrypoint file would be the primary input. |
| 58 /// | 58 /// |
| 59 /// If this is not overridden, defaults to allow any asset whose extension | 59 /// If this is not overridden, defaults to allow any asset whose extension |
| 60 /// matches one of the ones returned by [allowedExtensions]. If *that* is | 60 /// matches one of the ones returned by [allowedExtensions]. If *that* is |
| 61 /// not overridden, allows all assets. | 61 /// not overridden, allows all assets. |
| 62 Future<bool> isPrimary(AssetId id) { | 62 /// |
| 63 /// This may return a `Future<bool>` or, if it's entirely synchronous, a |
| 64 /// `bool`. |
| 65 isPrimary(AssetId id) { |
| 63 // Allow all files if [primaryExtensions] is not overridden. | 66 // Allow all files if [primaryExtensions] is not overridden. |
| 64 if (allowedExtensions == null) return new Future.value(true); | 67 if (allowedExtensions == null) return true; |
| 65 | 68 |
| 66 for (var extension in allowedExtensions.split(" ")) { | 69 for (var extension in allowedExtensions.split(" ")) { |
| 67 if (id.path.endsWith(extension)) return new Future.value(true); | 70 if (id.path.endsWith(extension)) return true; |
| 68 } | 71 } |
| 69 | 72 |
| 70 return new Future.value(false); | 73 return false; |
| 71 } | 74 } |
| 72 | 75 |
| 73 /// Run this transformer on on the primary input specified by [transform]. | 76 /// Run this transformer on on the primary input specified by [transform]. |
| 74 /// | 77 /// |
| 75 /// The [transform] is used by the [Transformer] for two purposes (in | 78 /// The [transform] is used by the [Transformer] for two purposes (in |
| 76 /// addition to accessing the primary input). It can call `getInput()` to | 79 /// addition to accessing the primary input). It can call `getInput()` to |
| 77 /// request additional input assets. It also calls `addOutput()` to provide | 80 /// request additional input assets. It also calls `addOutput()` to provide |
| 78 /// generated assets back to the system. Either can be called multiple times, | 81 /// generated assets back to the system. Either can be called multiple times, |
| 79 /// in any order. | 82 /// in any order. |
| 80 /// | 83 /// |
| 81 /// In other words, a Transformer's job is to find all inputs for a | 84 /// In other words, a Transformer's job is to find all inputs for a |
| 82 /// transform, starting at the primary input, then generate all output assets | 85 /// transform, starting at the primary input, then generate all output assets |
| 83 /// and yield them back to the transform. | 86 /// and yield them back to the transform. |
| 84 Future apply(Transform transform); | 87 /// |
| 88 /// If this does asynchronous work, it should return a [Future] that completes |
| 89 /// once it's finished. |
| 90 apply(Transform transform); |
| 85 | 91 |
| 86 String toString() => runtimeType.toString().replaceAll("Transformer", ""); | 92 String toString() => runtimeType.toString().replaceAll("Transformer", ""); |
| 87 } | 93 } |
| OLD | NEW |