| OLD | NEW |
| 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:html5lib/dom.dart'; | 8 import 'package:html5lib/dom.dart'; |
| 9 import 'package:html5lib/dom_parsing.dart' show TreeVisitor; | 9 import 'package:html5lib/dom_parsing.dart' show TreeVisitor; |
| 10 import 'package:html5lib/parser.dart' show parseFragment; | 10 import 'package:html5lib/parser.dart' show parseFragment; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 /** The code that will be used to bootstrap the application. */ | 42 /** The code that will be used to bootstrap the application. */ |
| 43 NestedPrinter generateBootstrapCode( | 43 NestedPrinter generateBootstrapCode( |
| 44 FileInfo info, FileInfo userMainInfo, GlobalInfo global, | 44 FileInfo info, FileInfo userMainInfo, GlobalInfo global, |
| 45 PathMapper pathMapper, CompilerOptions options) { | 45 PathMapper pathMapper, CompilerOptions options) { |
| 46 | 46 |
| 47 var printer = new NestedPrinter(0) | 47 var printer = new NestedPrinter(0) |
| 48 ..addLine('library app_bootstrap;') | 48 ..addLine('library app_bootstrap;') |
| 49 ..addLine('') | 49 ..addLine('') |
| 50 ..addLine("import 'package:polymer/polymer.dart';") | 50 ..addLine("import 'package:polymer/polymer.dart';") |
| 51 ..addLine("import 'dart:mirrors' show currentMirrorSystem;"); | 51 ..addLine("import 'dart:mirrors' show currentMirrorSystem;"); |
| 52 if (userMainInfo.userCode != null) { | |
| 53 printer..addLine("import '${pathMapper.importUrlFor(info, userMainInfo)}' " | |
| 54 "as userMain;\n"); | |
| 55 } | |
| 56 | 52 |
| 57 int i = 0; | 53 int i = 0; |
| 58 for (var c in global.components.values) { | 54 for (var c in global.components.values) { |
| 59 if (c.hasConflict) continue; | 55 if (c.hasConflict) continue; |
| 60 printer.addLine("import '${pathMapper.importUrlFor(info, c)}' as i$i;"); | 56 printer.addLine("import '${pathMapper.importUrlFor(info, c)}' as i$i;"); |
| 61 i++; | 57 i++; |
| 62 } | 58 } |
| 59 if (userMainInfo.userCode != null) { |
| 60 printer..addLine("import '${pathMapper.importUrlFor(info, userMainInfo)}' " |
| 61 "as i$i;\n"); |
| 62 } |
| 63 | 63 |
| 64 printer..addLine('') | 64 printer..addLine('') |
| 65 ..addLine('void main() {') | 65 ..addLine('void main() {') |
| 66 ..indent += 1 | 66 ..indent += 1 |
| 67 ..addLine("initPolymer([") | 67 ..addLine("initPolymer([") |
| 68 ..indent += 2; | 68 ..indent += 2; |
| 69 | 69 |
| 70 for (var c in global.components.values) { | 70 for (var c in global.components.values) { |
| 71 if (c.hasConflict) continue; | 71 if (c.hasConflict) continue; |
| 72 printer.addLine("'${pathMapper.importUrlFor(info, c)}',"); | 72 printer.addLine("'${pathMapper.importUrlFor(info, c)}',"); |
| 73 } | 73 } |
| 74 | 74 |
| 75 if (userMainInfo.userCode != null) { |
| 76 printer.addLine("'${pathMapper.importUrlFor(info, userMainInfo)}',"); |
| 77 } |
| 78 |
| 75 return printer | 79 return printer |
| 76 ..indent -= 1 | 80 ..indent -= 1 |
| 77 ..addLine('],') | 81 ..addLine('],') |
| 78 ..addLine(userMainInfo.userCode != null ? 'userMain.main,' : '() {},') | |
| 79 ..addLine( | 82 ..addLine( |
| 80 "currentMirrorSystem().findLibrary(const Symbol('app_bootstrap'))") | 83 "currentMirrorSystem().findLibrary(const Symbol('app_bootstrap'))") |
| 81 ..indent += 2 | 84 ..indent += 2 |
| 82 ..addLine(".first.uri.toString());") | 85 ..addLine(".first.uri.toString());") |
| 83 ..indent -= 4 | 86 ..indent -= 4 |
| 84 ..addLine('}'); | 87 ..addLine('}'); |
| 85 } | 88 } |
| 86 | 89 |
| 87 | 90 |
| 88 /** | 91 /** |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 // For simplicity we emit the warning always, like validator.nu does. | 240 // For simplicity we emit the warning always, like validator.nu does. |
| 238 if (doctype.tagName != 'html' || commentIndex != 1) { | 241 if (doctype.tagName != 'html' || commentIndex != 1) { |
| 239 messages.warning('file should start with <!DOCTYPE html> ' | 242 messages.warning('file should start with <!DOCTYPE html> ' |
| 240 'to avoid the possibility of it being parsed in quirks mode in IE. ' | 243 'to avoid the possibility of it being parsed in quirks mode in IE. ' |
| 241 'See http://www.w3.org/TR/html5-diff/#doctype', doctype.sourceSpan); | 244 'See http://www.w3.org/TR/html5-diff/#doctype', doctype.sourceSpan); |
| 242 } | 245 } |
| 243 } | 246 } |
| 244 document.nodes.insert(commentIndex, parseFragment( | 247 document.nodes.insert(commentIndex, parseFragment( |
| 245 '\n<!-- This file was auto-generated from $filePath. -->\n')); | 248 '\n<!-- This file was auto-generated from $filePath. -->\n')); |
| 246 } | 249 } |
| OLD | NEW |