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

Unified Diff: packages/barback/test/transformer/rewrite.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: packages/barback/test/transformer/rewrite.dart
diff --git a/packages/barback/test/transformer/rewrite.dart b/packages/barback/test/transformer/rewrite.dart
new file mode 100644
index 0000000000000000000000000000000000000000..d25a552a29f8e55cd46983fd1df91f255fca2db3
--- /dev/null
+++ b/packages/barback/test/transformer/rewrite.dart
@@ -0,0 +1,42 @@
+// Copyright (c) 2013, 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.rewrite;
+
+import 'dart:async';
+
+import 'package:barback/barback.dart';
+
+import 'mock.dart';
+
+/// A [Transformer] that takes assets ending with one extension and generates
+/// assets with a given extension.
+///
+/// Appends the output extension to the contents of the input file.
+class RewriteTransformer extends MockTransformer {
+ final String from;
+ final String to;
+
+ /// Creates a transformer that rewrites assets whose extension is [from] to
+ /// one whose extension is [to].
+ ///
+ /// [to] may be a space-separated list in which case multiple outputs will be
+ /// created for each input.
+ RewriteTransformer(this.from, this.to);
+
+ bool doIsPrimary(AssetId id) => id.extension == ".$from";
+
+ Future doApply(Transform transform) {
+ return getPrimary(transform).then((input) {
+ return Future.wait(to.split(" ").map((extension) {
+ var id = input.id.changeExtension(".$extension");
+ return input.readAsString().then((content) {
+ transform.addOutput(new Asset.fromString(id, "$content.$extension"));
+ });
+ }));
+ });
+ }
+
+ String toString() => "$from->$to";
+}
« no previous file with comments | « packages/barback/test/transformer/one_to_many.dart ('k') | packages/barback/test/transformer/sync_rewrite.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698