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

Unified Diff: pkg/barback/lib/src/transformer.dart

Issue 23050009: Add "allowedExtensions" to Transformer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/barback/test/transformer_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/barback/lib/src/transformer.dart
diff --git a/pkg/barback/lib/src/transformer.dart b/pkg/barback/lib/src/transformer.dart
index 58377f0257fd0c1c51d1bf492e005726d3f4a4c3..9baf3b987fda4ac1935786fe5984f4cd4dd37b55 100644
--- a/pkg/barback/lib/src/transformer.dart
+++ b/pkg/barback/lib/src/transformer.dart
@@ -16,6 +16,15 @@ import 'transform.dart';
/// files are all examples of transformers. To define your own transformation
/// step, extend (or implement) this class.
abstract class Transformer {
+ /// Override this to return a space-separated list of file extensions
+ /// (without leading `.`) that are allowed for the primary inputs to this
nweiz 2013/08/20 00:35:43 It's confusing that this doesn't use the leading "
Bob Nystrom 2013/08/20 16:15:37 Changed to require the leading ".".
+ /// transformer.
+ ///
+ /// If you don't override [isPrimary] yourself, it defaults to allowing any
+ /// asset whose extension matches one of the ones returned by this. If you
+ /// don't override [isPrimary] *or* this, it allows all files.
+ String get allowedExtensions => null;
nweiz 2013/08/20 00:35:43 It's weird that this uses a space-separated list w
Bob Nystrom 2013/08/20 16:15:37 I thought about that, but then I wouldn't be able
nweiz 2013/08/20 19:20:54 If the way you specify a list of extensions is as
+
/// Returns `true` if [input] can be a primary input for this transformer.
///
/// While a transformer can read from multiple input files, one must be the
@@ -28,7 +37,20 @@ abstract class Transformer {
/// of those to generate the final JS. However you still run dart2js "on" a
/// single file: the entrypoint Dart file that has your `main()` method.
/// This entrypoint file would be the primary input.
- Future<bool> isPrimary(Asset input);
+ ///
+ /// If this is not overridden, defaults to allow any asset whose extension
+ /// matches one of the ones returned by [allowedExtensions]. If *that* is
+ /// not overridden, allows all assets.
+ Future<bool> isPrimary(Asset input) {
+ // Allow all files if [primaryExtensions] is not overridden.
+ if (allowedExtensions == null) return new Future.value(true);
+
+ for (var extension in allowedExtensions.split(" ")) {
+ if (input.id.extension == ".$extension") return new Future.value(true);
+ }
+
+ return new Future.value(false);
+ }
/// Run this transformer on on the primary input specified by [transform].
///
« no previous file with comments | « no previous file | pkg/barback/test/transformer_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698