This commit is contained in:
thosakwe 2017-03-08 17:47:58 -05:00
parent c8eac16ffc
commit c9f8cafa56
3 changed files with 24 additions and 19 deletions

View file

@ -1,6 +1,6 @@
# Angel Configuration
![version 1.0.1+8](https://img.shields.io/badge/version-1.0.1+8-red.svg)
![version 1.0.2](https://img.shields.io/badge/version-1.0.2-brightgreen.svg)
![build status](https://travis-ci.org/angel-dart/configuration.svg)
Isomorphic YAML configuration loader for Angel.
@ -17,7 +17,7 @@ In `pubspec.yaml`:
```yaml
dependencies:
angel_configuration: ^1.0.0-dev
angel_configuration: ^1.0.0
```
# Usage

View file

@ -14,22 +14,27 @@ class ConfigurationTransformer extends Transformer {
ConfigurationTransformer.asPlugin(this._settings) {}
Future apply(Transform transform) async {
var app = new Angel();
try {
var app = new Angel();
await app.configure(loadConfigurationFile(
directoryPath: _settings.configuration["dir"] ?? "./config",
overrideEnvironmentName: _settings.configuration["env"]));
await app.configure(loadConfigurationFile(
directoryPath: _settings.configuration["dir"] ?? "./config",
overrideEnvironmentName: _settings.configuration["env"]));
var text = await transform.primaryInput.readAsString();
var compilationUnit = parseCompilationUnit(text);
var visitor = new ConfigAstVisitor(app.properties);
visitor.visitCompilationUnit(compilationUnit);
var text = await transform.primaryInput.readAsString();
var compilationUnit = parseCompilationUnit(text);
var visitor = new ConfigAstVisitor(app.properties);
visitor.visitCompilationUnit(compilationUnit);
await for (Map replaced in visitor.onReplaced) {
await for (Map replaced in visitor.onReplaced) {
text = text.replaceAll(replaced["needle"], replaced["with"]);
}
}
transform.addOutput(new Asset.fromString(transform.primaryInput.id, text));
transform
.addOutput(new Asset.fromString(transform.primaryInput.id, text));
} catch (e) {
// Fail silently...
}
}
}
@ -57,9 +62,9 @@ class ConfigAstVisitor extends GeneralizingAstVisitor {
@override
visitCompilationUnit(CompilationUnit ctx) {
var result = super.visitCompilationUnit(ctx);
_onReplaced.close();
return result;
var result = super.visitCompilationUnit(ctx);
_onReplaced.close();
return result;
}
@override
@ -70,7 +75,7 @@ class ConfigAstVisitor extends GeneralizingAstVisitor {
_onReplaced.add({"needle": ctx.toString(), "with": ""});
if (ctx.asKeyword != null) {
_prefix = ctx.prefix.name;
_prefix = ctx.prefix.name;
}
}

View file

@ -1,6 +1,6 @@
name: angel_configuration
description: Isomorphic YAML configuration loader for Angel.
version: 1.0.1+8
version: 1.0.2
author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/angel_configuration
dependencies: