OLD | NEW |
1 library dromaeo.transformer; | 1 library dromaeo.transformer; |
2 | 2 |
3 import 'dart:async'; | 3 import 'dart:async'; |
4 import 'package:barback/barback.dart'; | 4 import 'package:barback/barback.dart'; |
5 | 5 |
6 /// Transformer used by `pub build` and `pub serve` to rewrite dromaeo html | 6 /// Transformer used by `pub build` and `pub serve` to rewrite dromaeo html |
7 /// files to run performance tests. | 7 /// files to run performance tests. |
8 class DromaeoTransformer extends Transformer { | 8 class DromaeoTransformer extends Transformer { |
9 | 9 |
10 final BarbackSettings settings; | 10 final BarbackSettings settings; |
11 | 11 |
12 DromaeoTransformer.asPlugin(this.settings); | 12 DromaeoTransformer.asPlugin(this.settings); |
13 | 13 |
14 /// The index.html file and the tests/dom-*-html.html files are the ones we | 14 /// The index.html file and the tests/dom-*-html.html files are the ones we |
15 /// apply this transform to. | 15 /// apply this transform to. |
16 Future<bool> isPrimary(Asset asset) { | 16 Future<bool> isPrimary(AssetId id) { |
17 var reg = new RegExp('(tests/dom-.+-html\.html\$)|(index\.html\$)'); | 17 var reg = new RegExp('(tests/dom-.+-html\.html\$)|(index\.html\$)'); |
18 return new Future.value(reg.hasMatch(asset.id.path)); | 18 return new Future.value(reg.hasMatch(id.path)); |
19 } | 19 } |
20 | 20 |
21 Future apply(Transform transform) { | 21 Future apply(Transform transform) { |
22 Asset primaryAsset = transform.primaryInput; | 22 Asset primaryAsset = transform.primaryInput; |
23 AssetId primaryAssetId = primaryAsset.id; | 23 AssetId primaryAssetId = primaryAsset.id; |
24 | 24 |
25 return primaryAsset.readAsString().then((String fileContents) { | 25 return primaryAsset.readAsString().then((String fileContents) { |
26 var filename = primaryAssetId.toString(); | 26 var filename = primaryAssetId.toString(); |
27 var outputFileContents = fileContents; | 27 var outputFileContents = fileContents; |
28 | 28 |
(...skipping 22 matching lines...) Expand all Loading... |
51 /// Given an html file that sources a Dart file, rewrite the html to instead | 51 /// Given an html file that sources a Dart file, rewrite the html to instead |
52 /// source the compiled JavaScript file. | 52 /// source the compiled JavaScript file. |
53 String _sourceJsNotDart(String fileContents) { | 53 String _sourceJsNotDart(String fileContents) { |
54 var dartScript = new RegExp( | 54 var dartScript = new RegExp( |
55 '<script type="application/dart" src="([\\w-]+)\.dart">'); | 55 '<script type="application/dart" src="([\\w-]+)\.dart">'); |
56 var match = dartScript.firstMatch(fileContents); | 56 var match = dartScript.firstMatch(fileContents); |
57 return fileContents.replaceAll(dartScript, '<script type="text/javascript"' | 57 return fileContents.replaceAll(dartScript, '<script type="text/javascript"' |
58 ' src="${match.group(1)+ ".dart.js"}" defer>'); | 58 ' src="${match.group(1)+ ".dart.js"}" defer>'); |
59 } | 59 } |
60 } | 60 } |
OLD | NEW |