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

Side by Side 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 unified diff | Download patch
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 import 'package:barback/barback.dart';
6 import 'package:path/path.dart' as p;
7
8 import 'dart:async';
9
10 class MakeBook extends AggregateTransformer {
11 // All transformers need to implement "asPlugin" to let Pub know that they
12 // are transformers.
13 MakeBook.asPlugin();
14
15 // Implement the classifyPrimary method to claim any assets that you want
16 // to handle. Return a value for the assets you want to handle,
17 // or null for those that you do not want to handle.
18 classifyPrimary(AssetId id) {
19
20 // Only process assets where the filename ends with "recipe.html".
21 if (!id.path.endsWith('recipe.html')) return null;
22
23 // Return the path string, minus the recipe itself.
24 // This is where the output asset will be written.
25 return p.url.dirname(id.path);
26 }
27
28 // Implement the apply method to process the assets and create the
29 // output asset.
30 Future apply(AggregateTransform transform) async {
31 var buffer = new StringBuffer()..write('<html><body>');
32
33 var assets = await transform.primaryInputs.toList();
34 assets.sort((x, y) => x.id.compareTo(y.id));
35 for (var asset in assets) {
36 var content = await asset.readAsString();
37 buffer.write(content);
38 buffer.write('<hr>');
39 }
40 buffer.write('</body></html>');
41 // Write the output back to the same directory,
42 // in a file named recipes.html.
43 var id = new AssetId(
44 transform.package, p.url.join(transform.key, "recipes.html"));
45 transform.addOutput(new Asset.fromString(id, buffer.toString()));
46 }
47 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698