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

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

Issue 157583007: Removing polymer-specific code from barback runner (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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 /** 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 import 'dart:math' show min, max; 9 import 'dart:math' show min, max;
10 10
11 import 'package:barback/barback.dart'; 11 import 'package:barback/barback.dart';
12 import 'package:html5lib/dom.dart' show Document; 12 import 'package:html5lib/dom.dart' show Document;
13 import 'package:html5lib/parser.dart' show HtmlParser; 13 import 'package:html5lib/parser.dart' show HtmlParser;
14 import 'package:path/path.dart' as path; 14 import 'package:path/path.dart' as path;
15 import 'package:observe/transformer.dart' show ObservableTransformer;
15 import 'package:source_maps/span.dart' show Span; 16 import 'package:source_maps/span.dart' show Span;
16 17
17 /** 18 /**
18 * Parses an HTML file [contents] and returns a DOM-like tree. Adds emitted 19 * Parses an HTML file [contents] and returns a DOM-like tree. Adds emitted
19 * error/warning to [logger]. 20 * error/warning to [logger].
20 */ 21 */
21 Document _parseHtml(String contents, String sourcePath, TransformLogger logger, 22 Document _parseHtml(String contents, String sourcePath, TransformLogger logger,
22 {bool checkDocType: true}) { 23 {bool checkDocType: true}) {
23 // TODO(jmesserly): make HTTP encoding configurable 24 // TODO(jmesserly): make HTTP encoding configurable
24 var parser = new HtmlParser(contents, encoding: 'utf8', generateSpans: true, 25 var parser = new HtmlParser(contents, encoding: 'utf8', generateSpans: true,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 checkDocType: samePackage && options.isHtmlEntryPoint(id)); 111 checkDocType: samePackage && options.isHtmlEntryPoint(id));
111 }); 112 });
112 } 113 }
113 114
114 Future<bool> assetExists(AssetId id, Transform transform) => 115 Future<bool> assetExists(AssetId id, Transform transform) =>
115 transform.getInput(id).then((_) => true).catchError((_) => false); 116 transform.getInput(id).then((_) => true).catchError((_) => false);
116 117
117 String toString() => 'polymer ($runtimeType)'; 118 String toString() => 'polymer ($runtimeType)';
118 } 119 }
119 120
121 /** Transformer phases which should be applied to the Polymer package. */
122 List<List<Transformer>> get phasesForPolymer =>
123 [[new ObservableTransformer(['lib/src/instance.dart'])]];
124
120 /** 125 /**
121 * Create an [AssetId] for a [url] seen in the [source] asset. By default this 126 * Create an [AssetId] for a [url] seen in the [source] asset. By default this
122 * is used to resolve relative urls that occur in HTML assets, including 127 * is used to resolve relative urls that occur in HTML assets, including
123 * cross-package urls of the form "packages/foo/bar.html". Dart-style "package:" 128 * cross-package urls of the form "packages/foo/bar.html". Dart-style "package:"
124 * urls are not resolved unless [source] is Dart file (has a .dart extension). 129 * urls are not resolved unless [source] is Dart file (has a .dart extension).
125 */ 130 */
126 // TODO(sigmund): delete once this is part of barback (dartbug.com/12610) 131 // TODO(sigmund): delete once this is part of barback (dartbug.com/12610)
127 AssetId resolve(AssetId source, String url, TransformLogger logger, Span span) { 132 AssetId resolve(AssetId source, String url, TransformLogger logger, Span span) {
128 if (url == null || url == '') return null; 133 if (url == null || url == '') return null;
129 var uri = Uri.parse(url); 134 var uri = Uri.parse(url);
130 var urlBuilder = path.url; 135 var urlBuilder = path.url;
131 if (uri.host != '' || uri.scheme != '' || urlBuilder.isAbsolute(url)) { 136 if (uri.host != '' || uri.scheme != '' || urlBuilder.isAbsolute(url)) {
132 if (source.extension == '.dart' && uri.scheme == 'package') { 137 if (source.extension == '.dart' && uri.scheme == 'package') {
133 var index = uri.path.indexOf('/'); 138 var index = uri.path.indexOf('/');
134 if (index != -1) { 139 if (index != -1) {
135 return new AssetId(uri.path.substring(0, index), 140 return new AssetId(uri.path.substring(0, index),
136 'lib${uri.path.substring(index)}'); 141 'lib${uri.path.substring(index)}');
137 } 142 }
138 } 143 }
139 144
140 logger.error('absolute paths not allowed: "$url"', span: span); 145 logger.error('absolute paths not allowed: "$url"', span: span);
141 return null; 146 return null;
142 } 147 }
143 148
144 var targetPath = urlBuilder.normalize( 149 var targetPath = urlBuilder.normalize(
145 urlBuilder.join(urlBuilder.dirname(source.path), url)); 150 urlBuilder.join(urlBuilder.dirname(source.path), url));
146 var segments = urlBuilder.split(targetPath); 151 var segments = urlBuilder.split(targetPath);
147 var sourceSegments = urlBuilder.split(source.path); 152 var sourceSegments = urlBuilder.split(source.path);
148 assert (sourceSegments.length > 0); 153 assert (sourceSegments.length > 0);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 return builder.relative(builder.join('/', id.path), 239 return builder.relative(builder.join('/', id.path),
235 from: builder.join('/', builder.dirname(sourceId.path))); 240 from: builder.join('/', builder.dirname(sourceId.path)));
236 } 241 }
237 242
238 243
239 /** Convert system paths to asset paths (asset paths are posix style). */ 244 /** Convert system paths to asset paths (asset paths are posix style). */
240 String _systemToAssetPath(String assetPath) { 245 String _systemToAssetPath(String assetPath) {
241 if (path.Style.platform != path.Style.windows) return assetPath; 246 if (path.Style.platform != path.Style.windows) return assetPath;
242 return path.posix.joinAll(path.split(assetPath)); 247 return path.posix.joinAll(path.split(assetPath));
243 } 248 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698