yamlscript 0.2.3 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ChangeLog.md +8 -0
- data/ReadMe.md +114 -102
- data/doc/readme.md +14 -38
- data/lib/yamlscript/version.rb +1 -1
- data/lib/yamlscript.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a8f1878ca08dc56b3778ee310b0ccbca64b2621c38e798344211db83ed30726a
|
|
4
|
+
data.tar.gz: 7497270f76bc916e8a2bd1cd627a4c9e575b7d4cef599be881a1cd7ed22585ee
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 81895aecd345475a75f06e8d65427c70e2f8640eaf697d01966c47193b8c4c5eb1b5f2f13d795eeabb15f197a43fe4d245f253bc831900ee4f18ca74f6a682e7
|
|
7
|
+
data.tar.gz: 315fb335814ada52ca50f8ef89a0e7e457e471018315fd94d9164e1da9e61e02bb4079d3812eaa0111dd817da002ef7790c94cc7dbca03ea5c43a34f750426cd
|
data/ChangeLog.md
CHANGED
data/ReadMe.md
CHANGED
|
@@ -1,154 +1,166 @@
|
|
|
1
1
|
<!-- DO NOT EDIT — THIS FILE WAS GENERATED -->
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
YAMLScript
|
|
4
|
+
==========
|
|
5
5
|
|
|
6
6
|
Add Logic to Your YAML Files
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## Quick Start
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
This library lets you load YAML files that may or may not contain
|
|
12
|
+
[YAMLScript](https://yamlscript.org) functional programming logic.
|
|
13
|
+
You can use it as a drop-in replacement for your current YAML loader.
|
|
14
|
+
|
|
15
|
+
Here's an example `config.yaml` that makes use of YAMLScript functions.
|
|
12
16
|
|
|
13
17
|
```yaml
|
|
14
|
-
|
|
18
|
+
# config.yaml with YAMLScript:
|
|
19
|
+
!ys-0:
|
|
20
|
+
|
|
21
|
+
# Define variables
|
|
22
|
+
db-host =: ENV.DB_HOST || 'localhost'
|
|
23
|
+
db-port =: ENV.DB_PORT || 5432
|
|
24
|
+
deploy =: ENV.DEPLOYMENT || 'dev'
|
|
25
|
+
:when deploy !~ /^(dev|stage|prod)/:
|
|
26
|
+
die: |
|
|
27
|
+
Invalid deployment value '$deploy'.
|
|
28
|
+
Must be one of: dev | stage | prod
|
|
29
|
+
|
|
30
|
+
# Normal YAML data
|
|
31
|
+
description: Dynamic application configuration
|
|
32
|
+
|
|
33
|
+
# Dynamic data values
|
|
34
|
+
database:
|
|
35
|
+
host:: db-host
|
|
36
|
+
port:: db-port:num
|
|
37
|
+
name:: "app_$deploy"
|
|
38
|
+
|
|
39
|
+
# Import external data
|
|
40
|
+
features:: load('common.yaml').features
|
|
41
|
+
|
|
42
|
+
# Use logic and conditions
|
|
43
|
+
cache:
|
|
44
|
+
# Variable scoped to this mapping
|
|
45
|
+
enabled =: deploy == 'production'
|
|
46
|
+
|
|
47
|
+
directory: .cache
|
|
48
|
+
enabled:: enabled
|
|
49
|
+
limit: 100
|
|
50
|
+
# Conditional key/value pairs
|
|
51
|
+
:when enabled::
|
|
52
|
+
limit:: 1000
|
|
53
|
+
ttl:: 60 * 60 # 3600
|
|
54
|
+
```
|
|
15
55
|
|
|
16
|
-
# Get data from external sources:
|
|
17
|
-
names-url =:
|
|
18
|
-
'github:dominictarr/random-name/first-names.json'
|
|
19
56
|
|
|
20
|
-
|
|
57
|
+
## What is YAMLScript?
|
|
21
58
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
aka:: name-list:rand-nth
|
|
25
|
-
age:: &num 2 * 3 * 7
|
|
26
|
-
color:: &hue
|
|
27
|
-
rand-nth: qw(red green blue yellow)
|
|
28
|
-
title:: "$(*num) shades of $(*hue)."
|
|
29
|
-
```
|
|
59
|
+
YAMLScript is a functional programming language that can be embedded in YAML.
|
|
60
|
+
Its syntax is 100% YAML so files that embed it are still valid YAML files.
|
|
30
61
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"aka": "Anita",
|
|
36
|
-
"age": 42,
|
|
37
|
-
"color": "green",
|
|
38
|
-
"title": "42 shades of green."
|
|
39
|
-
}
|
|
40
|
-
```
|
|
62
|
+
The YAMLScript project provides YAML loader libraries for many programming
|
|
63
|
+
languages.
|
|
64
|
+
They can be used to load any YAML config files properly, whether or not they
|
|
65
|
+
contain functional programming logic.
|
|
41
66
|
|
|
67
|
+
It's perfect for:
|
|
42
68
|
|
|
43
|
-
|
|
69
|
+
* **Configuration files** that need logic, variables, and dynamic values
|
|
70
|
+
* **Data transformation** with built-in functions for JSON, YAML, and text
|
|
71
|
+
processing
|
|
72
|
+
* **Templating** with powerful string interpolation and data manipulation
|
|
73
|
+
* **Scripting** as a complete functional programming language
|
|
44
74
|
|
|
45
|
-
[YS](https://yamlscript.org) is a functional programming language with a clean
|
|
46
|
-
YAML syntax.
|
|
47
75
|
|
|
48
|
-
|
|
49
|
-
functional operations, such as:
|
|
76
|
+
## Key Features
|
|
50
77
|
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
78
|
+
* **Drop-in YAML replacement** – Works with your existing YAML files
|
|
79
|
+
* **Variables & functions** – Define and reuse values throughout your files
|
|
80
|
+
* **External data loading** – Import JSON, YAML, or data from URLs
|
|
81
|
+
* **Conditional logic** – Use if/then/else and pattern matching
|
|
82
|
+
* **Data transformation** – Built-ins for transforming & manipulating data
|
|
83
|
+
* **String interpolation** – Embed expressions/variables directly in strings
|
|
84
|
+
* **No JVM required** – Runs as a native library despite compiling to Clojure
|
|
54
85
|
|
|
55
|
-
This YS library should be a drop-in replacement for your current YAML loader!
|
|
56
86
|
|
|
57
|
-
|
|
58
|
-
This means that YS works as a normal YAML loader, but can also evaluate
|
|
59
|
-
functional expressions if asked to.
|
|
87
|
+
## How It Works
|
|
60
88
|
|
|
61
|
-
|
|
62
|
-
This makes YS a complete functional programming language right out of the box.
|
|
89
|
+
YAMLScript extends YAML with a simple, elegant syntax:
|
|
63
90
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
by any programming language that can load shared libraries.
|
|
91
|
+
```yaml
|
|
92
|
+
# file.yaml
|
|
93
|
+
!ys-0: # Enable YAMLScript
|
|
68
94
|
|
|
69
|
-
|
|
70
|
-
|
|
95
|
+
name =: 'World' # Variable assignment
|
|
96
|
+
nums =:: [1, 2, 3] # Any YAML value
|
|
71
97
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
(let
|
|
75
|
-
[names-url "https://raw.githubusercontent.com/dominictarr/random-name/master/first-names.json"
|
|
76
|
-
name-list (json/load (curl names-url))]
|
|
77
|
-
(%
|
|
78
|
-
"name" (first (shuffle name-list))
|
|
79
|
-
"aka" (rand-nth name-list)
|
|
80
|
-
"age" (_& 'num (mul+ 2 3 7))
|
|
81
|
-
"color" (_& 'hue (rand-nth (qw red green blue yellow)))
|
|
82
|
-
"title" (str (_** 'num) " shades of " (_** 'hue) ".")))
|
|
83
|
-
```
|
|
98
|
+
# Literal YAML with ':'
|
|
99
|
+
a key: a value
|
|
84
100
|
|
|
85
|
-
|
|
101
|
+
# Evaluated expressions with '::'
|
|
102
|
+
message:: "Hello, $name!"
|
|
103
|
+
sum:: nums.reduce(+)
|
|
104
|
+
timestamp:: now():str
|
|
105
|
+
```
|
|
86
106
|
|
|
87
|
-
|
|
107
|
+
You can load this file from a program as described below, or you can use the
|
|
108
|
+
`ys` YAMLScript binary to load the file from the command line:
|
|
88
109
|
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
110
|
+
```bash
|
|
111
|
+
$ ys -Y file.yaml
|
|
112
|
+
a key: a value
|
|
113
|
+
message: Hello, World!
|
|
114
|
+
sum: 6
|
|
115
|
+
timestamp: '2025-09-14T22:35:42.832470203Z'
|
|
95
116
|
```
|
|
96
117
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
```yaml
|
|
100
|
-
!YS-v0:
|
|
118
|
+
Under the hood, YAMLScript compiles YAML to Clojure and evaluates it, giving
|
|
119
|
+
you access to a rich functional programming environment.
|
|
101
120
|
|
|
102
|
-
|
|
121
|
+
## Ruby Usage
|
|
103
122
|
|
|
104
|
-
|
|
105
|
-
bar:: load("other.yaml")
|
|
106
|
-
baz:: "Hello, $name!"
|
|
107
|
-
```
|
|
123
|
+
Use `yamlscript` as a drop-in replacement for your current YAML loader:
|
|
108
124
|
|
|
109
|
-
|
|
125
|
+
```ruby
|
|
126
|
+
# program.rb
|
|
127
|
+
require 'yamlscript'
|
|
128
|
+
require 'json'
|
|
110
129
|
|
|
111
|
-
|
|
112
|
-
oh: Hello
|
|
113
|
-
```
|
|
130
|
+
ys = YAMLScript.new
|
|
114
131
|
|
|
115
|
-
|
|
132
|
+
# Load from file
|
|
133
|
+
input = File.read('config.yaml')
|
|
134
|
+
config = ys.load(input)
|
|
116
135
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
{"foo"=>[1, 2, 42], "bar"=>{"oh"=>"Hello"}, "baz"=>"Hello, World!"}
|
|
136
|
+
# Convert to JSON
|
|
137
|
+
puts JSON.pretty_generate(config)
|
|
120
138
|
```
|
|
121
139
|
|
|
122
140
|
|
|
123
141
|
## Installation
|
|
124
142
|
|
|
125
|
-
|
|
143
|
+
Install YAMLScript for Ruby and the `libys.so` shared library:
|
|
126
144
|
|
|
127
145
|
```bash
|
|
128
146
|
gem install yamlscript
|
|
147
|
+
curl -sSL https://yamlscript.org/install | bash
|
|
129
148
|
```
|
|
130
149
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
One simple way to do that is with:
|
|
150
|
+
See <https://yamlscript.org/doc/install/> for more info.
|
|
134
151
|
|
|
135
|
-
```bash
|
|
136
|
-
curl https://yamlscript.org/install | bash
|
|
137
|
-
```
|
|
138
152
|
|
|
139
|
-
|
|
140
|
-
command line utility, `ys`, and the shared library, `libys.so`, into
|
|
141
|
-
`~/local/bin` and `~/.local/lib` respectively.
|
|
153
|
+
### Requirements
|
|
142
154
|
|
|
143
|
-
|
|
155
|
+
* Ruby 2.7 or higher
|
|
144
156
|
|
|
145
157
|
## See Also
|
|
146
158
|
|
|
147
|
-
* [
|
|
148
|
-
* [
|
|
149
|
-
* [
|
|
150
|
-
* [
|
|
151
|
-
* [
|
|
159
|
+
* [YAMLScript Web Site](https://yamlscript.org)
|
|
160
|
+
* [Learn YAMLScript](https://exercism.org/tracks/yamlscript)
|
|
161
|
+
* [YAMLScript Blog](https://yamlscript.org/blog)
|
|
162
|
+
* [YAMLScript Source Code](https://github.com/yaml/yamlscript)
|
|
163
|
+
* [YAMLScript Programs](https://rosettacode.org/wiki/Category:YAMLScript)
|
|
152
164
|
* [YAML](https://yaml.org)
|
|
153
165
|
* [Clojure](https://clojure.org)
|
|
154
166
|
|
|
@@ -163,5 +175,5 @@ See <https://yamlscript.org/doc/install/> for more info.
|
|
|
163
175
|
Copyright 2022-2025 Ingy döt Net <ingy@ingy.net>
|
|
164
176
|
|
|
165
177
|
This project is licensed under the terms of the `MIT` license.
|
|
166
|
-
See [LICENSE](https://github.com/yaml/yamlscript/blob/main/License) for
|
|
167
|
-
|
|
178
|
+
See [LICENSE](https://github.com/yaml/yamlscript/blob/main/License) for more
|
|
179
|
+
details.
|
data/doc/readme.md
CHANGED
|
@@ -1,59 +1,35 @@
|
|
|
1
1
|
## Ruby Usage
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Use `yamlscript` as a drop-in replacement for your current YAML loader:
|
|
4
4
|
|
|
5
5
|
```ruby
|
|
6
|
+
# program.rb
|
|
6
7
|
require 'yamlscript'
|
|
7
|
-
|
|
8
|
-
ys = YAMLScript.new
|
|
9
|
-
data = ys.load(input)
|
|
10
|
-
puts data
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
File `file.ys`:
|
|
14
|
-
|
|
15
|
-
```yaml
|
|
16
|
-
!YS-v0:
|
|
17
|
-
|
|
18
|
-
name =: "World"
|
|
19
|
-
|
|
20
|
-
foo: [1, 2, ! inc(41)]
|
|
21
|
-
bar:: load("other.yaml")
|
|
22
|
-
baz:: "Hello, $name!"
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
File `other.yaml`:
|
|
8
|
+
require 'json'
|
|
26
9
|
|
|
27
|
-
|
|
28
|
-
oh: Hello
|
|
29
|
-
```
|
|
10
|
+
ys = YAMLScript.new
|
|
30
11
|
|
|
31
|
-
|
|
12
|
+
# Load from file
|
|
13
|
+
input = File.read('config.yaml')
|
|
14
|
+
config = ys.load(input)
|
|
32
15
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
{"foo"=>[1, 2, 42], "bar"=>{"oh"=>"Hello"}, "baz"=>"Hello, World!"}
|
|
16
|
+
# Convert to JSON
|
|
17
|
+
puts JSON.pretty_generate(config)
|
|
36
18
|
```
|
|
37
19
|
|
|
38
20
|
|
|
39
21
|
## Installation
|
|
40
22
|
|
|
41
|
-
|
|
23
|
+
Install YAMLScript for Ruby and the `libys.so` shared library:
|
|
42
24
|
|
|
43
25
|
```bash
|
|
44
26
|
gem install yamlscript
|
|
27
|
+
curl -sSL https://yamlscript.org/install | bash
|
|
45
28
|
```
|
|
46
29
|
|
|
47
|
-
|
|
30
|
+
See <https://yamlscript.org/doc/install/> for more info.
|
|
48
31
|
|
|
49
|
-
One simple way to do that is with:
|
|
50
32
|
|
|
51
|
-
|
|
52
|
-
curl https://yamlscript.org/install | bash
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
> Note: The above command will install the latest version of the YAMLScript
|
|
56
|
-
command line utility, `ys`, and the shared library, `libys.so`, into
|
|
57
|
-
`~/local/bin` and `~/.local/lib` respectively.
|
|
33
|
+
### Requirements
|
|
58
34
|
|
|
59
|
-
|
|
35
|
+
* Ruby 2.7 or higher
|
data/lib/yamlscript/version.rb
CHANGED
data/lib/yamlscript.rb
CHANGED
|
@@ -16,7 +16,7 @@ class YAMLScript
|
|
|
16
16
|
# This value is automatically updated by 'make bump'.
|
|
17
17
|
# The version number is used to find the correct shared library file.
|
|
18
18
|
# We currently only support binding to an exact version of libys.
|
|
19
|
-
YAMLSCRIPT_VERSION = '0.2.
|
|
19
|
+
YAMLSCRIPT_VERSION = '0.2.5'
|
|
20
20
|
|
|
21
21
|
# A low-level interface to the native library
|
|
22
22
|
module LibYS
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: yamlscript
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ingy döt Net
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: exe
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2025-
|
|
12
|
+
date: 2025-10-20 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: minitest
|