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

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

Issue 21226004: Refactor the barback tests somewhat. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes. Created 7 years, 4 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
« no previous file with comments | « pkg/barback/test/transformer/one_to_many.dart ('k') | pkg/barback/test/utils.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, 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 import 'dart:async';
6
7 import 'package:barback/barback.dart';
8
9 import 'mock.dart';
10
11 /// A [Transformer] that takes assets ending with one extension and generates
12 /// assets with a given extension.
13 ///
14 /// Appends the output extension to the contents of the input file.
15 class RewriteTransformer extends MockTransformer {
16 final String from;
17 final String to;
18
19 /// Creates a transformer that rewrites assets whose extension is [from] to
20 /// one whose extension is [to].
21 ///
22 /// [to] may be a space-separated list in which case multiple outputs will be
23 /// created for each input.
24 RewriteTransformer(this.from, this.to);
25
26 Future<bool> doIsPrimary(Asset asset) =>
27 new Future.value(asset.id.extension == ".$from");
28
29 Future doApply(Transform transform) {
30 return getPrimary(transform).then((input) {
31 return Future.wait(to.split(" ").map((extension) {
32 var id = transform.primaryId.changeExtension(".$extension");
33 return input.readAsString().then((content) {
34 transform.addOutput(new Asset.fromString(id, "$content.$extension"));
35 });
36 }));
37 });
38 }
39
40 String toString() => "$from->$to";
41 }
OLDNEW
« no previous file with comments | « pkg/barback/test/transformer/one_to_many.dart ('k') | pkg/barback/test/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698