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

Side by Side Diff: pkg/polymer/lib/src/transform/import_inliner.dart

Issue 23478015: Apply several phases only to entrypoint files (which currently are identified as (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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 /** 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:path/path.dart' as path; 11 import 'package:path/path.dart' as path;
12 import 'package:html5lib/dom.dart' show Document, Node, DocumentFragment; 12 import 'package:html5lib/dom.dart' show Document, Node, DocumentFragment;
13 import 'package:html5lib/dom_parsing.dart' show TreeVisitor; 13 import 'package:html5lib/dom_parsing.dart' show TreeVisitor;
14 import 'common.dart'; 14 import 'common.dart';
15 15
16 /** Recursively inlines polymer-element definitions from html imports. */ 16 /** Recursively inlines polymer-element definitions from html imports. */
17 // TODO(sigmund): make sure we match semantics of html-imports for tags other 17 // TODO(sigmund): make sure we match semantics of html-imports for tags other
18 // than polymer-element (see dartbug.com/12613). 18 // than polymer-element (see dartbug.com/12613).
19 class ImportedElementInliner extends Transformer { 19 class ImportedElementInliner extends Transformer {
20 /** Only run this transformer on .html files. */ 20 /** Only run on entrypoint .html files under web or test. */
Jennifer Messerly 2013/09/04 02:35:04 nit: space between entry and point
Siggi Cherem (dart-lang) 2013/09/04 16:30:16 Done.
21 final String allowedExtensions = ".html"; 21 Future<bool> isPrimary(Asset input) => isHtmlInWebOrTest(input.id);
22 22
23 Future apply(Transform transform) { 23 Future apply(Transform transform) {
24 var seen = new Set<AssetId>(); 24 var seen = new Set<AssetId>();
25 var elements = []; 25 var elements = [];
26 var id = transform.primaryInput.id; 26 var id = transform.primaryInput.id;
27 seen.add(id); 27 seen.add(id);
28 return transform.primaryInput.readAsString().then((content) { 28 return transform.primaryInput.readAsString().then((content) {
29 var document = parseHtml(content, id.path, transform.logger); 29 var document = parseHtml(content, id.path, transform.logger,
30 checkDocType: true);
30 var future = _visitImports(document, id, transform, seen, elements); 31 var future = _visitImports(document, id, transform, seen, elements);
31 return future.then((importsFound) { 32 return future.then((importsFound) {
32 if (!importsFound) { 33 if (!importsFound) {
33 transform.addOutput(new Asset.fromString(id, content)); 34 transform.addOutput(new Asset.fromString(id, content));
34 return; 35 return;
35 } 36 }
36 37
37 for (var tag in document.queryAll('link')) { 38 for (var tag in document.queryAll('link')) {
38 if (tag.attributes['rel'] == 'import') { 39 if (tag.attributes['rel'] == 'import') {
39 tag.remove(); 40 tag.remove();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 }).then((_) => true); 77 }).then((_) => true);
77 } 78 }
78 79
79 /** 80 /**
80 * Loads an asset identified by [id], visits its imports and collects it's 81 * Loads an asset identified by [id], visits its imports and collects it's
81 * polymer-element definitions. 82 * polymer-element definitions.
82 */ 83 */
83 Future _collectPolymerElements(AssetId id, Transform transform, 84 Future _collectPolymerElements(AssetId id, Transform transform,
84 Set<AssetId> seen, List elements) { 85 Set<AssetId> seen, List elements) {
85 return transform.readInputAsString(id).then((content) { 86 return transform.readInputAsString(id).then((content) {
86 var document = parseHtml( 87 var document = parseHtml(content, id.path, transform.logger);
Jennifer Messerly 2013/09/04 02:35:04 it's not a big deal but i'm not sure about flippin
Siggi Cherem (dart-lang) 2013/09/04 16:30:16 :) - good point, I flipped it back.
87 content, id.path, transform.logger, checkDocType: false);
88 return _visitImports(document, id, transform, seen, elements).then((_) { 88 return _visitImports(document, id, transform, seen, elements).then((_) {
89 var normalizer = new _UrlNormalizer(transform, id); 89 var normalizer = new _UrlNormalizer(transform, id);
90 for (var element in document.queryAll('polymer-element')) { 90 for (var element in document.queryAll('polymer-element')) {
91 normalizer.visit(document); 91 normalizer.visit(document);
92 elements.add(element); 92 elements.add(element);
93 } 93 }
94 }); 94 });
95 }); 95 });
96 } 96 }
97 } 97 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 'cite', // in blockquote, del, ins, q 161 'cite', // in blockquote, del, ins, q
162 'data', // in object 162 'data', // in object
163 'formaction', // in button, input 163 'formaction', // in button, input
164 'href', // in a, area, link, base, command 164 'href', // in a, area, link, base, command
165 'icon', // in command 165 'icon', // in command
166 'manifest', // in html 166 'manifest', // in html
167 'poster', // in video 167 'poster', // in video
168 'src', // in audio, embed, iframe, img, input, script, source, track, 168 'src', // in audio, embed, iframe, img, input, script, source, track,
169 // video 169 // video
170 ]; 170 ];
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698