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

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

Issue 22928008: Refactor emitter in web-ui to make dart.js the last script, also cleanup tests (Closed) Base URL: git@github.com:dart-lang/web-ui.git@master
Patch Set: 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 836 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 } 847 }
848 848
849 var expr = 'new autogenerated.$constructor'; 849 var expr = 'new autogenerated.$constructor';
850 var varName = '__html${statics.declarations.length}'; 850 var varName = '__html${statics.declarations.length}';
851 statics.add('final', varName, node.sourceSpan, expr); 851 statics.add('final', varName, node.sourceSpan, expr);
852 return '${varName}.clone(true)'; 852 return '${varName}.clone(true)';
853 } 853 }
854 854
855 /** Trim down the html for the main html page. */ 855 /** Trim down the html for the main html page. */
856 void transformMainHtml(Document document, FileInfo fileInfo, 856 void transformMainHtml(Document document, FileInfo fileInfo,
857 PathMapper pathMapper, bool hasCss, bool rewriteUrls, Messages messages) { 857 PathMapper pathMapper, bool hasCss, bool rewriteUrls, Messages messages,
858 String bootstrapOutName) {
858 var filePath = fileInfo.inputUrl.resolvedPath; 859 var filePath = fileInfo.inputUrl.resolvedPath;
859 860
860 bool dartLoaderFound = false; 861 var dartLoaderTag = null;
861 for (var tag in document.queryAll('script')) { 862 for (var tag in document.queryAll('script')) {
862 var src = tag.attributes['src']; 863 var src = tag.attributes['src'];
863 if (src != null && src.split('/').last == 'dart.js') { 864 if (src != null && src.split('/').last == 'dart.js') {
864 dartLoaderFound = true; 865 dartLoaderTag = tag;
865 } 866 }
866 if (tag.attributes['type'] == 'application/dart') { 867 if (tag.attributes['type'] == 'application/dart') {
867 tag.remove(); 868 tag.remove();
868 } else if (src != null && rewriteUrls) { 869 } else if (src != null && rewriteUrls) {
869 tag.attributes["src"] = pathMapper.transformUrl(filePath, src); 870 tag.attributes["src"] = pathMapper.transformUrl(filePath, src);
870 } 871 }
871 } 872 }
872 for (var tag in document.queryAll('link')) { 873 for (var tag in document.queryAll('link')) {
873 var href = tag.attributes['href']; 874 var href = tag.attributes['href'];
874 var rel = tag.attributes['rel']; 875 var rel = tag.attributes['rel'];
(...skipping 27 matching lines...) Expand all
902 for (var i = styles.length - 1; i > 0 ; i--) { 903 for (var i = styles.length - 1; i > 0 ; i--) {
903 styles[i].remove(); 904 styles[i].remove();
904 } 905 }
905 } 906 }
906 907
907 // TODO(jmesserly): put this in the global CSS file? 908 // TODO(jmesserly): put this in the global CSS file?
908 // http://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/templates/index.html# css-additions 909 // http://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/templates/index.html# css-additions
909 document.head.nodes.insert(0, parseFragment( 910 document.head.nodes.insert(0, parseFragment(
910 '<style>template { display: none; }</style>')); 911 '<style>template { display: none; }</style>'));
911 912
912 if (!dartLoaderFound) { 913
914 var bootstrapScript = parseFragment(
915 '<script type="application/dart" src="$bootstrapOutName"></script>');
916 if (dartLoaderTag == null) {
917 document.body.nodes.add(bootstrapScript);
913 document.body.nodes.add(parseFragment( 918 document.body.nodes.add(parseFragment(
914 '<script type="text/javascript" src="packages/browser/dart.js">' 919 '<script type="text/javascript" src="packages/browser/dart.js">'
915 '</script>\n')); 920 '</script>\n'));
921 } else if (dartLoaderTag.parent != document.body) {
922 document.body.nodes.add(bootstrapScript);
923 } else {
924 document.body.nodes.insertBefore(bootstrapScript, dartLoaderTag);
916 } 925 }
917 926
918 // Insert the "auto-generated" comment after the doctype, otherwise IE will 927 // Insert the "auto-generated" comment after the doctype, otherwise IE will
919 // go into quirks mode. 928 // go into quirks mode.
920 int commentIndex = 0; 929 int commentIndex = 0;
921 DocumentType doctype = find(document.nodes, (n) => n is DocumentType); 930 DocumentType doctype = find(document.nodes, (n) => n is DocumentType);
922 if (doctype != null) { 931 if (doctype != null) {
923 commentIndex = document.nodes.indexOf(doctype) + 1; 932 commentIndex = document.nodes.indexOf(doctype) + 1;
924 // TODO(jmesserly): the html5lib parser emits a warning for missing 933 // TODO(jmesserly): the html5lib parser emits a warning for missing
925 // doctype, but it allows you to put it after comments. Presumably they do 934 // doctype, but it allows you to put it after comments. Presumably they do
(...skipping 17 matching lines...) Expand all
943 return """ 952 return """
944 // Auto-generated from $filename. 953 // Auto-generated from $filename.
945 // DO NOT EDIT. 954 // DO NOT EDIT.
946 $lib 955 $lib
947 import 'dart:html' as autogenerated; 956 import 'dart:html' as autogenerated;
948 import 'dart:svg' as autogenerated_svg; 957 import 'dart:svg' as autogenerated_svg;
949 import 'package:web_ui/web_ui.dart' as autogenerated; 958 import 'package:web_ui/web_ui.dart' as autogenerated;
950 import 'package:web_ui/observe/observable.dart' as __observe; 959 import 'package:web_ui/observe/observable.dart' as __observe;
951 """; 960 """;
952 } 961 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698