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 /** Common methods used by transfomers. */ | 5 /** Common methods used by transfomers. */ |
| 6 library polymer.src.transform.common; | 6 library polymer.src.transform.common; |
| 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; | 11 import 'package:html5lib/dom.dart' show Document; |
| 12 import 'package:html5lib/parser.dart' show HtmlParser; | 12 import 'package:html5lib/parser.dart' show HtmlParser; |
| 13 import 'package:path/path.dart' as path; | 13 import 'package:path/path.dart' as path; |
| 14 import 'package:source_maps/span.dart' show Span; | 14 import 'package:source_maps/span.dart' show Span; |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * Parses an HTML file [contents] and returns a DOM-like tree. Adds emitted | 17 * Parses an HTML file [contents] and returns a DOM-like tree. Adds emitted |
| 18 * error/warning to [logger]. | 18 * error/warning to [logger]. |
| 19 */ | 19 */ |
| 20 Document parseHtml(String contents, String sourcePath, TransformLogger logger, | 20 Document parseHtml(String contents, String sourcePath, TransformLogger logger, |
| 21 {bool checkDocType: true}) { | 21 {bool checkDocType: false}) { |
| 22 // TODO(jmesserly): make HTTP encoding configurable | 22 // TODO(jmesserly): make HTTP encoding configurable |
| 23 var parser = new HtmlParser(contents, encoding: 'utf8', generateSpans: true, | 23 var parser = new HtmlParser(contents, encoding: 'utf8', generateSpans: true, |
| 24 sourceUrl: sourcePath); | 24 sourceUrl: sourcePath); |
| 25 var document = parser.parse(); | 25 var document = parser.parse(); |
| 26 | 26 |
| 27 // Note: errors aren't fatal in HTML (unless strict mode is on). | 27 // Note: errors aren't fatal in HTML (unless strict mode is on). |
| 28 // So just print them as warnings. | 28 // So just print them as warnings. |
| 29 for (var e in parser.errors) { | 29 for (var e in parser.errors) { |
| 30 if (checkDocType || e.errorCode != 'expected-doctype-but-got-start-tag') { | 30 if (checkDocType || e.errorCode != 'expected-doctype-but-got-start-tag') { |
| 31 logger.warning(e.message, e.span); | 31 logger.warning(e.message, e.span); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 package = segments[1]; | 65 package = segments[1]; |
| 66 targetPath = urlBuilder.join('asset', | 66 targetPath = urlBuilder.join('asset', |
| 67 urlBuilder.joinAll(segments.sublist(2))); | 67 urlBuilder.joinAll(segments.sublist(2))); |
| 68 } else { | 68 } else { |
| 69 package = source.package; | 69 package = source.package; |
| 70 targetPath = urlBuilder.normalize( | 70 targetPath = urlBuilder.normalize( |
| 71 urlBuilder.join(urlBuilder.dirname(source.path), url)); | 71 urlBuilder.join(urlBuilder.dirname(source.path), url)); |
| 72 } | 72 } |
| 73 return new AssetId(package, targetPath); | 73 return new AssetId(package, targetPath); |
| 74 } | 74 } |
| 75 | |
| 76 Future<bool> isHtmlInWebOrTest(AssetId id) => | |
|
Jennifer Messerly
2013/09/04 02:35:04
wondering if we could name this to more reflect wh
Siggi Cherem (dart-lang)
2013/09/04 16:30:16
Done. Went with isPrimaryHtml
| |
| 77 new Future.value(id.extension == '.html' && | |
|
Jennifer Messerly
2013/09/04 02:35:04
hmm. Perhaps add a comment that these are always a
Siggi Cherem (dart-lang)
2013/09/04 16:30:16
Done
| |
| 78 (id.path.startsWith('web/') || id.path.startsWith('test/'))); | |
| OLD | NEW |