| 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 /** | 5 /** |
| 6 * Final phase of the polymer transformation: includes any additional polyfills | 6 * Final phase of the polymer transformation: includes any additional polyfills |
| 7 * that may needed by the deployed app. | 7 * that may needed by the deployed app. |
| 8 */ | 8 */ |
| 9 library polymer.src.transform.polyfill_injector; | 9 library polymer.src.transform.polyfill_injector; |
| 10 | 10 |
| 11 import 'dart:async'; | 11 import 'dart:async'; |
| 12 | 12 |
| 13 import 'package:barback/barback.dart'; | 13 import 'package:barback/barback.dart'; |
| 14 import 'package:html5lib/dom.dart' show Document, Node, DocumentFragment; | 14 import 'package:html5lib/dom.dart' show Document, Node, DocumentFragment; |
| 15 import 'package:html5lib/parser.dart' show parseFragment; | 15 import 'package:html5lib/parser.dart' show parseFragment; |
| 16 import 'common.dart'; | 16 import 'common.dart'; |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * Ensures that any scripts and polyfills needed to run a polymer application | 19 * Ensures that any scripts and polyfills needed to run a polymer application |
| 20 * are included. For example, this transformer will ensure that there is a | 20 * are included. For example, this transformer will ensure that there is a |
| 21 * script tag that loads the shadow_dom polyfill and interop.js (used for the | 21 * script tag that loads the shadow_dom polyfill and interop.js (used for the |
| 22 * css shimming). | 22 * css shimming). |
| 23 */ | 23 */ |
| 24 class PolyfillInjector extends Transformer { | 24 class PolyfillInjector extends Transformer with PolymerTransformer { |
| 25 final TransformOptions options; |
| 26 |
| 27 PolyfillInjector(this.options); |
| 28 |
| 25 /** Only run on entry point .html files. */ | 29 /** Only run on entry point .html files. */ |
| 26 Future<bool> isPrimary(Asset input) => | 30 Future<bool> isPrimary(Asset input) => |
| 27 new Future.value(isPrimaryHtml(input.id)); | 31 new Future.value(options.isHtmlEntryPoint(input.id)); |
| 28 | 32 |
| 29 Future apply(Transform transform) { | 33 Future apply(Transform transform) { |
| 30 return readPrimaryAsHtml(transform).then((document) { | 34 return readPrimaryAsHtml(transform).then((document) { |
| 31 bool shadowDomFound = false; | 35 bool shadowDomFound = false; |
| 32 bool jsInteropFound = false; | 36 bool jsInteropFound = false; |
| 33 bool pkgJsInteropFound = false; | 37 bool pkgJsInteropFound = false; |
| 34 bool dartScriptTags = false; | 38 bool dartScriptTags = false; |
| 35 | 39 |
| 36 for (var tag in document.queryAll('script')) { | 40 for (var tag in document.queryAll('script')) { |
| 37 var src = tag.attributes['src']; | 41 var src = tag.attributes['src']; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 '<script src="packages/shadow_dom/shadow_dom.debug.js"></script>\n')
); | 81 '<script src="packages/shadow_dom/shadow_dom.debug.js"></script>\n')
); |
| 78 } | 82 } |
| 79 | 83 |
| 80 transform.addOutput( | 84 transform.addOutput( |
| 81 new Asset.fromString(transform.primaryInput.id, document.outerHtml)); | 85 new Asset.fromString(transform.primaryInput.id, document.outerHtml)); |
| 82 }); | 86 }); |
| 83 } | 87 } |
| 84 } | 88 } |
| 85 | 89 |
| 86 final _shadowDomJS = new RegExp(r'shadow_dom\..*\.js', caseSensitive: false); | 90 final _shadowDomJS = new RegExp(r'shadow_dom\..*\.js', caseSensitive: false); |
| OLD | NEW |