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

Unified Diff: pkg/barback/example/lazy_transformer/lib/transformer.dart

Issue 552843003: Adding a lazy transformer example. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Adding the lazy transformer example to barback Created 6 years, 3 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: pkg/barback/example/lazy_transformer/lib/transformer.dart
diff --git a/pkg/barback/example/lazy_transformer/lib/transformer.dart b/pkg/barback/example/lazy_transformer/lib/transformer.dart
new file mode 100644
index 0000000000000000000000000000000000000000..5d3e70785373532741885c39e1b53019a46662c4
--- /dev/null
+++ b/pkg/barback/example/lazy_transformer/lib/transformer.dart
@@ -0,0 +1,46 @@
+// 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 'dart:async';
+
+class CodedMessageConverter extends Transformer
+ implements LazyTransformer {
+
+ // A constructor named "asPlugin" is required. It can be empty, but
+ // it must be present.
+ CodedMessageConverter.asPlugin();
+
+ Future<bool> isPrimary(AssetId id) {
+ return new Future.value(id.extension == '.txt');
+ }
+
+ Future declareOutputs(DeclaringTransform transform) {
+ return new Future.value(transform.primaryId.changeExtension('.shhhhh'));
+ }
+
+ Future apply(Transform transform) {
+ return transform.primaryInput.readAsString().then((content) {
+
+ // The output file is created with the '.shhhhh' extension.
+ var id = transform.primaryInput.id.changeExtension('.shhhhh');
+
+ StringBuffer newContent = new StringBuffer();
+ for (int i = 0; i < content.length; i++ ) {
+ newContent.write(rot13(content[i]));
+ }
+ transform.addOutput(new Asset.fromString(id, newContent.toString()));
+ });
+ }
+
+ rot13(var ch) {
+ var c = ch.codeUnitAt(0);
+ if (c >= 'a'.codeUnitAt(0) && c <= 'm'.codeUnitAt(0)) c += 13;
+ else if (c >= 'A'.codeUnitAt(0) && c <= 'M'.codeUnitAt(0)) c += 13;
+ else if (c >= 'n'.codeUnitAt(0) && c <= 'z'.codeUnitAt(0)) c -= 13;
+ else if (c >= 'N'.codeUnitAt(0) && c <= 'Z'.codeUnitAt(0)) c -= 13;
+ return new String.fromCharCode(c);
+ }
+}
« no previous file with comments | « pkg/barback/example/lazy_transformer/lib/message.txt ('k') | pkg/barback/example/lazy_transformer/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698