| 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.test.transformer.declare_asset; | 5 library barback.test.transformer.declare_asset; |
| 6 | 6 |
| 7 import 'package:barback/barback.dart'; | 7 import 'package:barback/barback.dart'; |
| 8 | 8 |
| 9 import 'mock.dart'; | 9 import 'mock.dart'; |
| 10 | 10 |
| 11 /// A transformer that declares some outputs and emits others. | 11 /// A transformer that declares some outputs and emits others. |
| 12 class DeclareAssetsTransformer extends MockTransformer | 12 class DeclareAssetsTransformer extends MockTransformer |
| 13 implements DeclaringTransformer { | 13 implements DeclaringTransformer { |
| 14 /// The assets that the transformer declares that it will emit. | 14 /// The assets that the transformer declares that it will emit. |
| 15 final List<AssetId> declared; | 15 final List<AssetId> declared; |
| 16 | 16 |
| 17 /// The assets that the transformer actually emits. | 17 /// The assets that the transformer actually emits. |
| 18 /// | 18 /// |
| 19 /// These assets' contents will be identical to their ids. | 19 /// These assets' contents will be identical to their ids. |
| 20 final List<AssetId> emitted; | 20 final List<AssetId> emitted; |
| 21 | 21 |
| 22 /// If this is non-`null`, assets are only declared for this input. | 22 /// If this is non-`null`, assets are only declared for this input. |
| 23 final AssetId input; | 23 final AssetId input; |
| 24 | 24 |
| 25 DeclareAssetsTransformer(Iterable<String> declared, {Iterable<String> emitted, | 25 DeclareAssetsTransformer(Iterable<String> declared, |
| 26 String input}) | 26 {Iterable<String> emitted, String input}) |
| 27 : this.declared = declared.map((id) => new AssetId.parse(id)).toList(), | 27 : this.declared = declared.map((id) => new AssetId.parse(id)).toList(), |
| 28 this.emitted = (emitted == null ? declared : emitted) | 28 this.emitted = (emitted == null ? declared : emitted) |
| 29 .map((id) => new AssetId.parse(id)).toList(), | 29 .map((id) => new AssetId.parse(id)) |
| 30 .toList(), |
| 30 this.input = input == null ? null : new AssetId.parse(input); | 31 this.input = input == null ? null : new AssetId.parse(input); |
| 31 | 32 |
| 32 bool doIsPrimary(AssetId id) => input == null || id == input; | 33 bool doIsPrimary(AssetId id) => input == null || id == input; |
| 33 | 34 |
| 34 void doApply(Transform transform) { | 35 void doApply(Transform transform) { |
| 35 for (var id in emitted) { | 36 for (var id in emitted) { |
| 36 transform.addOutput(new Asset.fromString(id, id.toString())); | 37 transform.addOutput(new Asset.fromString(id, id.toString())); |
| 37 } | 38 } |
| 38 } | 39 } |
| 39 | 40 |
| 40 void declareOutputs(DeclaringTransform transform) { | 41 void declareOutputs(DeclaringTransform transform) { |
| 41 declared.forEach(transform.declareOutput); | 42 declared.forEach(transform.declareOutput); |
| 42 } | 43 } |
| 43 } | 44 } |
| OLD | NEW |