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

Unified Diff: packages/barback/example/aggregate_transformer/lib/transformer.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/example/aggregate_transformer/lib/transformer.dart
diff --git a/packages/barback/example/aggregate_transformer/lib/transformer.dart b/packages/barback/example/aggregate_transformer/lib/transformer.dart
new file mode 100644
index 0000000000000000000000000000000000000000..35634dc9120cc522d4b87088ffded39e53b79bb2
--- /dev/null
+++ b/packages/barback/example/aggregate_transformer/lib/transformer.dart
@@ -0,0 +1,47 @@
+// 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.
+
+import 'package:barback/barback.dart';
+import 'package:path/path.dart' as p;
+
+import 'dart:async';
+
+class MakeBook extends AggregateTransformer {
+ // All transformers need to implement "asPlugin" to let Pub know that they
+ // are transformers.
+ MakeBook.asPlugin();
+
+ // Implement the classifyPrimary method to claim any assets that you want
+ // to handle. Return a value for the assets you want to handle,
+ // or null for those that you do not want to handle.
+ classifyPrimary(AssetId id) {
+
+ // Only process assets where the filename ends with "recipe.html".
+ if (!id.path.endsWith('recipe.html')) return null;
+
+ // Return the path string, minus the recipe itself.
+ // This is where the output asset will be written.
+ return p.url.dirname(id.path);
+ }
+
+ // Implement the apply method to process the assets and create the
+ // output asset.
+ Future apply(AggregateTransform transform) async {
+ var buffer = new StringBuffer()..write('<html><body>');
+
+ var assets = await transform.primaryInputs.toList();
+ assets.sort((x, y) => x.id.compareTo(y.id));
+ for (var asset in assets) {
+ var content = await asset.readAsString();
+ buffer.write(content);
+ buffer.write('<hr>');
+ }
+ buffer.write('</body></html>');
+ // Write the output back to the same directory,
+ // in a file named recipes.html.
+ var id = new AssetId(
+ transform.package, p.url.join(transform.key, "recipes.html"));
+ transform.addOutput(new Asset.fromString(id, buffer.toString()));
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698