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: pkg/barback/example/aggregate_transformer/lib/transformer.dart

Issue 808713003: Remove barback from the repo. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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 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 // Only process assets where the filename ends with "recipe.html".
20 if (!id.path.endsWith('recipe.html')) return null;
21
22 // Return the path string, minus the recipe itself.
23 // This is where the output asset will be written.
24 return p.url.dirname(id.path);
25 }
26
27 // Implement the apply method to process the assets and create the
28 // output asset.
29 Future apply(AggregateTransform transform) {
30 var buffer = new StringBuffer()..write('<html><body>');
31
32 return transform.primaryInputs.toList().then((assets) {
33 // The order of [transform.primaryInputs] is not guaranteed
34 // to be stable across multiple runs of the transformer.
35 // Therefore, we alphabetically sort the assets by ID string.
36 assets.sort((x, y) => x.id.compareTo(y.id));
37 return Future.wait(assets.map((asset) {
38 return asset.readAsString().then((content) {
39 buffer.write(content);
40 buffer.write('<hr>');
41 });
42 }));
43 }).then((_) {
44 buffer.write('</body></html>');
45 // Write the output back to the same directory,
46 // in a file named recipes.html.
47 var id = new AssetId(transform.package,
48 p.url.join(transform.key, ".recipes.html"));
49 transform.addOutput(new Asset.fromString(id, buffer.toString()));
50 });
51 }
52 }
53
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698