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

Side by Side Diff: samples/third_party/dromaeo/lib/transformer.dart

Issue 1576153002: Remove the Dromaeo and TodoMVC samples. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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 unified diff | Download patch
« no previous file with comments | « samples/third_party/dromaeo/.gitignore ('k') | samples/third_party/dromaeo/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 library dromaeo.transformer;
2
3 import 'dart:async';
4 import 'package:barback/barback.dart';
5
6 /// Transformer used by `pub build` and `pub serve` to rewrite dromaeo html
7 /// files to run performance tests.
8 class DromaeoTransformer extends Transformer {
9
10 final BarbackSettings settings;
11
12 DromaeoTransformer.asPlugin(this.settings);
13
14 /// The index.html file and the tests/dom-*-html.html files are the ones we
15 /// apply this transform to.
16 Future<bool> isPrimary(AssetId id) {
17 var reg = new RegExp('(tests/dom-.+-html\.html\$)|(index\.html\$)');
18 return new Future.value(reg.hasMatch(id.path));
19 }
20
21 Future apply(Transform transform) {
22 Asset primaryAsset = transform.primaryInput;
23 AssetId primaryAssetId = primaryAsset.id;
24
25 return primaryAsset.readAsString().then((String fileContents) {
26 var filename = primaryAssetId.toString();
27 var outputFileContents = fileContents;
28
29 if (filename.endsWith('index.html')) {
30 var index = outputFileContents.indexOf(
31 '<script src="packages/browser/dart.js">');
32 outputFileContents = outputFileContents.substring(0, index) +
33 '<script src="packages/browser_controller' +
34 '/perf_test_controller.js"></script>\n' +
35 outputFileContents.substring(index);
36 transform.addOutput(new Asset.fromString(new AssetId.parse(
37 primaryAssetId.toString().replaceAll('.html', '-dart.html')),
38 outputFileContents));
39 }
40
41 outputFileContents = _sourceJsNotDart(outputFileContents);
42 // Rename the script to take the JavaScript source.
43 transform.addOutput(new Asset.fromString(new AssetId.parse(
44 _appendJs(primaryAssetId.toString())),
45 outputFileContents));
46 });
47 }
48
49 String _appendJs(String path) => path.replaceAll('.html', '-js.html');
50
51 /// Given an html file that sources a Dart file, rewrite the html to instead
52 /// source the compiled JavaScript file.
53 String _sourceJsNotDart(String fileContents) {
54 var dartScript = new RegExp(
55 '<script type="application/dart" src="([\\w-]+)\.dart">');
56 var match = dartScript.firstMatch(fileContents);
57 return fileContents.replaceAll(dartScript, '<script type="text/javascript"'
58 ' src="${match.group(1)+ ".dart.js"}" defer>');
59 }
60 }
OLDNEW
« no previous file with comments | « samples/third_party/dromaeo/.gitignore ('k') | samples/third_party/dromaeo/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698