| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /// Includes any additional polyfills that may needed by the deployed app. | 5 /// Includes any additional polyfills that may needed by the deployed app. |
| 6 library polymer.src.build.polyfill_injector; | 6 library polymer.src.build.polyfill_injector; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 | 9 |
| 10 import 'package:barback/barback.dart'; | 10 import 'package:barback/barback.dart'; |
| 11 import 'package:html5lib/dom.dart' show | 11 import 'package:html5lib/dom.dart' show |
| 12 Document, DocumentFragment, Element, Node; | 12 Document, DocumentFragment, Element, Node; |
| 13 import 'package:html5lib/parser.dart' show parseFragment; | 13 import 'package:html5lib/parser.dart' show parseFragment; |
| 14 import 'package:code_transformers/messages/build_logger.dart'; |
| 14 import 'common.dart'; | 15 import 'common.dart'; |
| 15 | 16 |
| 16 /// Ensures that any scripts and polyfills needed to run a polymer application | 17 /// Ensures that any scripts and polyfills needed to run a polymer application |
| 17 /// are included. | 18 /// are included. |
| 18 /// | 19 /// |
| 19 /// This step also replaces "packages/browser/dart.js" and the Dart script tag | 20 /// This step also replaces "packages/browser/dart.js" and the Dart script tag |
| 20 /// with a script tag that loads the dart2js compiled code directly. | 21 /// with a script tag that loads the dart2js compiled code directly. |
| 21 class PolyfillInjector extends Transformer with PolymerTransformer { | 22 class PolyfillInjector extends Transformer with PolymerTransformer { |
| 22 final TransformOptions options; | 23 final TransformOptions options; |
| 23 | 24 |
| 24 PolyfillInjector(this.options); | 25 PolyfillInjector(this.options); |
| 25 | 26 |
| 26 /// Only run on entry point .html files. | 27 /// Only run on entry point .html files. |
| 27 // TODO(nweiz): This should just take an AssetId when barback <0.13.0 support | 28 // TODO(nweiz): This should just take an AssetId when barback <0.13.0 support |
| 28 // is dropped. | 29 // is dropped. |
| 29 Future<bool> isPrimary(idOrAsset) { | 30 Future<bool> isPrimary(idOrAsset) { |
| 30 var id = idOrAsset is AssetId ? idOrAsset : idOrAsset.id; | 31 var id = idOrAsset is AssetId ? idOrAsset : idOrAsset.id; |
| 31 return new Future.value(options.isHtmlEntryPoint(id)); | 32 return new Future.value(options.isHtmlEntryPoint(id)); |
| 32 } | 33 } |
| 33 | 34 |
| 34 Future apply(Transform transform) { | 35 Future apply(Transform transform) { |
| 35 return readPrimaryAsHtml(transform).then((document) { | 36 var logger = new BuildLogger(transform, |
| 37 convertErrorsToWarnings: !options.releaseMode); |
| 38 return readPrimaryAsHtml(transform, logger).then((document) { |
| 36 bool webComponentsFound = false; | 39 bool webComponentsFound = false; |
| 37 Element dartJs; | 40 Element dartJs; |
| 38 final dartScripts = <Element>[]; | 41 final dartScripts = <Element>[]; |
| 39 | 42 |
| 40 for (var tag in document.querySelectorAll('script')) { | 43 for (var tag in document.querySelectorAll('script')) { |
| 41 var src = tag.attributes['src']; | 44 var src = tag.attributes['src']; |
| 42 if (src != null) { | 45 if (src != null) { |
| 43 var last = src.split('/').last; | 46 var last = src.split('/').last; |
| 44 if (_webComponentsJS.hasMatch(last)) { | 47 if (_webComponentsJS.hasMatch(last)) { |
| 45 webComponentsFound = true; | 48 webComponentsFound = true; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 } | 102 } |
| 100 | 103 |
| 101 transform.addOutput( | 104 transform.addOutput( |
| 102 new Asset.fromString(transform.primaryInput.id, document.outerHtml)); | 105 new Asset.fromString(transform.primaryInput.id, document.outerHtml)); |
| 103 }); | 106 }); |
| 104 } | 107 } |
| 105 } | 108 } |
| 106 | 109 |
| 107 final _webComponentsJS = new RegExp(r'platform.*\.js', | 110 final _webComponentsJS = new RegExp(r'platform.*\.js', |
| 108 caseSensitive: false); | 111 caseSensitive: false); |
| OLD | NEW |