OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013, 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 barback.barback_settings; |
| 6 |
| 7 /// A generic settings object for providing configuration details to |
| 8 /// [Transformer]s. |
| 9 /// |
| 10 /// Barback does not specify *how* this is provided to transformers. It is up |
| 11 /// to a host application to handle this. (For example, pub passes this to the |
| 12 /// transformer's constructor.) |
| 13 class BarbackSettings { |
| 14 /// An open-ended map of configuration properties specific to this |
| 15 /// transformer. |
| 16 /// |
| 17 /// The contents of the map should be serializable across isolates, but |
| 18 /// otherwise can contain whatever you want. |
| 19 final Map configuration; |
| 20 |
| 21 /// The mode that user is running Barback in. |
| 22 /// |
| 23 /// This will be the same for all transformers in a running instance of |
| 24 /// Barback. |
| 25 final BarbackMode mode; |
| 26 |
| 27 BarbackSettings(this.configuration, this.mode); |
| 28 } |
| 29 |
| 30 /// Enum-like class for specifying a mode that transformers may be run in. |
| 31 /// |
| 32 /// Note that this is not a *closed* set of enum values. Host applications may |
| 33 /// define their own values for this, so a transformer relying on it should |
| 34 /// ensure that it behaves sanely with unknown values. |
| 35 class BarbackMode { |
| 36 /// The normal mode used during development. |
| 37 static const DEBUG = const BarbackMode._("debug"); |
| 38 |
| 39 /// The normal mode used to build an application for deploying to production. |
| 40 static const RELEASE = const BarbackMode._("release"); |
| 41 |
| 42 /// The name of the mode. |
| 43 /// |
| 44 /// By convention, this is a lowercase string. |
| 45 final String name; |
| 46 |
| 47 /// Create a mode named [name]. |
| 48 factory BarbackMode(String name) { |
| 49 // Use canonical instances of known names. |
| 50 switch (name) { |
| 51 case "debug": return BarbackMode.DEBUG; |
| 52 case "release": return BarbackMode.RELEASE; |
| 53 default: |
| 54 return new BarbackMode._(name); |
| 55 } |
| 56 } |
| 57 |
| 58 const BarbackMode._(this.name); |
| 59 |
| 60 String toString() => name; |
| 61 } |
OLD | NEW |