yamlscript 0.2.3 → 0.2.4
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 +4 -0
- data/ReadMe.md +113 -101
- 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: 0a62fb7a5f809111d94cbcc1e0824396bd90ec24e0ad3c18aecebef412a213cc
|
4
|
+
data.tar.gz: 97f3b6629be5f8ca08ed1b9564539c0533fb40e10d67639e45c5fbf0526db367
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a89ad53088075994459d49b5ce23aff9b840cefdd8baf2f865d44d6d95fb79be2882d2f0503332ec595ddb47d8acc7823060c8e55806d8b307b1497e9c5e53f0
|
7
|
+
data.tar.gz: 17f583776e27b926edee1c4d877854ff9c34647ef4f85ef2d39ec18f199379aa23f517d97c6c460c5f6c3c8a78b975a30ce7bdeafdf38f83b2ff00eaeb535d25
|
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
|
18
|
+
# config.yaml with YAMLScript:
|
14
19
|
!YS-v0:
|
15
20
|
|
16
|
-
#
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
29
54
|
```
|
30
55
|
|
31
|
-
and get:
|
32
|
-
```json
|
33
|
-
{
|
34
|
-
"name": "Dolores",
|
35
|
-
"aka": "Anita",
|
36
|
-
"age": 42,
|
37
|
-
"color": "green",
|
38
|
-
"title": "42 shades of green."
|
39
|
-
}
|
40
|
-
```
|
41
56
|
|
57
|
+
## What is YAMLScript?
|
42
58
|
|
43
|
-
|
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.
|
44
61
|
|
45
|
-
|
46
|
-
|
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.
|
47
66
|
|
48
|
-
|
49
|
-
functional operations, such as:
|
67
|
+
It's perfect for:
|
50
68
|
|
51
|
-
*
|
52
|
-
*
|
53
|
-
|
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
|
54
74
|
|
55
|
-
This YS library should be a drop-in replacement for your current YAML loader!
|
56
75
|
|
57
|
-
|
58
|
-
This means that YS works as a normal YAML loader, but can also evaluate
|
59
|
-
functional expressions if asked to.
|
76
|
+
## Key Features
|
60
77
|
|
61
|
-
|
62
|
-
|
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
|
63
85
|
|
64
|
-
Even though YS compiles to Clojure, and Clojure compiles to Java, there is no
|
65
|
-
dependency on Java or the JVM.
|
66
|
-
YS is compiled to a native shared library (`libys.so`) that can be used
|
67
|
-
by any programming language that can load shared libraries.
|
68
86
|
|
69
|
-
|
70
|
-
CLI binary `ys` to run:
|
87
|
+
## How It Works
|
71
88
|
|
72
|
-
|
73
|
-
$ ys --compile file.ys
|
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
|
-
```
|
89
|
+
YAMLScript extends YAML with a simple, elegant syntax:
|
84
90
|
|
85
|
-
|
91
|
+
```yaml
|
92
|
+
# file.yaml
|
93
|
+
!YS-v0: # Enable YAMLScript
|
86
94
|
|
87
|
-
|
95
|
+
name =: 'World' # Variable assignment
|
96
|
+
nums =:: [1, 2, 3] # Any YAML value
|
88
97
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
98
|
+
# Literal YAML with ':'
|
99
|
+
a key: a value
|
100
|
+
|
101
|
+
# Evaluated expressions with '::'
|
102
|
+
message:: "Hello, $name!"
|
103
|
+
sum:: nums.reduce(+)
|
104
|
+
timestamp:: now():str
|
95
105
|
```
|
96
106
|
|
97
|
-
|
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:
|
98
109
|
|
99
|
-
```
|
100
|
-
|
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'
|
116
|
+
```
|
101
117
|
|
102
|
-
|
118
|
+
Under the hood, YAMLScript compiles YAML to Clojure and evaluates it, giving
|
119
|
+
you access to a rich functional programming environment.
|
103
120
|
|
104
|
-
|
105
|
-
bar:: load("other.yaml")
|
106
|
-
baz:: "Hello, $name!"
|
107
|
-
```
|
121
|
+
## Ruby Usage
|
108
122
|
|
109
|
-
|
123
|
+
Use `yamlscript` as a drop-in replacement for your current YAML loader:
|
110
124
|
|
111
|
-
```
|
112
|
-
|
113
|
-
|
125
|
+
```ruby
|
126
|
+
# program.rb
|
127
|
+
require 'yamlscript'
|
128
|
+
require 'json'
|
114
129
|
|
115
|
-
|
130
|
+
ys = YAMLScript.new
|
131
|
+
|
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
|
-
|
150
|
+
See <https://yamlscript.org/doc/install/> for more info.
|
132
151
|
|
133
|
-
One simple way to do that is with:
|
134
152
|
|
135
|
-
|
136
|
-
curl https://yamlscript.org/install | bash
|
137
|
-
```
|
138
|
-
|
139
|
-
> Note: The above command will install the latest version of the YAMLScript
|
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.4'
|
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.4
|
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-09-
|
12
|
+
date: 2025-09-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|