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

Unified Diff: samples/third_party/dromaeo/lib/transformer.dart

Issue 199003005: Package-ify Dromaeo and browser controller functionality (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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
« no previous file with comments | « samples/third_party/dromaeo/index.html ('k') | samples/third_party/dromaeo/pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samples/third_party/dromaeo/lib/transformer.dart
diff --git a/samples/third_party/dromaeo/lib/transformer.dart b/samples/third_party/dromaeo/lib/transformer.dart
new file mode 100644
index 0000000000000000000000000000000000000000..88fb58485fdd0040d3ed427a19fe0bde0c0fffeb
--- /dev/null
+++ b/samples/third_party/dromaeo/lib/transformer.dart
@@ -0,0 +1,60 @@
+library dromaeo.transformer;
+
+import 'dart:async';
+import 'package:barback/barback.dart';
+
+/// Transformer used by `pub build` and `pub serve` to rewrite dromaeo html
+/// files to run performance tests.
+class DromaeoTransformer extends Transformer {
+
+ final BarbackSettings settings;
+
+ DromaeoTransformer.asPlugin(this.settings);
+
+ /// The index.html file and the tests/dom-*-html.html files are the ones we
+ /// apply this transform to.
+ Future<bool> isPrimary(Asset asset) {
+ var reg = new RegExp('(tests/dom-.+-html\.html\$)|(index\.html\$)');
+ return new Future.value(reg.hasMatch(asset.id.path));
+ }
+
+ Future apply(Transform transform) {
+ Asset primaryAsset = transform.primaryInput;
+ AssetId primaryAssetId = primaryAsset.id;
+
+ return primaryAsset.readAsString().then((String fileContents) {
+ var filename = primaryAssetId.toString();
+ var outputFileContents = fileContents;
+
+ if (filename.endsWith('index.html')) {
+ var index = outputFileContents.indexOf(
+ '<script src="packages/browser/dart.js">');
+ outputFileContents = outputFileContents.substring(0, index) +
+ '<script src="packages/browser_controller' +
+ '/perf_test_controller.js"></script>\n' +
+ outputFileContents.substring(index);
+ transform.addOutput(new Asset.fromString(new AssetId.parse(
+ primaryAssetId.toString().replaceAll('.html', '-dart.html')),
+ outputFileContents));
+ }
+
+ outputFileContents = _sourceJsNotDart(outputFileContents);
+ // Rename the script to take the JavaScript source.
+ transform.addOutput(new Asset.fromString(new AssetId.parse(
+ _appendJs(primaryAssetId.toString())),
+ outputFileContents));
+ });
+ }
+
+ String _appendJs(String path) => path.replaceAll('.html', '-js.html');
+
+ /// Given an html file that sources a Dart file, rewrite the html to instead
+ /// source the compiled JavaScript file.
+ String _sourceJsNotDart(String fileContents) {
+ var dartScript = new RegExp(
+ '<script type="application/dart" src="([\\w-]+)\.dart">');
+ var match = dartScript.firstMatch(fileContents);
+ return fileContents.replaceAll(dartScript, '<script type="text/javascript"'
+ ' src="${match.group(1)+ ".dart.js"}" defer>');
+ }
+}
« no previous file with comments | « samples/third_party/dromaeo/index.html ('k') | samples/third_party/dromaeo/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698