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

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

Issue 12474002: Support for parsing all CSS and producing one CSS file (Closed) Base URL: https://github.com/dart-lang/web-ui.git@master
Patch Set: merged Created 7 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 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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 406
407 if (info.element.attributes['apply-author-styles'] != null) { 407 if (info.element.attributes['apply-author-styles'] != null) {
408 _context.printer.addLine('if (_root is autogenerated.ShadowRoot) ' 408 _context.printer.addLine('if (_root is autogenerated.ShadowRoot) '
409 '_root.applyAuthorStyles = true;'); 409 '_root.applyAuthorStyles = true;');
410 // TODO(jmesserly): warn at runtime if apply-author-styles was not set, 410 // TODO(jmesserly): warn at runtime if apply-author-styles was not set,
411 // and we don't have Shadow DOM support? In that case, styles won't have 411 // and we don't have Shadow DOM support? In that case, styles won't have
412 // proper encapsulation. 412 // proper encapsulation.
413 } 413 }
414 414
415 if (info.template != null && !elemInfo.childrenCreatedInCode) { 415 if (info.template != null && !elemInfo.childrenCreatedInCode) {
416 // TODO(jmesserly): scoped styles probably don't work when
417 // childrenCreatedInCode is true.
418 if (info.styleSheet != null) {
419 var tag = cssPolyfill ? info.tagName : null;
420 // TODO(jmesserly): csslib+html5lib should work together. We shouldn't
421 // need to call a different function to serialize CSS.
422 // Calling innerHTML on a StyleElement should be
423 // enought - like a real browser. CSSOM and DOM
424 // should work together in the same tree.
425 // TODO(terry): Consider not emitting <style> tag inside of component.
426 // Maybe we can generate a .css file that has all the CSS
427 // polyfill. The style tag can change the rendering a bit.
428 var styleSheet =
429 '<style>\n'
430 '${emitStyleSheet(info.styleSheet, tag)}'
431 '\n</style>';
432 var template = elemInfo.node;
433 template.insertBefore(new Element.html(styleSheet),
434 template.children[0]);
435 }
436
437 _context.statics.add('final', '__shadowTemplate', 416 _context.statics.add('final', '__shadowTemplate',
438 elemInfo.node.sourceSpan, 417 elemInfo.node.sourceSpan,
439 "new autogenerated.DocumentFragment.html('''" 418 "new autogenerated.DocumentFragment.html('''"
440 "${escapeDartString(elemInfo.node.innerHtml, triple: true)}" 419 "${escapeDartString(elemInfo.node.innerHtml, triple: true)}"
441 "''')"); 420 "''')");
442 _context.printer.addLine( 421 _context.printer.addLine(
443 "_root.nodes.add(__shadowTemplate.clone(true));"); 422 "_root.nodes.add(__shadowTemplate.clone(true));");
444 } 423 }
445 424
446 visit(elemInfo); 425 visit(elemInfo);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 document.queryAll('script').forEach((tag) { 523 document.queryAll('script').forEach((tag) {
545 var src = tag.attributes["src"]; 524 var src = tag.attributes["src"];
546 if (tag.attributes['type'] == 'application/dart') { 525 if (tag.attributes['type'] == 'application/dart') {
547 tag.remove(); 526 tag.remove();
548 } else if (src != null && rewriteUrls) { 527 } else if (src != null && rewriteUrls) {
549 tag.attributes["src"] = pathInfo.transformUrl(_fileInfo.path, src); 528 tag.attributes["src"] = pathInfo.transformUrl(_fileInfo.path, src);
550 } 529 }
551 }); 530 });
552 document.queryAll('link').forEach((tag) { 531 document.queryAll('link').forEach((tag) {
553 var href = tag.attributes['href']; 532 var href = tag.attributes['href'];
554 if (tag.attributes['rel'] == 'components') { 533 var rel = tag.attributes['rel'];
534 if (rel == 'components') {
Siggi Cherem (dart-lang) 2013/03/07 22:14:20 do you mind adding rel == 'component' too, I think
terry 2013/03/08 20:11:24 Done.
555 tag.remove(); 535 tag.remove();
536 } else if (rel == 'stylesheet' && !href.startsWith('http')) {
Siggi Cherem (dart-lang) 2013/03/07 22:14:20 let's check also that && cssPolyfill is true, othe
terry 2013/03/08 20:11:24 I didn't think of this as polyfill but more of how
537 tag.remove();
556 } else if (href != null && rewriteUrls) { 538 } else if (href != null && rewriteUrls) {
557 tag.attributes['href'] = pathInfo.transformUrl(_fileInfo.path, href); 539 tag.attributes['href'] = pathInfo.transformUrl(_fileInfo.path, href);
558 } 540 }
559 }); 541 });
560 542
543 var linkElem = new Element.html('<link rel="stylesheet" type="text/css"'
Siggi Cherem (dart-lang) 2013/03/07 22:14:20 likewise - we should only add this new link if css
terry 2013/03/08 20:11:24 Done.
544 ' href="${_fileInfo.path.filename}.css">');
545 document.head.insertBefore(linkElem, null);
Siggi Cherem (dart-lang) 2013/03/07 22:14:20 should this be done as the first child so that the
terry 2013/03/08 20:11:24 Good idea to make it first. On 2013/03/07 22:14:20
561 546
562 var codeInfo = _fileInfo.userCode; 547 var codeInfo = _fileInfo.userCode;
563 if (codeInfo == null) { 548 if (codeInfo == null) {
564 assert(transaction == null); 549 assert(transaction == null);
565 codeInfo = new DartCodeInfo(null, null, [], 'main(){\n}', null); 550 codeInfo = new DartCodeInfo(null, null, [], 'main(){\n}', null);
566 } 551 }
567 552
568 if (transaction == null) { 553 if (transaction == null) {
569 transaction = new TextEditTransaction(codeInfo.code, codeInfo.sourceFile); 554 transaction = new TextEditTransaction(codeInfo.code, codeInfo.sourceFile);
570 } 555 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 } 676 }
692 typeName = htmlElementExtends[typeName]; 677 typeName = htmlElementExtends[typeName];
693 } 678 }
694 // If we didn't find a DOM setter, and this is a component, set a property on 679 // If we didn't find a DOM setter, and this is a component, set a property on
695 // the component. 680 // the component.
696 if (info.component != null && !name.startsWith('data-')) { 681 if (info.component != null && !name.startsWith('data-')) {
697 return 'xtag.${toCamelCase(name)}'; 682 return 'xtag.${toCamelCase(name)}';
698 } 683 }
699 return "attributes['$name']"; 684 return "attributes['$name']";
700 } 685 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698