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

Side by Side Diff: pkg/polymer/lib/src/build/common.dart

Issue 28053008: Transformer plugin for polymer. This will make it possible (one day) to use (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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
« no previous file with comments | « pkg/polymer/lib/deploy.dart ('k') | pkg/polymer/lib/transformer.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /** Common methods used by transfomers. */ 5 /** Common methods used by transfomers. */
6 library polymer.src.build.common; 6 library polymer.src.build.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';
(...skipping 18 matching lines...) Expand all
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, span: e.span); 31 logger.warning(e.message, span: e.span);
32 } 32 }
33 } 33 }
34 return document; 34 return document;
35 } 35 }
36 36
37 /** Additional options used by polymer transformers */ 37 /** Additional options used by polymer transformers */
38 class TransformOptions { 38 class TransformOptions {
39 String currentPackage;
40 List<String> entryPoints; 39 List<String> entryPoints;
41 40
42 TransformOptions([this.currentPackage, entryPoints]) 41 TransformOptions([entryPoints])
43 : entryPoints = entryPoints == null ? null 42 : entryPoints = entryPoints == null ? null
44 : entryPoints.map(_systemToAssetPath).toList(); 43 : entryPoints.map(_systemToAssetPath).toList();
45 44
46 /** Whether an asset with [id] is an entry point HTML file. */ 45 /** Whether an asset with [id] is an entry point HTML file. */
47 bool isHtmlEntryPoint(AssetId id) { 46 bool isHtmlEntryPoint(AssetId id) {
48 if (id.extension != '.html') return false; 47 if (id.extension != '.html') return false;
49 48
50 // Note: [id.path] is a relative path from the root of a package. 49 // Note: [id.path] is a relative path from the root of a package.
51 if (currentPackage == null || entryPoints == null) { 50 if (entryPoints == null) {
52 return id.path.startsWith('web/') || id.path.startsWith('test/'); 51 return id.path.startsWith('web/') || id.path.startsWith('test/');
53 } 52 }
54 53
55 return id.package == currentPackage && entryPoints.contains(id.path); 54 return entryPoints.contains(id.path);
56 } 55 }
57 } 56 }
58 57
59 /** Mixin for polymer transformers. */ 58 /** Mixin for polymer transformers. */
60 abstract class PolymerTransformer { 59 abstract class PolymerTransformer {
61 TransformOptions get options; 60 TransformOptions get options;
62 61
63 Future<Document> readPrimaryAsHtml(Transform transform) { 62 Future<Document> readPrimaryAsHtml(Transform transform) {
64 var asset = transform.primaryInput; 63 var asset = transform.primaryInput;
65 var id = asset.id; 64 var id = asset.id;
66 return asset.readAsString().then((content) { 65 return asset.readAsString().then((content) {
67 return _parseHtml(content, id.path, transform.logger, 66 return _parseHtml(content, id.path, transform.logger,
68 checkDocType: options.isHtmlEntryPoint(id)); 67 checkDocType: options.isHtmlEntryPoint(id));
69 }); 68 });
70 } 69 }
71 70
72 Future<Document> readAsHtml(AssetId id, Transform transform) { 71 Future<Document> readAsHtml(AssetId id, Transform transform) {
73 var primaryId = transform.primaryInput.id; 72 var primaryId = transform.primaryInput.id;
74 var url = (id.package == primaryId.package) ? id.path 73 bool samePackage = id.package == primaryId.package;
74 var url = samePackage ? id.path
75 : assetUrlFor(id, primaryId, transform.logger, allowAssetUrl: true); 75 : assetUrlFor(id, primaryId, transform.logger, allowAssetUrl: true);
76 return transform.readInputAsString(id).then((content) { 76 return transform.readInputAsString(id).then((content) {
77 return _parseHtml(content, url, transform.logger, 77 return _parseHtml(content, url, transform.logger,
78 checkDocType: options.isHtmlEntryPoint(id)); 78 checkDocType: samePackage && options.isHtmlEntryPoint(id));
79 }); 79 });
80 } 80 }
81 81
82 Future<bool> assetExists(AssetId id, Transform transform) => 82 Future<bool> assetExists(AssetId id, Transform transform) =>
83 transform.getInput(id).then((_) => true).catchError((_) => false); 83 transform.getInput(id).then((_) => true).catchError((_) => false);
84 } 84 }
85 85
86 /** Create an [AssetId] for a [url] seen in the [source] asset. */ 86 /** Create an [AssetId] for a [url] seen in the [source] asset. */
87 // TODO(sigmund): delete once this is part of barback (dartbug.com/12610) 87 // TODO(sigmund): delete once this is part of barback (dartbug.com/12610)
88 AssetId resolve(AssetId source, String url, TransformLogger logger, Span span) { 88 AssetId resolve(AssetId source, String url, TransformLogger logger, Span span) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 return builder.relative(builder.join('/', id.path), 153 return builder.relative(builder.join('/', id.path),
154 from: builder.join('/', builder.dirname(sourceId.path))); 154 from: builder.join('/', builder.dirname(sourceId.path)));
155 } 155 }
156 156
157 157
158 /** Convert system paths to asset paths (asset paths are posix style). */ 158 /** Convert system paths to asset paths (asset paths are posix style). */
159 String _systemToAssetPath(String assetPath) { 159 String _systemToAssetPath(String assetPath) {
160 if (path.Style.platform != path.Style.windows) return assetPath; 160 if (path.Style.platform != path.Style.windows) return assetPath;
161 return path.posix.joinAll(path.split(assetPath)); 161 return path.posix.joinAll(path.split(assetPath));
162 } 162 }
OLDNEW
« no previous file with comments | « pkg/polymer/lib/deploy.dart ('k') | pkg/polymer/lib/transformer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698