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

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

Issue 26051002: Updating Polymer to derive from custom elements. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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.build.polyfill_injector; 9 library polymer.src.build.polyfill_injector;
10 10
(...skipping 16 matching lines...) Expand all
27 PolyfillInjector(this.options); 27 PolyfillInjector(this.options);
28 28
29 /** Only run on entry point .html files. */ 29 /** Only run on entry point .html files. */
30 Future<bool> isPrimary(Asset input) => 30 Future<bool> isPrimary(Asset input) =>
31 new Future.value(options.isHtmlEntryPoint(input.id)); 31 new Future.value(options.isHtmlEntryPoint(input.id));
32 32
33 Future apply(Transform transform) { 33 Future apply(Transform transform) {
34 return readPrimaryAsHtml(transform).then((document) { 34 return readPrimaryAsHtml(transform).then((document) {
35 bool shadowDomFound = false; 35 bool shadowDomFound = false;
36 bool jsInteropFound = false; 36 bool jsInteropFound = false;
37 bool customElementFound = false;
37 bool dartScriptTags = false; 38 bool dartScriptTags = false;
38 39
39 for (var tag in document.queryAll('script')) { 40 for (var tag in document.queryAll('script')) {
40 var src = tag.attributes['src']; 41 var src = tag.attributes['src'];
41 if (src != null) { 42 if (src != null) {
42 var last = src.split('/').last; 43 var last = src.split('/').last;
43 if (last == 'interop.js') { 44 if (last == 'interop.js') {
44 jsInteropFound = true; 45 jsInteropFound = true;
45 } else if (_shadowDomJS.hasMatch(last)) { 46 } else if (_shadowDomJS.hasMatch(last)) {
46 shadowDomFound = true; 47 shadowDomFound = true;
48 } else if (_customElementJS.hasMatch(last)) {
49 customElementFound = true;
47 } 50 }
48 } 51 }
49 52
50 if (tag.attributes['type'] == 'application/dart') { 53 if (tag.attributes['type'] == 'application/dart') {
51 dartScriptTags = true; 54 dartScriptTags = true;
52 } 55 }
53 } 56 }
54 57
55 if (!dartScriptTags) { 58 if (!dartScriptTags) {
56 // This HTML has no Dart code, there is nothing to do here. 59 // This HTML has no Dart code, there is nothing to do here.
57 transform.addOutput(transform.primaryInput); 60 transform.addOutput(transform.primaryInput);
58 return; 61 return;
59 } 62 }
60 63
61 if (!jsInteropFound) { 64 if (!jsInteropFound) {
62 // JS interop code is required for Polymer CSS shimming. 65 // JS interop code is required for Polymer CSS shimming.
63 document.body.nodes.insert(0, parseFragment( 66 document.body.nodes.insert(0, parseFragment(
64 '<script src="packages/browser/interop.js"></script>\n')); 67 '<script src="packages/browser/interop.js"></script>\n'));
65 } 68 }
66 69
70 if (!customElementFound) {
71 document.body.nodes.insert(0, parseFragment(
72 '<script src="packages/custom_element/custom-elements.debug.js">'
73 '</script>\n'));
74 }
75
67 if (!shadowDomFound) { 76 if (!shadowDomFound) {
68 // Insert at the beginning (this polyfill needs to run as early as 77 // Insert at the beginning (this polyfill needs to run as early as
69 // possible). 78 // possible).
70 // TODO(jmesserly): this is .debug to workaround issue 13046. 79 // TODO(jmesserly): this is .debug to workaround issue 13046.
71 document.body.nodes.insert(0, parseFragment( 80 document.body.nodes.insert(0, parseFragment(
72 '<script src="packages/shadow_dom/shadow_dom.debug.js"></script>\n') ); 81 '<script src="packages/shadow_dom/shadow_dom.debug.js"></script>\n') );
73 } 82 }
74 83
75 transform.addOutput( 84 transform.addOutput(
76 new Asset.fromString(transform.primaryInput.id, document.outerHtml)); 85 new Asset.fromString(transform.primaryInput.id, document.outerHtml));
77 }); 86 });
78 } 87 }
79 } 88 }
80 89
81 final _shadowDomJS = new RegExp(r'shadow_dom\..*\.js', caseSensitive: false); 90 final _shadowDomJS = new RegExp(r'shadow_dom\..*\.js', caseSensitive: false);
91 final _customElementJS = new RegExp(r'custom-elements\..*\.js',
92 caseSensitive: false);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698