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

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: Require leading "." in extensions. 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..e8479f1f8143d2273593250e4aeab3bb48e7324d 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
+ /// (with leading `.`) that are allowed for the primary inputs to this
+ /// 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;
+
/// 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