| 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 /** Transfomer that combines multiple dart script tags into a single one. */ | 5 /** Transfomer that combines multiple dart script tags into a single one. */ |
| 6 library polymer.src.transform.script_compactor; | 6 library polymer.src.transform.script_compactor; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 | 9 |
| 10 import 'package:barback/barback.dart'; | 10 import 'package:barback/barback.dart'; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * This transformer assumes that all script tags point to external files. To | 21 * This transformer assumes that all script tags point to external files. To |
| 22 * support script tags with inlined code, use this transformer after running | 22 * support script tags with inlined code, use this transformer after running |
| 23 * [InlineCodeExtractor] on an earlier phase. | 23 * [InlineCodeExtractor] on an earlier phase. |
| 24 * | 24 * |
| 25 * Internally, this transformer will convert each script tag into an import | 25 * Internally, this transformer will convert each script tag into an import |
| 26 * statement to a library, and then uses `initPolymer` (see polymer.dart) to | 26 * statement to a library, and then uses `initPolymer` (see polymer.dart) to |
| 27 * invoke the main method on each of these libraries and register any polymer | 27 * invoke the main method on each of these libraries and register any polymer |
| 28 * elements annotated with `@CustomTag`. | 28 * elements annotated with `@CustomTag`. |
| 29 */ | 29 */ |
| 30 class ScriptCompactor extends Transformer { | 30 class ScriptCompactor extends Transformer { |
| 31 /** Only run this transformer on .html files. */ | 31 /** Only run on entry point .html files. */ |
| 32 final String allowedExtensions = ".html"; | 32 Future<bool> isPrimary(Asset input) => isPrimaryHtml(input.id); |
| 33 | 33 |
| 34 Future apply(Transform transform) { | 34 Future apply(Transform transform) { |
| 35 var id = transform.primaryInput.id; | 35 var id = transform.primaryInput.id; |
| 36 var logger = transform.logger; | 36 var logger = transform.logger; |
| 37 return transform.primaryInput.readAsString().then((content) { | 37 return transform.primaryInput.readAsString().then((content) { |
| 38 var document = parseHtml(content, id.path, logger); | 38 var document = parseHtml(content, id.path, logger, |
| 39 checkDocType: false); |
| 39 var libraries = []; | 40 var libraries = []; |
| 40 bool changed = false; | 41 bool changed = false; |
| 41 var dartLoaderTag = null; | 42 var dartLoaderTag = null; |
| 42 for (var tag in document.queryAll('script')) { | 43 for (var tag in document.queryAll('script')) { |
| 43 var src = tag.attributes['src']; | 44 var src = tag.attributes['src']; |
| 44 if (src != null) { | 45 if (src != null) { |
| 45 if (src == 'packages/polymer/boot.js') { | 46 if (src == 'packages/polymer/boot.js') { |
| 46 tag.remove(); | 47 tag.remove(); |
| 47 continue; | 48 continue; |
| 48 } | 49 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 137 |
| 137 void main() { | 138 void main() { |
| 138 initPolymer([ | 139 initPolymer([ |
| 139 """; | 140 """; |
| 140 | 141 |
| 141 // TODO(sigmund): investigate alternative to get the baseUri (dartbug.com/12612) | 142 // TODO(sigmund): investigate alternative to get the baseUri (dartbug.com/12612) |
| 142 const _mainSuffix = """ | 143 const _mainSuffix = """ |
| 143 ], currentMirrorSystem().isolate.rootLibrary.uri.toString()); | 144 ], currentMirrorSystem().isolate.rootLibrary.uri.toString()); |
| 144 } | 145 } |
| 145 """; | 146 """; |
| OLD | NEW |