Chromium Code Reviews| Index: sdk/lib/_internal/pub/lib/src/barback/excluding_transformer.dart |
| diff --git a/sdk/lib/_internal/pub/lib/src/barback/excluding_transformer.dart b/sdk/lib/_internal/pub/lib/src/barback/excluding_transformer.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f9062d4b6cce4b11937e488a937bad4e267770d2 |
| --- /dev/null |
| +++ b/sdk/lib/_internal/pub/lib/src/barback/excluding_transformer.dart |
| @@ -0,0 +1,56 @@ |
| +// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +library pub.excluding_transformer; |
| + |
| +import 'dart:async'; |
| + |
| +import 'package:barback/barback.dart'; |
| + |
| +/// Decorates an inner [Transformer] and handles including and excluding |
| +/// primary inputs. |
| +class ExcludingTransformer extends Transformer { |
| + /// If [includes] or [excludes] is non-empty, wraps [inner] in an |
| + /// [ExcludingTransformer] that handles those. |
| + /// |
| + /// Otherwise, just returns [inner] unmodified. |
| + static Transformer wrap(Transformer inner, Set<String> includes, |
| + Set<String> excludes) { |
|
nweiz
2014/02/24 21:42:46
Nit, but I think we usually just indent continued
Bob Nystrom
2014/02/26 01:09:41
We're inconsistent, I think, but done. I'm fine wi
|
| + if (includes.isEmpty && excludes.isEmpty) return inner; |
| + |
| + return new ExcludingTransformer._(inner, includes, excludes); |
| + } |
| + |
| + final Transformer _inner; |
| + |
| + /// The set of asset paths which should be included. |
| + /// |
| + /// If empty, all non-excluded assets are allowed. Otherwise, only included |
| + /// assets are allowed. |
| + final Set<String> _includes; |
| + |
| + /// The set of assets which should be excluded. |
| + /// |
| + /// Exclusions are applied after inclusions. |
| + final Set<String> _excludes; |
| + |
| + ExcludingTransformer._(this._inner, this._includes, this._excludes); |
| + |
| + Future<bool> isPrimary(Asset asset) { |
| + // TODO(rnystrom): Support globs in addition to paths. |
|
nweiz
2014/02/24 21:42:46
Is there a bug for this? If not, file one and refe
Bob Nystrom
2014/02/26 01:09:41
Done.
|
| + if (_includes.isNotEmpty) { |
| + // If there are any includes, it must match one of them. |
| + if (!_includes.contains(asset.id.path)) return new Future.value(false); |
| + } |
| + |
| + // It must not be excluded. |
| + if (_excludes.contains(asset.id.path)) return new Future.value(false); |
| + |
| + return _inner.isPrimary(asset); |
| + } |
| + |
| + Future apply(Transform transform) => _inner.apply(transform); |
| + |
| + String toString() => _inner.toString(); |
| +} |