| 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 Future<bool> isPrimary(Asset input) => | 31 /** Only run this transformer on .html files. */ |
| 32 new Future.value(input.id.extension == ".html"); | 32 final String allowedExtensions = ".html"; |
| 33 | 33 |
| 34 Future apply(Transform transform) { | 34 Future apply(Transform transform) { |
| 35 var id = transform.primaryId; | 35 var id = transform.primaryId; |
| 36 var logger = transform.logger; | 36 var logger = transform.logger; |
| 37 return getPrimaryContent(transform).then((content) { | 37 return getPrimaryContent(transform).then((content) { |
| 38 var document = parseHtml(content, id.path, logger); | 38 var document = parseHtml(content, id.path, logger); |
| 39 var libraries = []; | 39 var libraries = []; |
| 40 bool changed = false; | 40 bool changed = false; |
| 41 var dartLoaderTag = null; | 41 var dartLoaderTag = null; |
| 42 for (var tag in document.queryAll('script')) { | 42 for (var tag in document.queryAll('script')) { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 136 |
| 137 void main() { | 137 void main() { |
| 138 initPolymer([ | 138 initPolymer([ |
| 139 """; | 139 """; |
| 140 | 140 |
| 141 // TODO(sigmund): investigate alternative to get the baseUri (dartbug.com/12612) | 141 // TODO(sigmund): investigate alternative to get the baseUri (dartbug.com/12612) |
| 142 const _mainSuffix = """ | 142 const _mainSuffix = """ |
| 143 ], currentMirrorSystem().isolate.rootLibrary.uri.toString()); | 143 ], currentMirrorSystem().isolate.rootLibrary.uri.toString()); |
| 144 } | 144 } |
| 145 """; | 145 """; |
| OLD | NEW |