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