| 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 inlines polymer-element definitions from html imports. */ | 5 /** Transfomer that inlines polymer-element definitions from html imports. */ |
| 6 library polymer.src.transform.import_inliner; | 6 library polymer.src.transform.import_inliner; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 | 9 |
| 10 import 'package:barback/barback.dart'; | 10 import 'package:barback/barback.dart'; |
| 11 import 'package:html5lib/dom.dart' show Document, Node, DocumentFragment; | 11 import 'package:html5lib/dom.dart' show Document, Node, DocumentFragment; |
| 12 import 'common.dart'; | 12 import 'common.dart'; |
| 13 | 13 |
| 14 /** Recursively inlines polymer-element definitions from html imports. */ | 14 /** Recursively inlines polymer-element definitions from html imports. */ |
| 15 // TODO(sigmund): make sure we match semantics of html-imports for tags other | 15 // TODO(sigmund): make sure we match semantics of html-imports for tags other |
| 16 // than polymer-element (see dartbug.com/12613). | 16 // than polymer-element (see dartbug.com/12613). |
| 17 class ImportedElementInliner extends Transformer { | 17 class ImportedElementInliner extends Transformer { |
| 18 Future<bool> isPrimary(Asset input) => | 18 Future<bool> isPrimary(Asset input) => |
| 19 new Future.value(input.id.extension == ".html"); | 19 new Future.value(input.id.extension == ".html"); |
| 20 | 20 |
| 21 Future apply(Transform transform) { | 21 Future apply(Transform transform) { |
| 22 var seen = new Set<AssetId>(); | 22 var seen = new Set<AssetId>(); |
| 23 var elements = []; | 23 var elements = []; |
| 24 var id = transform.primaryId; | 24 var id = transform.primaryInput.id; |
| 25 seen.add(id); | 25 seen.add(id); |
| 26 return getPrimaryContent(transform).then((content) { | 26 return transform.primaryInput.readAsString().then((content) { |
| 27 var document = parseHtml(content, id.path, transform.logger); | 27 var document = parseHtml(content, id.path, transform.logger); |
| 28 var future = _visitImports(document, id, transform, seen, elements); | 28 var future = _visitImports(document, id, transform, seen, elements); |
| 29 return future.then((importsFound) { | 29 return future.then((importsFound) { |
| 30 if (!importsFound) { | 30 if (!importsFound) { |
| 31 transform.addOutput(new Asset.fromString(id, content)); | 31 transform.addOutput(new Asset.fromString(id, content)); |
| 32 return; | 32 return; |
| 33 } | 33 } |
| 34 | 34 |
| 35 for (var tag in document.queryAll('link')) { | 35 for (var tag in document.queryAll('link')) { |
| 36 if (tag.attributes['rel'] == 'import') { | 36 if (tag.attributes['rel'] == 'import') { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 return _collectPolymerElements(id, transform, seen, elements); | 73 return _collectPolymerElements(id, transform, seen, elements); |
| 74 }).then((_) => true); | 74 }).then((_) => true); |
| 75 } | 75 } |
| 76 | 76 |
| 77 /** | 77 /** |
| 78 * Loads an asset identified by [id], visits its imports and collects it's | 78 * Loads an asset identified by [id], visits its imports and collects it's |
| 79 * polymer-element definitions. | 79 * polymer-element definitions. |
| 80 */ | 80 */ |
| 81 Future _collectPolymerElements( | 81 Future _collectPolymerElements( |
| 82 AssetId id, Transform transform, Set<AssetId> seen, List elements) { | 82 AssetId id, Transform transform, Set<AssetId> seen, List elements) { |
| 83 return getContent(transform, id) | 83 return transform.readInputAsString(id) |
| 84 .then((content) => parseHtml( | 84 .then((content) => parseHtml( |
| 85 content, id.path, transform.logger, checkDocType: false)) | 85 content, id.path, transform.logger, checkDocType: false)) |
| 86 .then((document) { | 86 .then((document) { |
| 87 return _visitImports(document, id, transform, seen, elements) | 87 return _visitImports(document, id, transform, seen, elements) |
| 88 .then((_) => elements.addAll(document.queryAll('polymer-element'))); | 88 .then((_) => elements.addAll(document.queryAll('polymer-element'))); |
| 89 }); | 89 }); |
| 90 } | 90 } |
| 91 } | 91 } |
| OLD | NEW |