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 # 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) ![build status](https://travis-ci.org/angel-dart/configuration.svg)
Isomorphic YAML configuration loader for Angel. Isomorphic YAML configuration loader for Angel.
@ -17,7 +17,7 @@ In `pubspec.yaml`:
```yaml ```yaml
dependencies: dependencies:
angel_configuration: ^1.0.0-dev angel_configuration: ^1.0.0
``` ```
# Usage # Usage

View file

@ -14,22 +14,27 @@ class ConfigurationTransformer extends Transformer {
ConfigurationTransformer.asPlugin(this._settings) {} ConfigurationTransformer.asPlugin(this._settings) {}
Future apply(Transform transform) async { Future apply(Transform transform) async {
var app = new Angel(); try {
var app = new Angel();
await app.configure(loadConfigurationFile( await app.configure(loadConfigurationFile(
directoryPath: _settings.configuration["dir"] ?? "./config", directoryPath: _settings.configuration["dir"] ?? "./config",
overrideEnvironmentName: _settings.configuration["env"])); overrideEnvironmentName: _settings.configuration["env"]));
var text = await transform.primaryInput.readAsString(); var text = await transform.primaryInput.readAsString();
var compilationUnit = parseCompilationUnit(text); var compilationUnit = parseCompilationUnit(text);
var visitor = new ConfigAstVisitor(app.properties); var visitor = new ConfigAstVisitor(app.properties);
visitor.visitCompilationUnit(compilationUnit); visitor.visitCompilationUnit(compilationUnit);
await for (Map replaced in visitor.onReplaced) { await for (Map replaced in visitor.onReplaced) {
text = text.replaceAll(replaced["needle"], replaced["with"]); 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...
}
} }
} }
@ -51,15 +56,15 @@ class ConfigAstVisitor extends GeneralizingAstVisitor {
for (int i = 0; i < split.length; i++) { for (int i = 0; i < split.length; i++) {
if (parent != null && parent is Map) parent = parent[split[i]]; if (parent != null && parent is Map) parent = parent[split[i]];
} }
return parent; return parent;
} }
@override @override
visitCompilationUnit(CompilationUnit ctx) { visitCompilationUnit(CompilationUnit ctx) {
var result = super.visitCompilationUnit(ctx); var result = super.visitCompilationUnit(ctx);
_onReplaced.close(); _onReplaced.close();
return result; return result;
} }
@override @override
@ -70,7 +75,7 @@ class ConfigAstVisitor extends GeneralizingAstVisitor {
_onReplaced.add({"needle": ctx.toString(), "with": ""}); _onReplaced.add({"needle": ctx.toString(), "with": ""});
if (ctx.asKeyword != null) { if (ctx.asKeyword != null) {
_prefix = ctx.prefix.name; _prefix = ctx.prefix.name;
} }
} }

View file

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