| 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: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 Loading... |
| 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:polymer/polymer.dart' as polymer;"); | 251 ..addLine("import 'package:polymer/polymer.dart';") |
| 252 ..addLine("import 'dart:mirrors' show currentMirrorSystem;"); |
| 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 |
| 260 int i = 0; |
| 259 for (var c in global.components.values) { | 261 for (var c in global.components.values) { |
| 260 if (c.hasConflict) continue; | 262 if (c.hasConflict) continue; |
| 261 printer.addLine("import '${pathMapper.importUrlFor(info, c)}';"); | 263 printer.addLine("import '${pathMapper.importUrlFor(info, c)}' as i$i;"); |
| 264 i++; |
| 262 } | 265 } |
| 263 | 266 |
| 264 printer..addLine('') | 267 printer..addLine('') |
| 265 ..addLine('void main() {') | 268 ..addLine('void main() {') |
| 266 ..indent += 1; | 269 ..indent += 1 |
| 267 | 270 ..addLine("initPolymer([") |
| 268 if (userMainInfo.userCode != null) printer.addLine('userMain.main();'); | 271 ..indent += 2; |
| 269 | 272 |
| 270 for (var c in global.components.values) { | 273 for (var c in global.components.values) { |
| 271 if (c.hasConflict) continue; | 274 if (c.hasConflict) continue; |
| 272 var tagName = escapeDartString(c.tagName); | 275 var tagName = escapeDartString(c.tagName); |
| 273 var cssMapExpression = createCssSelectorsExpression(c, | 276 var cssMapExpression = createCssSelectorsExpression(c, |
| 274 CssPolyfillKind.of(options, c)); | 277 CssPolyfillKind.of(options, c)); |
| 275 printer | 278 printer.addLine("'${pathMapper.importUrlFor(info, c)}',"); |
| 276 ..addLine("polymer.setScopedCss('$tagName', $cssMapExpression);") | |
| 277 ..addLine("polymer.registerPolymerElement(" | |
| 278 "'$tagName', () => new ${c.className}());"); | |
| 279 } | 279 } |
| 280 | 280 |
| 281 return printer | 281 return printer |
| 282 ..indent -= 1 | 282 ..indent -= 1 |
| 283 ..addLine('],') |
| 284 ..addLine(userMainInfo.userCode != null ? 'userMain.main,' : '() {},') |
| 285 ..addLine( |
| 286 "currentMirrorSystem().findLibrary(const Symbol('app_bootstrap'))") |
| 287 ..indent += 2 |
| 288 ..addLine(".first.uri.toString());") |
| 289 ..indent -= 4 |
| 283 ..addLine('}'); | 290 ..addLine('}'); |
| 284 } | 291 } |
| 285 | 292 |
| 286 | 293 |
| 287 | 294 |
| 288 /** | 295 /** |
| 289 * List of HTML4 elements which could have relative URL resource: | 296 * List of HTML4 elements which could have relative URL resource: |
| 290 * | 297 * |
| 291 * <body background=url>, <img src=url>, <input src=url> | 298 * <body background=url>, <img src=url>, <input src=url> |
| 292 * | 299 * |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 } | 360 } |
| 354 | 361 |
| 355 // Add existing import, export, and part directives. | 362 // Add existing import, export, and part directives. |
| 356 var file = codeInfo.sourceFile; | 363 var file = codeInfo.sourceFile; |
| 357 for (var d in codeInfo.directives) { | 364 for (var d in codeInfo.directives) { |
| 358 addUnique(d.toString(), file != null ? file.location(d.offset) : null); | 365 addUnique(d.toString(), file != null ? file.location(d.offset) : null); |
| 359 } | 366 } |
| 360 } | 367 } |
| 361 | 368 |
| 362 final shadowDomJS = new RegExp(r'shadowdom\..*\.js', caseSensitive: false); | 369 final shadowDomJS = new RegExp(r'shadowdom\..*\.js', caseSensitive: false); |
| 370 final bootJS = new RegExp(r'.*/polymer/boot.js', caseSensitive: false); |
| 363 | 371 |
| 364 /** Trim down the html for the main html page. */ | 372 /** Trim down the html for the main html page. */ |
| 365 void transformMainHtml(Document document, FileInfo fileInfo, | 373 void transformMainHtml(Document document, FileInfo fileInfo, |
| 366 PathMapper pathMapper, bool hasCss, bool rewriteUrls, | 374 PathMapper pathMapper, bool hasCss, bool rewriteUrls, |
| 367 Messages messages, GlobalInfo global) { | 375 Messages messages, GlobalInfo global) { |
| 368 var filePath = fileInfo.inputUrl.resolvedPath; | 376 var filePath = fileInfo.inputUrl.resolvedPath; |
| 369 | 377 |
| 370 bool dartLoaderFound = false; | 378 bool dartLoaderFound = false; |
| 371 bool shadowDomFound = false; | 379 bool shadowDomFound = false; |
| 372 for (var tag in document.queryAll('script')) { | 380 for (var tag in document.queryAll('script')) { |
| 373 var src = tag.attributes['src']; | 381 var src = tag.attributes['src']; |
| 374 if (src != null) { | 382 if (src != null) { |
| 375 var last = src.split('/').last; | 383 var last = src.split('/').last; |
| 376 if (last == 'dart.js' || last == 'testing.js') { | 384 if (last == 'dart.js' || last == 'testing.js') { |
| 377 dartLoaderFound = true; | 385 dartLoaderFound = true; |
| 378 } else if (shadowDomJS.hasMatch(last)) { | 386 } else if (shadowDomJS.hasMatch(last)) { |
| 379 shadowDomFound = true; | 387 shadowDomFound = true; |
| 380 } | 388 } |
| 381 } | 389 } |
| 382 if (tag.attributes['type'] == 'application/dart') { | 390 if (tag.attributes['type'] == 'application/dart') { |
| 383 tag.remove(); | 391 tag.remove(); |
| 384 } else if (src != null && rewriteUrls) { | 392 } else if (src != null) { |
| 385 tag.attributes["src"] = pathMapper.transformUrl(filePath, src); | 393 if (bootJS.hasMatch(src)) { |
| 394 tag.remove(); |
| 395 } else if (rewriteUrls) { |
| 396 tag.attributes["src"] = pathMapper.transformUrl(filePath, src); |
| 397 } |
| 386 } | 398 } |
| 387 } | 399 } |
| 388 | 400 |
| 389 for (var tag in document.queryAll('link')) { | 401 for (var tag in document.queryAll('link')) { |
| 390 var href = tag.attributes['href']; | 402 var href = tag.attributes['href']; |
| 391 var rel = tag.attributes['rel']; | 403 var rel = tag.attributes['rel']; |
| 392 if (rel == 'component' || rel == 'components' || rel == 'import') { | 404 if (rel == 'component' || rel == 'components' || rel == 'import') { |
| 393 tag.remove(); | 405 tag.remove(); |
| 394 } else if (href != null && rewriteUrls && !hasCss) { | 406 } else if (href != null && rewriteUrls && !hasCss) { |
| 395 // Only rewrite URL if rewrite on and we're not CSS polyfilling. | 407 // Only rewrite URL if rewrite on and we're not CSS polyfilling. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 // Auto-generated from $filename. | 497 // Auto-generated from $filename. |
| 486 // DO NOT EDIT. | 498 // DO NOT EDIT. |
| 487 $lib | 499 $lib |
| 488 import 'dart:html' as autogenerated; | 500 import 'dart:html' as autogenerated; |
| 489 import 'dart:svg' as autogenerated_svg; | 501 import 'dart:svg' as autogenerated_svg; |
| 490 import 'package:mdv/mdv.dart' as autogenerated_mdv; | 502 import 'package:mdv/mdv.dart' as autogenerated_mdv; |
| 491 import 'package:observe/observe.dart' as __observe; | 503 import 'package:observe/observe.dart' as __observe; |
| 492 import 'package:polymer/polymer.dart' as autogenerated; | 504 import 'package:polymer/polymer.dart' as autogenerated; |
| 493 """; | 505 """; |
| 494 } | 506 } |
| OLD | NEW |