Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 /** Transfomer that extracts inlined script code into separate assets. */ | |
| 6 library polymer.src.transformers; | |
| 7 | |
| 8 import 'dart:async'; | |
| 9 | |
| 10 import 'package:path/path.dart' as path; | |
|
Jennifer Messerly
2013/08/19 22:57:26
not sure if you want to sort these, noticed a few
Siggi Cherem (dart-lang)
2013/08/21 20:35:42
Done.
| |
| 11 import 'package:barback/barback.dart'; | |
| 12 import 'common.dart'; | |
| 13 | |
| 14 /** | |
| 15 * Transformer that extracts Dart code inlined in HTML script tags and outputs a | |
| 16 * separate file for each. | |
| 17 */ | |
| 18 class InlineCodeExtractor extends Transformer { | |
|
terry
2013/08/20 17:03:24
Does Barback has the ability to pass options for t
Bob Nystrom
2013/08/20 17:20:05
No, it doesn't currently have a way to handle conf
| |
| 19 Future<bool> isPrimary(Asset input) => | |
| 20 new Future.value(input.id.extension == ".html"); | |
| 21 | |
| 22 Future apply(Transform transform) { | |
| 23 var inputId = transform.primaryId; | |
| 24 return getPrimaryContent(transform).then((content) { | |
|
Bob Nystrom
2013/08/19 22:28:59
Add a TODO mentioning #12515 or #12516 here since
Siggi Cherem (dart-lang)
2013/08/21 20:35:42
awesome. Done. moved the TODOs to the definition o
| |
| 25 var document = parseHtml(content, inputId.path, transform.logger); | |
| 26 int count = 0; | |
| 27 for (var tag in document.queryAll('script')) { | |
| 28 if (tag.attributes['type'] == 'application/dart' && | |
| 29 !tag.attributes.containsKey('src')) { | |
| 30 // TODO(sigmund): should we automatically include a library directive | |
| 31 // if it doesn't have one? | |
| 32 var filename = path.basename(inputId.path); | |
| 33 tag.attributes['src'] = '$filename.$count.dart'; | |
| 34 var textContent = tag.nodes.first; | |
| 35 var id = inputId.addExtension('.$count.dart'); | |
|
Jennifer Messerly
2013/08/19 22:57:26
do we need to worry about this name conflicting wi
Siggi Cherem (dart-lang)
2013/08/21 20:35:42
It's mainly on our hands to worry about finding a
Bob Nystrom
2013/08/21 21:18:21
Similarly, you need to choose something that is no
| |
| 36 transform.addOutput(new Asset.fromString(id, textContent.value)); | |
|
terry
2013/08/20 17:03:24
Can barback produce an output stream. Might want
Bob Nystrom
2013/08/20 17:20:05
Yes, a barback Asset exposes a stream interface yo
| |
| 37 textContent.remove(); | |
| 38 count++; | |
| 39 } | |
| 40 } | |
| 41 transform.addOutput(new Asset.fromString(inputId, | |
| 42 count == 0 ? content : document.outerHtml)); | |
|
Bob Nystrom
2013/08/19 22:28:59
Just indent +4 here or all the way to the "(".
Siggi Cherem (dart-lang)
2013/08/21 20:35:42
Done. Thanks, vi-mode for Dart is not perfect yet
| |
| 43 }); | |
| 44 } | |
| 45 } | |
| OLD | NEW |