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 'common.dart'; | 14 import 'common.dart'; |
15 | 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. For example, this transformer will ensure that there is a |
18 * are included. For example, this transformer will ensure that there is a | 18 /// script tag that loads the polyfills and interop.js (used for css shimming). |
19 * script tag that loads the polyfills and interop.js (used for css shimming). | 19 /// |
20 * | 20 /// This step also replaces "packages/browser/dart.js" and the Dart script tag |
21 * This step also replaces "packages/browser/dart.js" and the Dart script tag | 21 /// with a script tag that loads the dart2js compiled code directly. |
22 * with a script tag that loads the dart2js compiled code directly. | |
23 */ | |
24 class PolyfillInjector extends Transformer with PolymerTransformer { | 22 class PolyfillInjector extends Transformer with PolymerTransformer { |
25 final TransformOptions options; | 23 final TransformOptions options; |
26 | 24 |
27 PolyfillInjector(this.options); | 25 PolyfillInjector(this.options); |
28 | 26 |
29 /** Only run on entry point .html files. */ | 27 /// Only run on entry point .html files. |
30 Future<bool> isPrimary(Asset input) => | 28 Future<bool> isPrimary(Asset input) => |
31 new Future.value(options.isHtmlEntryPoint(input.id)); | 29 new Future.value(options.isHtmlEntryPoint(input.id)); |
32 | 30 |
33 Future apply(Transform transform) { | 31 Future apply(Transform transform) { |
34 return readPrimaryAsHtml(transform).then((document) { | 32 return readPrimaryAsHtml(transform).then((document) { |
35 bool webComponentsFound = false; | 33 bool webComponentsFound = false; |
36 bool jsInteropFound = false; | 34 bool jsInteropFound = false; |
37 Element dartJs; | 35 Element dartJs; |
38 final dartScripts = <Element>[]; | 36 final dartScripts = <Element>[]; |
39 | 37 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 } | 100 } |
103 | 101 |
104 transform.addOutput( | 102 transform.addOutput( |
105 new Asset.fromString(transform.primaryInput.id, document.outerHtml)); | 103 new Asset.fromString(transform.primaryInput.id, document.outerHtml)); |
106 }); | 104 }); |
107 } | 105 } |
108 } | 106 } |
109 | 107 |
110 final _webComponentsJS = new RegExp(r'platform.*\.js', | 108 final _webComponentsJS = new RegExp(r'platform.*\.js', |
111 caseSensitive: false); | 109 caseSensitive: false); |
OLD | NEW |