Chromium Code Reviews| Index: pkg/barback/lib/src/barback_settings.dart |
| diff --git a/pkg/barback/lib/src/barback_settings.dart b/pkg/barback/lib/src/barback_settings.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c0420ba24dad3d4b319506557740af23754c053d |
| --- /dev/null |
| +++ b/pkg/barback/lib/src/barback_settings.dart |
| @@ -0,0 +1,59 @@ |
| +// Copyright (c) 2013, 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 barback.barback_settings; |
| + |
| +/// A generic settings object for providing configuration details to |
| +/// [Transformer]s. |
| +/// |
| +/// Barback does not specify *how* this is provided to transformers. It is up |
| +/// to a host application to handle this. (For example, pub passes this to the |
| +/// transformer's constructor.) |
| +class BarbackSettings { |
| + /// An open-ended map of configuration properties specific to this |
| + /// transformer. |
| + /// |
| + /// Aside from requiring to be serializable across isolates, Barback places |
|
nweiz
2013/10/31 00:24:41
"requiring to be" -> "requiring that this be" or "
Bob Nystrom
2013/10/31 01:51:19
Reworded.
|
| + /// no restrictions on what this should contain. |
| + final Map transformer; |
|
nweiz
2013/10/31 00:24:41
I agree with Siggi that this reads awkwardly. What
Bob Nystrom
2013/10/31 01:51:19
I think that's worse. I can do "transformerConfigu
nweiz
2013/10/31 18:47:56
"fromUser"? "fromPubspec"? "pubspec"?
"transforme
Bob Nystrom
2013/10/31 20:04:08
Changed to "configuration".
|
| + |
| + /// The overall development mode that user is running Barback in. This will |
|
nweiz
2013/10/31 00:24:41
Paragraph break.
"development mode" is confusing
Bob Nystrom
2013/10/31 01:51:19
Removed "overall" too.
|
| + /// be the same for all transformers in a running instance of Barback. |
| + final BarbackMode mode; |
| + |
| + BarbackSettings(this.transformer, this.mode); |
| +} |
| + |
| +/// Enum-like class for specifying a mode that transformers may be run in. |
| +/// |
| +/// Note that this is not a *closed* set of enum values. Host applications may |
| +/// define their own values for this, so a transformer relying on it should |
| +/// ensure that it behaves sanely with unknown values. |
| +class BarbackMode { |
| + /// The normal mode used during development. |
| + static const DEBUG = const BarbackMode("debug"); |
| + |
| + /// The normal mode used to build an application for deploying to production. |
| + static const RELEASE = const BarbackMode("release"); |
| + |
| + /// The name of the mode. |
| + /// |
| + /// By convention, this is a lowercase string. |
| + final String name; |
| + |
| + const BarbackMode(this.name); |
| + |
| + /// Create a mode named [name]. |
| + factory BarbackMode.fromString(String name) { |
|
nweiz
2013/10/31 00:24:41
It's confusing for this to be a different construc
Bob Nystrom
2013/10/31 01:51:19
Done. Not sure what I was thinking here.
|
| + // Use canonical instances of known names. |
| + switch (name) { |
| + case "debug": return BarbackMode.DEBUG; |
| + case "release": return BarbackMode.RELEASE; |
| + default: |
| + return new BarbackMode(name); |
| + } |
| + } |
| + |
| + String toString() => name; |
| +} |