Chromium Code Reviews| 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.build.import_inliner; | 6 library polymer.src.build.import_inliner; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:convert'; | 9 import 'dart:convert'; |
| 10 | 10 |
| 11 import 'package:barback/barback.dart'; | 11 import 'package:barback/barback.dart'; |
| 12 import 'package:path/path.dart' as path; | 12 import 'package:path/path.dart' as path; |
| 13 import 'package:html5lib/dom.dart' show Document, Node, DocumentFragment; | 13 import 'package:html5lib/dom.dart' show |
| 14 Document, DocumentFragment, Element, Node; | |
| 14 import 'package:html5lib/dom_parsing.dart' show TreeVisitor; | 15 import 'package:html5lib/dom_parsing.dart' show TreeVisitor; |
| 16 import 'package:source_maps/span.dart' show Span; | |
| 15 | 17 |
| 16 import 'code_extractor.dart'; // import just for documentation. | 18 import 'code_extractor.dart'; // import just for documentation. |
| 17 import 'common.dart'; | 19 import 'common.dart'; |
| 18 | 20 |
| 19 /** | 21 /** |
| 20 * Recursively inlines the contents of HTML imports. Produces as output a single | 22 * Recursively inlines the contents of HTML imports. Produces as output a single |
| 21 * HTML file that inlines the polymer-element definitions, and a text file that | 23 * HTML file that inlines the polymer-element definitions, and a text file that |
| 22 * contains, in order, the URIs to each library that sourced in a script tag. | 24 * contains, in order, the URIs to each library that sourced in a script tag. |
| 23 * | 25 * |
| 24 * This transformer assumes that all script tags point to external files. To | 26 * This transformer assumes that all script tags point to external files. To |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 //TODO(jmesserly): add Node.firstChild to html5lib | 90 //TODO(jmesserly): add Node.firstChild to html5lib |
| 89 document.body.nodes.length == 0 ? null : document.body.nodes[0]); | 91 document.body.nodes.length == 0 ? null : document.body.nodes[0]); |
| 90 transform.addOutput(new Asset.fromString(id, document.outerHtml)); | 92 transform.addOutput(new Asset.fromString(id, document.outerHtml)); |
| 91 | 93 |
| 92 var scriptIds = []; | 94 var scriptIds = []; |
| 93 for (var script in scripts) { | 95 for (var script in scripts) { |
| 94 var src = script.attributes['src']; | 96 var src = script.attributes['src']; |
| 95 if (src == null) { | 97 if (src == null) { |
| 96 logger.warning('unexpected script without a src url. The ' | 98 logger.warning('unexpected script without a src url. The ' |
| 97 'ImportInliner transformer should run after running the ' | 99 'ImportInliner transformer should run after running the ' |
| 98 'InlineCodeExtractor', script.sourceSpan); | 100 'InlineCodeExtractor', span: script.sourceSpan); |
| 99 continue; | 101 continue; |
| 100 } | 102 } |
| 101 scriptIds.add(resolve(id, src, logger, script.sourceSpan)); | 103 scriptIds.add(resolve(id, src, logger, script.sourceSpan)); |
| 102 } | 104 } |
| 103 transform.addOutput(new Asset.fromString(secondaryId, | 105 transform.addOutput(new Asset.fromString(secondaryId, |
| 104 JSON.encode(scriptIds, toEncodable: (id) => id.serialize()))); | 106 JSON.encode(scriptIds, toEncodable: (id) => id.serialize()))); |
| 105 }); | 107 }); |
| 106 }); | 108 }); |
| 107 } | 109 } |
| 108 | 110 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 | 201 |
| 200 if (id.path.startsWith('lib/')) { | 202 if (id.path.startsWith('lib/')) { |
| 201 return 'packages/${id.package}/${id.path.substring(4)}'; | 203 return 'packages/${id.package}/${id.path.substring(4)}'; |
| 202 } | 204 } |
| 203 | 205 |
| 204 if (id.path.startsWith('asset/')) { | 206 if (id.path.startsWith('asset/')) { |
| 205 return 'assets/${id.package}/${id.path.substring(6)}'; | 207 return 'assets/${id.package}/${id.path.substring(6)}'; |
| 206 } | 208 } |
| 207 | 209 |
| 208 if (primaryId.package != id.package) { | 210 if (primaryId.package != id.package) { |
| 209 // Techincally we shouldn't get there | 211 // Techincally we shouldn't get there |
|
Siggi Cherem (dart-lang)
2013/10/30 01:12:40
love the irony =)
| |
| 210 logger.error("don't know how to include $id from $primaryId", span); | 212 transform.logger.error("don't know how to include $id from $primaryId", |
| 213 span: span); | |
| 211 return null; | 214 return null; |
| 212 } | 215 } |
| 213 | 216 |
| 214 var builder = path.url; | 217 var builder = path.url; |
| 215 return builder.relative(builder.join('/', id.path), | 218 return builder.relative(builder.join('/', id.path), |
| 216 from: builder.join('/', builder.dirname(primaryId.path))); | 219 from: builder.join('/', builder.dirname(primaryId.path))); |
| 217 } | 220 } |
| 218 } | 221 } |
| 219 | 222 |
| 220 /** | 223 /** |
| 221 * HTML attributes that expect a URL value. | 224 * HTML attributes that expect a URL value. |
| 222 * <http://dev.w3.org/html5/spec/section-index.html#attributes-1> | 225 * <http://dev.w3.org/html5/spec/section-index.html#attributes-1> |
| 223 * | 226 * |
| 224 * Every one of these attributes is a URL in every context where it is used in | 227 * Every one of these attributes is a URL in every context where it is used in |
| 225 * the DOM. The comments show every DOM element where an attribute can be used. | 228 * the DOM. The comments show every DOM element where an attribute can be used. |
| 226 */ | 229 */ |
| 227 const _urlAttributes = const [ | 230 const _urlAttributes = const [ |
| 228 'action', // in form | 231 'action', // in form |
| 229 'background', // in body | 232 'background', // in body |
| 230 'cite', // in blockquote, del, ins, q | 233 'cite', // in blockquote, del, ins, q |
| 231 'data', // in object | 234 'data', // in object |
| 232 'formaction', // in button, input | 235 'formaction', // in button, input |
| 233 'href', // in a, area, link, base, command | 236 'href', // in a, area, link, base, command |
| 234 'icon', // in command | 237 'icon', // in command |
| 235 'manifest', // in html | 238 'manifest', // in html |
| 236 'poster', // in video | 239 'poster', // in video |
| 237 'src', // in audio, embed, iframe, img, input, script, source, track, | 240 'src', // in audio, embed, iframe, img, input, script, source, track, |
| 238 // video | 241 // video |
| 239 ]; | 242 ]; |
| OLD | NEW |