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

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

Issue 27903006: Improves how to initialize polymer apps and fixes polymer build and linter to (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 18 matching lines...) Expand all
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 customElementFound = false;
38 bool dartScriptTags = false; 38 bool dartScriptTags = false;
39 bool dartLoaderTagFound = false;
39 40
40 for (var tag in document.queryAll('script')) { 41 for (var tag in document.queryAll('script')) {
41 var src = tag.attributes['src']; 42 var src = tag.attributes['src'];
42 if (src != null) { 43 if (src != null) {
43 var last = src.split('/').last; 44 var last = src.split('/').last;
44 if (last == 'interop.js') { 45 if (last == 'interop.js') {
45 jsInteropFound = true; 46 jsInteropFound = true;
46 } else if (_shadowDomJS.hasMatch(last)) { 47 } else if (_shadowDomJS.hasMatch(last)) {
47 shadowDomFound = true; 48 shadowDomFound = true;
48 } else if (_customElementJS.hasMatch(last)) { 49 } else if (_customElementJS.hasMatch(last)) {
49 customElementFound = true; 50 customElementFound = true;
51 } else if (last == 'dart.js') {
52 dartLoaderTagFound = true;
50 } 53 }
51 } 54 }
52 55
53 if (tag.attributes['type'] == 'application/dart') { 56 if (tag.attributes['type'] == 'application/dart') {
54 dartScriptTags = true; 57 dartScriptTags = true;
55 } 58 }
56 } 59 }
57 60
58 if (!dartScriptTags) { 61 if (!dartScriptTags) {
59 // This HTML has no Dart code, there is nothing to do here. 62 // This HTML has no Dart code, there is nothing to do here.
60 transform.addOutput(transform.primaryInput); 63 transform.addOutput(transform.primaryInput);
61 return; 64 return;
62 } 65 }
63 66
64 _addScript(urlSegment) { 67 _addScript(urlSegment) {
65 document.body.nodes.insert(0, parseFragment( 68 document.head.nodes.insert(0, parseFragment(
66 '<script src="packages/$urlSegment"></script>\n')); 69 '<script src="packages/$urlSegment"></script>\n'));
67 } 70 }
68 71
69 // JS interop code is required for Polymer CSS shimming. 72 // JS interop code is required for Polymer CSS shimming.
70 if (!jsInteropFound) _addScript('browser/interop.js'); 73 if (!jsInteropFound) _addScript('browser/interop.js');
71 if (!customElementFound) { 74 if (!customElementFound) {
72 _addScript('custom_element/custom-elements.debug.js'); 75 _addScript('custom_element/custom-elements.debug.js');
73 } 76 }
74 77
75 // This polyfill needs to be the first one on the body 78 // This polyfill needs to be the first one on the head
76 // TODO(jmesserly): this is .debug to workaround issue 13046. 79 // TODO(jmesserly): this is .debug to workaround issue 13046.
77 if (!shadowDomFound) _addScript('shadow_dom/shadow_dom.debug.js'); 80 if (!shadowDomFound) _addScript('shadow_dom/shadow_dom.debug.js');
78 81
82 if (!dartLoaderTagFound) {
83 document.body.nodes.add(parseFragment(
84 '<script src="packages/browser/dart.js"></script>'));
85 }
86
79 transform.addOutput( 87 transform.addOutput(
80 new Asset.fromString(transform.primaryInput.id, document.outerHtml)); 88 new Asset.fromString(transform.primaryInput.id, document.outerHtml));
81 }); 89 });
82 } 90 }
83 } 91 }
84 92
85 final _shadowDomJS = new RegExp(r'shadow_dom\..*\.js', caseSensitive: false); 93 final _shadowDomJS = new RegExp(r'shadow_dom\..*\.js', caseSensitive: false);
86 final _customElementJS = new RegExp(r'custom-elements\..*\.js', 94 final _customElementJS = new RegExp(r'custom-elements\..*\.js',
87 caseSensitive: false); 95 caseSensitive: false);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698