| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.sync_rewrite; | 5 library barback.test.transformer.sync_rewrite; |
| 6 | 6 |
| 7 import 'dart:async'; | |
| 8 | |
| 9 import 'package:barback/barback.dart'; | 7 import 'package:barback/barback.dart'; |
| 10 | 8 |
| 11 /// Like [DeclaringRewriteTransformer], but with no methods returning Futures. | 9 /// Like [DeclaringRewriteTransformer], but with no methods returning Futures. |
| 12 class SyncRewriteTransformer extends Transformer | 10 class SyncRewriteTransformer extends Transformer |
| 13 implements DeclaringTransformer { | 11 implements DeclaringTransformer { |
| 14 final String from; | 12 final String from; |
| 15 final String to; | 13 final String to; |
| 16 | 14 |
| 17 SyncRewriteTransformer(this.from, this.to); | 15 SyncRewriteTransformer(this.from, this.to); |
| 18 | 16 |
| 19 bool isPrimary(AssetId id) => id.extension == ".$from"; | 17 bool isPrimary(AssetId id) => id.extension == ".$from"; |
| 20 | 18 |
| 21 void apply(Transform transform) { | 19 void apply(Transform transform) { |
| 22 for (var extension in to.split(" ")) { | 20 for (var extension in to.split(" ")) { |
| 23 var id = transform.primaryInput.id.changeExtension(".$extension"); | 21 var id = transform.primaryInput.id.changeExtension(".$extension"); |
| 24 transform.addOutput(new Asset.fromString(id, "new.$extension")); | 22 transform.addOutput(new Asset.fromString(id, "new.$extension")); |
| 25 } | 23 } |
| 26 } | 24 } |
| 27 | 25 |
| 28 void declareOutputs(DeclaringTransform transform) { | 26 void declareOutputs(DeclaringTransform transform) { |
| 29 for (var extension in to.split(" ")) { | 27 for (var extension in to.split(" ")) { |
| 30 var id = transform.primaryId.changeExtension(".$extension"); | 28 var id = transform.primaryId.changeExtension(".$extension"); |
| 31 transform.declareOutput(id); | 29 transform.declareOutput(id); |
| 32 } | 30 } |
| 33 } | 31 } |
| 34 | 32 |
| 35 String toString() => "$from->$to"; | 33 String toString() => "$from->$to"; |
| 36 } | 34 } |
| OLD | NEW |