Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 library pub.excluding_transformer; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 | |
| 9 import 'package:barback/barback.dart'; | |
| 10 | |
| 11 /// Decorates an inner [Transformer] and handles including and excluding | |
| 12 /// primary inputs. | |
| 13 class ExcludingTransformer extends Transformer { | |
| 14 /// If [includes] or [excludes] is non-empty, wraps [inner] in an | |
| 15 /// [ExcludingTransformer] that handles those. | |
| 16 /// | |
| 17 /// Otherwise, just returns [inner] unmodified. | |
| 18 static Transformer wrap(Transformer inner, Set<String> includes, | |
| 19 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
| |
| 20 if (includes.isEmpty && excludes.isEmpty) return inner; | |
| 21 | |
| 22 return new ExcludingTransformer._(inner, includes, excludes); | |
| 23 } | |
| 24 | |
| 25 final Transformer _inner; | |
| 26 | |
| 27 /// The set of asset paths which should be included. | |
| 28 /// | |
| 29 /// If empty, all non-excluded assets are allowed. Otherwise, only included | |
| 30 /// assets are allowed. | |
| 31 final Set<String> _includes; | |
| 32 | |
| 33 /// The set of assets which should be excluded. | |
| 34 /// | |
| 35 /// Exclusions are applied after inclusions. | |
| 36 final Set<String> _excludes; | |
| 37 | |
| 38 ExcludingTransformer._(this._inner, this._includes, this._excludes); | |
| 39 | |
| 40 Future<bool> isPrimary(Asset asset) { | |
| 41 // 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.
| |
| 42 if (_includes.isNotEmpty) { | |
| 43 // If there are any includes, it must match one of them. | |
| 44 if (!_includes.contains(asset.id.path)) return new Future.value(false); | |
| 45 } | |
| 46 | |
| 47 // It must not be excluded. | |
| 48 if (_excludes.contains(asset.id.path)) return new Future.value(false); | |
| 49 | |
| 50 return _inner.isPrimary(asset); | |
| 51 } | |
| 52 | |
| 53 Future apply(Transform transform) => _inner.apply(transform); | |
| 54 | |
| 55 String toString() => _inner.toString(); | |
| 56 } | |
| OLD | NEW |