https://github.com/cah4a/dart_cryaml
YAML on steroids
https://github.com/cah4a/dart_cryaml
dart yaml
Last synced: 9 months ago
JSON representation
YAML on steroids
- Host: GitHub
- URL: https://github.com/cah4a/dart_cryaml
- Owner: cah4a
- Created: 2019-08-22T07:32:44.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-11-20T12:17:18.000Z (over 6 years ago)
- Last Synced: 2024-03-19T06:52:13.819Z (over 2 years ago)
- Topics: dart, yaml
- Language: Dart
- Homepage:
- Size: 95.7 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CrYAML
Turing-complete YAML on steroids.

[](https://codecov.io/gh/cah4a/dart_cryaml)
# Dart API
Load only data with variables:
```cryaml
name: "John"
count: $count
```
```dart
final cryaml = loadCrYAML(source);
final data = cryaml.evaluate({"count": 1}); // {"name": "John", count: 1}
```
Use functions inside document:
```cryaml
user:
name: "John"
count: multiply($count, times: 3)
```
```dart
final cryaml = loadCrYAML(source, Specification(
functions: {
"multiply": (int count, {int times: 1}) => count * times,
}),
);
final data = cryaml.evaluate({"count": 1}); // {"name": "John", count: 2}
```
Use directives:
```cryaml
@user
name: "John"
count: multiply($count, times: 3)
```
```dart
class UserDirective extends Directive {
final specification = const DirectiveSpec(
documentType: DocumentType.map,
);
User call(CrYAMLContext context, {Map document()}) {
final result = document();
return User(
name: result["name"],
count: result["count"],
);
}
}
final cryaml = loadCrYAML(
source,
Specification(
functions: {
"multiply": (int count, {int times: 1}) => count * times,
},
directives: {"user": UserDirective()},
),
);
final data = cryaml.evaluate({"count": 1}); // {"name": "John", count: 2}
```