Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: pkg/polymer/lib/src/transform/polyfill_injector.dart

Issue 23478015: Apply several phases only to entrypoint files (which currently are identified as (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 {
25 /** Only run this transformer on .html files. */ 25 /** Only run on entry point .html files. */
26 final String allowedExtensions = ".html"; 26 Future<bool> isPrimary(Asset input) => isPrimaryHtml(input.id);
27 27
28 Future apply(Transform transform) { 28 Future apply(Transform transform) {
29 var id = transform.primaryInput.id; 29 var id = transform.primaryInput.id;
30 return transform.primaryInput.readAsString().then((content) { 30 return transform.primaryInput.readAsString().then((content) {
31 var document = parseHtml(content, id.path, transform.logger); 31 var document = parseHtml(content, id.path, transform.logger,
32 checkDocType: false);
32 bool shadowDomFound = false; 33 bool shadowDomFound = false;
33 bool jsInteropFound = false; 34 bool jsInteropFound = false;
34 bool dartScriptTags = false; 35 bool dartScriptTags = false;
35 36
36 for (var tag in document.queryAll('script')) { 37 for (var tag in document.queryAll('script')) {
37 var src = tag.attributes['src']; 38 var src = tag.attributes['src'];
38 if (src != null) { 39 if (src != null) {
39 var last = src.split('/').last; 40 var last = src.split('/').last;
40 if (last == 'interop.js') { 41 if (last == 'interop.js') {
41 jsInteropFound = true; 42 jsInteropFound = true;
(...skipping 25 matching lines...) Expand all
67 document.body.nodes.insert(0, parseFragment( 68 document.body.nodes.insert(0, parseFragment(
68 '<script src="packages/shadow_dom/shadow_dom.min.js"></script>\n')); 69 '<script src="packages/shadow_dom/shadow_dom.min.js"></script>\n'));
69 } 70 }
70 71
71 transform.addOutput(new Asset.fromString(id, document.outerHtml)); 72 transform.addOutput(new Asset.fromString(id, document.outerHtml));
72 }); 73 });
73 } 74 }
74 } 75 }
75 76
76 final _shadowDomJS = new RegExp(r'shadow_dom\..*\.js', caseSensitive: false); 77 final _shadowDomJS = new RegExp(r'shadow_dom\..*\.js', caseSensitive: false);
OLDNEW
« no previous file with comments | « pkg/polymer/lib/src/transform/import_inliner.dart ('k') | pkg/polymer/lib/src/transform/script_compactor.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698