Chromium Code Reviews| Index: pkg/barback/test/transformer/aggregate_many_to_one.dart |
| diff --git a/pkg/barback/test/transformer/aggregate_many_to_one.dart b/pkg/barback/test/transformer/aggregate_many_to_one.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5a0fcc5b2e5a6b6dbd0bda2140d6dfbef368a613 |
| --- /dev/null |
| +++ b/pkg/barback/test/transformer/aggregate_many_to_one.dart |
| @@ -0,0 +1,42 @@ |
| +// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +library barback.test.transformer.aggregate_many_to_one; |
| + |
| +import 'dart:async'; |
| + |
| +import 'package:barback/barback.dart'; |
| +import 'package:path/path.dart' as path; |
| + |
| +import 'mock_aggregate.dart'; |
| + |
| +/// An [AggregateTransformer] that takes all assets in each directory with a |
| +/// given extension and concatenates them in alphabetic order by filename. |
|
Bob Nystrom
2014/05/27 17:20:18
This is ambiguous (and a bit hard to read). How ab
nweiz
2014/05/27 21:03:10
Done.
|
| +class AggregateManyToOneTransformer extends MockAggregateTransformer { |
| + /// The extension of assets to combine. |
| + final String extension; |
| + |
| + /// The basename of the output asset. |
|
Bob Nystrom
2014/05/27 17:20:18
Mention that the output includes the directory nam
nweiz
2014/05/27 21:03:10
Done.
|
| + final String output; |
| + |
| + AggregateManyToOneTransformer(this.extension, this.output); |
| + |
| + String doClassifyPrimary(AssetId id) { |
| + if (id.extension != ".$extension") return null; |
| + return path.url.dirname(id.path); |
| + } |
| + |
| + Future doApply(AggregateTransform transform) { |
| + return getPrimaryInputs(transform).toList().then((assets) { |
| + assets.sort((asset1, asset2) => asset1.id.path.compareTo(asset2.id.path)); |
| + return Future.wait(assets.map((asset) => asset.readAsString())); |
| + }).then((contents) { |
| + var id = new AssetId(transform.package, |
| + path.url.join(transform.key, output)); |
| + transform.addOutput(new Asset.fromString(id, contents.join('\n'))); |
| + }); |
| + } |
| + |
| + String toString() => "aggregate $extension->$output"; |
| +} |