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

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

Issue 198103003: Support extensions with multiple periods in Transformer.allowedExtensions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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/lib/src/utils.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 6eed17af60f3b4695c0355556ede0e64ea2a8236..669478b1a6ed369ed0feef12e6fdc68e83bdfcbf 100644
--- a/pkg/barback/lib/src/transformer.dart
+++ b/pkg/barback/lib/src/transformer.dart
@@ -8,6 +8,7 @@ import 'dart:async';
import 'asset.dart';
import 'transform.dart';
+import 'utils.dart';
/// A [Transformer] represents a processor that takes in one or more input
/// assets and uses them to generate one or more output assets.
@@ -23,11 +24,26 @@ abstract class Transformer {
/// (with leading `.`) that are allowed for the primary inputs to this
Bob Nystrom 2014/03/12 23:25:28 Remove the "(with leading `.`)" part.
nweiz 2014/03/12 23:30:48 Done.
/// transformer.
///
+ /// Each extension must begin with a leading `.`.
+ ///
/// 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;
+ Transformer() {
+ if (allowedExtensions == null) return;
+
+ var invalidExtensions = allowedExtensions.split(" ")
+ .where((extension) => !extension.startsWith("."))
+ .map((extension) => '"$extension"');
+ if (invalidExtensions.isEmpty) return;
+
+ throw new FormatException('Each extension in $this.allowedExtensions '
+ 'must begin with a ".", but ${toSentence(invalidExtensions)} '
+ '${pluralize("doesn't", invalidExtensions.length, plural: "don't")}.');
+ }
+
/// 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
@@ -49,7 +65,7 @@ abstract class Transformer {
if (allowedExtensions == null) return new Future.value(true);
for (var extension in allowedExtensions.split(" ")) {
- if (input.id.extension == extension) return new Future.value(true);
+ if (input.id.path.endsWith(extension)) return new Future.value(true);
}
return new Future.value(false);
« no previous file with comments | « no previous file | pkg/barback/lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698