OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library barback.test.transformer.aggregate_many_to_many; |
| 6 |
| 7 import 'dart:async'; |
| 8 |
| 9 import 'package:barback/barback.dart'; |
| 10 import 'package:path/path.dart' as path; |
| 11 |
| 12 import 'mock_aggregate.dart'; |
| 13 |
| 14 /// An [AggregateTransformer] that takes all assets with a given extension, |
| 15 /// grouped by directory, adds to their contents. |
| 16 class AggregateManyToManyTransformer extends MockAggregateTransformer { |
| 17 /// The extension of assets to combine. |
| 18 final String extension; |
| 19 |
| 20 AggregateManyToManyTransformer(this.extension); |
| 21 |
| 22 String doClassifyPrimary(AssetId id) { |
| 23 if (id.extension != ".$extension") return null; |
| 24 return path.url.dirname(id.path); |
| 25 } |
| 26 |
| 27 Future doApply(AggregateTransform transform) { |
| 28 return getPrimaryInputs(transform).asyncMap((asset) { |
| 29 return asset.readAsString().then((contents) { |
| 30 transform.addOutput(new Asset.fromString( |
| 31 asset.id, "modified $contents")); |
| 32 }); |
| 33 }).toList(); |
| 34 } |
| 35 |
| 36 String toString() => "aggregate $extension->many"; |
| 37 } |
OLD | NEW |