Index: packages/barback/example/lazy_transformer/lib/transformer.dart |
diff --git a/packages/barback/example/lazy_transformer/lib/transformer.dart b/packages/barback/example/lazy_transformer/lib/transformer.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..aaee46f588324a83351ed58f4b73c92977f92c61 |
--- /dev/null |
+++ b/packages/barback/example/lazy_transformer/lib/transformer.dart |
@@ -0,0 +1,42 @@ |
+// 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) async => id.extension == '.txt'; |
+ |
+ Future declareOutputs(DeclaringTransform transform) { |
+ transform.declareOutput(transform.primaryId.changeExtension('.shhhhh')); |
+ } |
+ |
+ Future apply(Transform transform) async { |
+ var content = await transform.primaryInput.readAsString(); |
+ |
+ // The output file is created with the '.shhhhh' extension. |
+ var id = transform.primaryInput.id.changeExtension('.shhhhh'); |
+ |
+ var newContent = new StringBuffer(); |
+ for (var 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); |
+ } |
+} |