Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: pkg/barback/test/transformer/aggregate_many_to_one.dart

Issue 299833003: Expose aggregate transformers in barback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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_one;
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 in each directory with a
15 /// 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.
16 class AggregateManyToOneTransformer extends MockAggregateTransformer {
17 /// The extension of assets to combine.
18 final String extension;
19
20 /// 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.
21 final String output;
22
23 AggregateManyToOneTransformer(this.extension, this.output);
24
25 String doClassifyPrimary(AssetId id) {
26 if (id.extension != ".$extension") return null;
27 return path.url.dirname(id.path);
28 }
29
30 Future doApply(AggregateTransform transform) {
31 return getPrimaryInputs(transform).toList().then((assets) {
32 assets.sort((asset1, asset2) => asset1.id.path.compareTo(asset2.id.path));
33 return Future.wait(assets.map((asset) => asset.readAsString()));
34 }).then((contents) {
35 var id = new AssetId(transform.package,
36 path.url.join(transform.key, output));
37 transform.addOutput(new Asset.fromString(id, contents.join('\n')));
38 });
39 }
40
41 String toString() => "aggregate $extension->$output";
42 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698