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

Side by Side Diff: lib/src/emitters.dart

Issue 20863002: Introduce boot.js: this finally makes it possible to load and run Todomvc (Closed) Base URL: git@github.com:dart-lang/web-ui.git@master
Patch Set: review comments, fixed build.dart Created 7 years, 4 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS 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 /** Collects several code emitters for the template tool. */ 5 /** Collects several code emitters for the template tool. */
6 library emitters; 6 library emitters;
7 7
8 import 'package:csslib/parser.dart' as css; 8 import 'package:csslib/parser.dart' as css;
9 import 'package:csslib/visitor.dart'; 9 import 'package:csslib/visitor.dart';
10 import 'package:html5lib/dom.dart'; 10 import 'package:html5lib/dom.dart';
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 } 241 }
242 242
243 /** The code that will be used to bootstrap the application. */ 243 /** The code that will be used to bootstrap the application. */
244 CodePrinter generateBootstrapCode( 244 CodePrinter generateBootstrapCode(
245 FileInfo info, FileInfo userMainInfo, GlobalInfo global, 245 FileInfo info, FileInfo userMainInfo, GlobalInfo global,
246 PathMapper pathMapper, CompilerOptions options) { 246 PathMapper pathMapper, CompilerOptions options) {
247 247
248 var printer = new CodePrinter(0) 248 var printer = new CodePrinter(0)
249 ..addLine('library app_bootstrap;') 249 ..addLine('library app_bootstrap;')
250 ..addLine('') 250 ..addLine('')
251 ..addLine("import 'package:mdv/mdv.dart' as mdv;")
251 ..addLine("import 'package:polymer/polymer.dart' as polymer;"); 252 ..addLine("import 'package:polymer/polymer.dart' as polymer;");
252 253
253 if (userMainInfo.userCode != null) { 254 if (userMainInfo.userCode != null) {
254 printer..addLine('') 255 printer..addLine('')
255 ..addLine("import '${pathMapper.importUrlFor(info, userMainInfo)}' " 256 ..addLine("import '${pathMapper.importUrlFor(info, userMainInfo)}' "
256 "as userMain;\n"); 257 "as userMain;\n");
257 } 258 }
258 259
259 for (var c in global.components.values) { 260 for (var c in global.components.values) {
260 if (c.hasConflict) continue; 261 if (c.hasConflict) continue;
261 printer.addLine("import '${pathMapper.importUrlFor(info, c)}';"); 262 printer.addLine("import '${pathMapper.importUrlFor(info, c)}';");
262 } 263 }
263 264
264 printer..addLine('') 265 printer..addLine('')
265 ..addLine('void main() {') 266 ..addLine('void main() {')
266 ..indent += 1; 267 ..indent += 1
268 ..addLine('mdv.initialize();');
Jennifer Messerly 2013/07/30 00:56:12 remove this because initPolymer does it? (shouldn
Siggi Cherem (dart-lang) 2013/07/30 23:32:04 I changed it to do so, but we should talk more abo
267 269
268 if (userMainInfo.userCode != null) printer.addLine('userMain.main();'); 270 if (userMainInfo.userCode != null) printer.addLine('userMain.main();');
269 271
270 for (var c in global.components.values) { 272 for (var c in global.components.values) {
271 if (c.hasConflict) continue; 273 if (c.hasConflict) continue;
272 var tagName = escapeDartString(c.tagName); 274 var tagName = escapeDartString(c.tagName);
273 var cssMapExpression = createCssSelectorsExpression(c, 275 var cssMapExpression = createCssSelectorsExpression(c,
274 CssPolyfillKind.of(options, c)); 276 CssPolyfillKind.of(options, c));
275 printer 277 printer
276 ..addLine("polymer.setScopedCss('$tagName', $cssMapExpression);") 278 ..addLine("polymer.setScopedCss('$tagName', $cssMapExpression);")
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 } 355 }
354 356
355 // Add existing import, export, and part directives. 357 // Add existing import, export, and part directives.
356 var file = codeInfo.sourceFile; 358 var file = codeInfo.sourceFile;
357 for (var d in codeInfo.directives) { 359 for (var d in codeInfo.directives) {
358 addUnique(d.toString(), file != null ? file.location(d.offset) : null); 360 addUnique(d.toString(), file != null ? file.location(d.offset) : null);
359 } 361 }
360 } 362 }
361 363
362 final shadowDomJS = new RegExp(r'shadowdom\..*\.js', caseSensitive: false); 364 final shadowDomJS = new RegExp(r'shadowdom\..*\.js', caseSensitive: false);
365 final bootJS = new RegExp(r'.*/polymer/boot.js', caseSensitive: false);
363 366
364 /** Trim down the html for the main html page. */ 367 /** Trim down the html for the main html page. */
365 void transformMainHtml(Document document, FileInfo fileInfo, 368 void transformMainHtml(Document document, FileInfo fileInfo,
366 PathMapper pathMapper, bool hasCss, bool rewriteUrls, 369 PathMapper pathMapper, bool hasCss, bool rewriteUrls,
367 Messages messages, GlobalInfo global) { 370 Messages messages, GlobalInfo global) {
368 var filePath = fileInfo.inputUrl.resolvedPath; 371 var filePath = fileInfo.inputUrl.resolvedPath;
369 372
370 bool dartLoaderFound = false; 373 bool dartLoaderFound = false;
371 bool shadowDomFound = false; 374 bool shadowDomFound = false;
372 for (var tag in document.queryAll('script')) { 375 for (var tag in document.queryAll('script')) {
373 var src = tag.attributes['src']; 376 var src = tag.attributes['src'];
374 if (src != null) { 377 if (src != null) {
375 var last = src.split('/').last; 378 var last = src.split('/').last;
376 if (last == 'dart.js' || last == 'testing.js') { 379 if (last == 'dart.js' || last == 'testing.js') {
377 dartLoaderFound = true; 380 dartLoaderFound = true;
378 } else if (shadowDomJS.hasMatch(last)) { 381 } else if (shadowDomJS.hasMatch(last)) {
379 shadowDomFound = true; 382 shadowDomFound = true;
380 } 383 }
381 } 384 }
382 if (tag.attributes['type'] == 'application/dart') { 385 if (tag.attributes['type'] == 'application/dart') {
383 tag.remove(); 386 tag.remove();
384 } else if (src != null && rewriteUrls) { 387 } else if (src != null) {
385 tag.attributes["src"] = pathMapper.transformUrl(filePath, src); 388 if (bootJS.hasMatch(src)) {
389 tag.remove();
390 } else if (rewriteUrls) {
391 tag.attributes["src"] = pathMapper.transformUrl(filePath, src);
392 }
386 } 393 }
387 } 394 }
388 395
389 for (var tag in document.queryAll('link')) { 396 for (var tag in document.queryAll('link')) {
390 var href = tag.attributes['href']; 397 var href = tag.attributes['href'];
391 var rel = tag.attributes['rel']; 398 var rel = tag.attributes['rel'];
392 if (rel == 'component' || rel == 'components' || rel == 'import') { 399 if (rel == 'component' || rel == 'components' || rel == 'import') {
393 tag.remove(); 400 tag.remove();
394 } else if (href != null && rewriteUrls && !hasCss) { 401 } else if (href != null && rewriteUrls && !hasCss) {
395 // Only rewrite URL if rewrite on and we're not CSS polyfilling. 402 // Only rewrite URL if rewrite on and we're not CSS polyfilling.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 // Auto-generated from $filename. 492 // Auto-generated from $filename.
486 // DO NOT EDIT. 493 // DO NOT EDIT.
487 $lib 494 $lib
488 import 'dart:html' as autogenerated; 495 import 'dart:html' as autogenerated;
489 import 'dart:svg' as autogenerated_svg; 496 import 'dart:svg' as autogenerated_svg;
490 import 'package:mdv/mdv.dart' as autogenerated_mdv; 497 import 'package:mdv/mdv.dart' as autogenerated_mdv;
491 import 'package:observe/observe.dart' as __observe; 498 import 'package:observe/observe.dart' as __observe;
492 import 'package:polymer/polymer.dart' as autogenerated; 499 import 'package:polymer/polymer.dart' as autogenerated;
493 """; 500 """;
494 } 501 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698