OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS d.file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS d.file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library pub_tests; | 5 library pub_tests; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 | 10 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 Future apply(Transform transform) { | 51 Future apply(Transform transform) { |
52 return transform.primaryInput.readAsString().then((contents) { | 52 return transform.primaryInput.readAsString().then((contents) { |
53 var id = transform.primaryInput.id.changeExtension(".out"); | 53 var id = transform.primaryInput.id.changeExtension(".out"); |
54 transform.addOutput(new Asset.fromString(id, "\$contents.out")); | 54 transform.addOutput(new Asset.fromString(id, "\$contents.out")); |
55 }); | 55 }); |
56 } | 56 } |
57 } | 57 } |
58 """; | 58 """; |
59 | 59 |
| 60 /// The code for a lazy version of [REWRITE_TRANSFORMER]. |
| 61 const LAZY_TRANSFORMER = """ |
| 62 import 'dart:async'; |
| 63 |
| 64 import 'package:barback/barback.dart'; |
| 65 |
| 66 class LazyRewriteTransformer extends Transformer implements LazyTransformer { |
| 67 LazyRewriteTransformer.asPlugin(); |
| 68 |
| 69 String get allowedExtensions => '.txt'; |
| 70 |
| 71 Future apply(Transform transform) { |
| 72 transform.logger.info('Rewriting \${transform.primaryInput.id}.'); |
| 73 return transform.primaryInput.readAsString().then((contents) { |
| 74 var id = transform.primaryInput.id.changeExtension(".out"); |
| 75 transform.addOutput(new Asset.fromString(id, "\$contents.out")); |
| 76 }); |
| 77 } |
| 78 |
| 79 Future declareOutputs(DeclaringTransform transform) { |
| 80 transform.declareOutput(transform.primaryId.changeExtension(".out")); |
| 81 return new Future.value(); |
| 82 } |
| 83 } |
| 84 """; |
| 85 |
60 /// The web socket error code for a directory not being served. | 86 /// The web socket error code for a directory not being served. |
61 const NOT_SERVED = 1; | 87 const NOT_SERVED = 1; |
62 | 88 |
63 /// Returns the source code for a Dart library defining a Transformer that | 89 /// Returns the source code for a Dart library defining a Transformer that |
64 /// rewrites Dart files. | 90 /// rewrites Dart files. |
65 /// | 91 /// |
66 /// The transformer defines a constant named TOKEN whose value is [id]. When the | 92 /// The transformer defines a constant named TOKEN whose value is [id]. When the |
67 /// transformer transforms another Dart file, it will look for a "TOKEN" | 93 /// transformer transforms another Dart file, it will look for a "TOKEN" |
68 /// constant definition there and modify it to include *this* transformer's | 94 /// constant definition there and modify it to include *this* transformer's |
69 /// TOKEN value as well. | 95 /// TOKEN value as well. |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 /// included. Unlike [getServerUrl], this should only be called after the ports | 467 /// included. Unlike [getServerUrl], this should only be called after the ports |
442 /// are known. | 468 /// are known. |
443 String _getServerUrlSync([String root, String path]) { | 469 String _getServerUrlSync([String root, String path]) { |
444 if (root == null) root = 'web'; | 470 if (root == null) root = 'web'; |
445 expect(_ports, contains(root)); | 471 expect(_ports, contains(root)); |
446 var url = "http://127.0.0.1:${_ports[root]}"; | 472 var url = "http://127.0.0.1:${_ports[root]}"; |
447 if (path != null) url = "$url/$path"; | 473 if (path != null) url = "$url/$path"; |
448 return url; | 474 return url; |
449 } | 475 } |
450 | 476 |
OLD | NEW |