kojo 0.3.5 → 0.3.9
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/README.md +72 -43
- data/lib/kojo/cli.rb +2 -0
- data/lib/kojo/commands/command_base.rb +2 -3
- data/lib/kojo/commands/config.rb +2 -10
- data/lib/kojo/commands/dir.rb +2 -2
- data/lib/kojo/commands/file.rb +3 -4
- data/lib/kojo/commands/form.rb +35 -0
- data/lib/kojo/commands/single.rb +1 -1
- data/lib/kojo/commands/to_json.rb +67 -0
- data/lib/kojo/config.rb +1 -3
- data/lib/kojo/extensions/yaml.rb +10 -0
- data/lib/kojo/form.rb +60 -0
- data/lib/kojo/front_matter_template.rb +1 -3
- data/lib/kojo/refinements/string.rb +1 -1
- data/lib/kojo/version.rb +1 -1
- data/lib/kojo.rb +5 -1
- metadata +36 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1952c33f6d6360f1a027ee30eefcfea5636a062c2c28c02d83916d99e51ed7c1
|
4
|
+
data.tar.gz: 9554ea0de969c79e11d40b237d4ffb24c3bceead6dc863511124af6b4753841b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40bdbcfa32871516c1776923dffd3d78b0757463941da85708b4292e9a84f5c8308dd655e1707493e6da9411771a12c18a57d7098ae0d85cc1c537bf41d3fcb7
|
7
|
+
data.tar.gz: 76d43feccd9c0210bd3239f86b089a27527fdbd293daaf771dcb3d8170dd5d57a864e2a7fc399a00b6989d963659eb1e7ea9a7b8e7f23561a288a27e7187d941
|
data/README.md
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
<div align='center'>
|
2
2
|
|
3
|
-

|
4
4
|
|
5
|
-
Kojo Configuration Ninja
|
6
|
-
==================================================
|
5
|
+
# Kojo Configuration Ninja
|
7
6
|
|
8
7
|
[](https://badge.fury.io/rb/kojo)
|
9
8
|
[](https://github.com/DannyBen/kojo/actions?query=workflow%3ATest)
|
@@ -11,15 +10,14 @@ Kojo Configuration Ninja
|
|
11
10
|
|
12
11
|
|
13
12
|
Kojo helps you generate configuration files from templates, using variables
|
14
|
-
and definition files.
|
15
|
-
|
13
|
+
and definition files. It is a command line utility, and works on any text file
|
14
|
+
format.
|
16
15
|
|
17
16
|
</div>
|
18
17
|
|
19
18
|
---
|
20
19
|
|
21
|
-
Table of Contents
|
22
|
-
--------------------------------------------------
|
20
|
+
## Table of Contents
|
23
21
|
|
24
22
|
- [Installation](#installation)
|
25
23
|
- [Usage](#usage)
|
@@ -28,31 +26,36 @@ Table of Contents
|
|
28
26
|
- [Transform an Entire Folder](#transform-an-entire-folder)
|
29
27
|
- [Transform One to Many using Config](#transform-one-to-many-using-config)
|
30
28
|
- [Transform One to Many using Front Matter](#transform-one-to-many-using-front-matter)
|
29
|
+
- [Convert YAML to JSON](#convert-yaml-to-json)
|
30
|
+
- [Interactive Form Templates](#interactive-form-templates)
|
31
31
|
- [Conditions and Loops with ERB](#conditions-and-loops-with-erb)
|
32
|
-
- [Interactive
|
32
|
+
- [Interactive Fallback](#interactive-fallback)
|
33
33
|
- [Using from Ruby Code](#using-from-ruby-code)
|
34
34
|
- [Contributing / Support](#contributing--support)
|
35
35
|
|
36
36
|
---
|
37
37
|
|
38
|
-
Installation
|
39
|
-
--------------------------------------------------
|
38
|
+
## Installation
|
40
39
|
|
41
|
-
|
40
|
+
```shell
|
41
|
+
$ gem install kojo
|
42
|
+
```
|
42
43
|
|
44
|
+
Or with Docker:
|
43
45
|
|
46
|
+
```shell
|
47
|
+
$ alias kojo='docker run --rm -it -v "$PWD:/app" dannyben/kojo'
|
48
|
+
```
|
44
49
|
|
45
|
-
Usage
|
46
|
-
--------------------------------------------------
|
50
|
+
## Usage
|
47
51
|
|
48
52
|
If you prefer to learn by example, see the [examples](examples#examples) folder for
|
49
53
|
several use cases. Each example subfolder contains the command to run, the
|
50
54
|
relevant files, and the expected output.
|
51
55
|
|
52
|
-
|
53
56
|
### Variables
|
54
57
|
|
55
|
-

|
56
59
|
|
57
60
|
Include variables in your configuration templates by using this syntax:
|
58
61
|
`%{varname}`
|
@@ -63,11 +66,13 @@ Include variables in your configuration templates by using this syntax:
|
|
63
66
|
- Variables from the top level will be forwarded downstream, and aggregated
|
64
67
|
with any additional variables that are defined in subsequent `@imports`.
|
65
68
|
|
66
|
-
|
69
|
+
Note that since the `%` sign is used for variable replacement, if you want
|
70
|
+
your generated file to include a literal percent sign, you need to escape it
|
71
|
+
as `%%` in your template.
|
67
72
|
|
68
73
|
### Import
|
69
74
|
|
70
|
-

|
71
76
|
|
72
77
|
Use the `@import filename` directive anywhere to include another file in the
|
73
78
|
resulting configuration file.
|
@@ -86,22 +91,18 @@ resulting configuration file.
|
|
86
91
|
|
87
92
|
The space after `filename` is optional.
|
88
93
|
|
89
|
-
|
90
|
-
|
91
94
|
### Transform an Entire Folder
|
92
95
|
|
93
|
-

|
94
97
|
|
95
98
|
Process a folder containing templates and `@imports`, and generate a mirror
|
96
99
|
output folder, with all the variables and `@imports` evaluated.
|
97
100
|
|
98
101
|
You may use `%{variables}` in filenames.
|
99
102
|
|
100
|
-
|
101
|
-
|
102
103
|
### Transform One to Many using Config
|
103
104
|
|
104
|
-

|
105
106
|
|
106
107
|
Using the `kojo config` command together with a simple definitions file, you
|
107
108
|
can:
|
@@ -146,7 +147,7 @@ output:
|
|
146
147
|
|
147
148
|
### Transform One to Many using Front Matter
|
148
149
|
|
149
|
-

|
150
151
|
|
151
152
|
Define a template that contains the instructions on how to transform it as a
|
152
153
|
YAML front matter.
|
@@ -154,7 +155,7 @@ YAML front matter.
|
|
154
155
|
The YAML front matter should be structured like this:
|
155
156
|
|
156
157
|
```yaml
|
157
|
-
|
158
|
+
filename1:
|
158
159
|
arg: value
|
159
160
|
another_arg: value
|
160
161
|
|
@@ -169,9 +170,36 @@ Your template that uses %{arg} goes here
|
|
169
170
|
Additional arguments provided to the command line, will also be transferred
|
170
171
|
to the template.
|
171
172
|
|
173
|
+
### Convert YAML to JSON
|
174
|
+
|
175
|
+

|
176
|
+
|
177
|
+
Convert one or more YAML files to JSON.
|
178
|
+
|
179
|
+
This can be useful when you require JSON files as output, but wish to edit
|
180
|
+
(or generate using Kojo) using the less error-prone and more aesthetically
|
181
|
+
pleasing YAML format.
|
182
|
+
|
183
|
+
Note that this Kojo command does not provide any additional preprocessing - the
|
184
|
+
input files should be valid YAML.
|
185
|
+
|
186
|
+
### Interactive Form Templates
|
187
|
+
|
188
|
+

|
189
|
+
|
190
|
+
Using the `kojo form` command lets you define an ERB or [ERBX][erbx] template, and include interactive prompts to enter the input.
|
191
|
+
|
192
|
+
1. Use either ERB tags (`<%= %>`, `<%- -%>`) or ERBX tags (`{{ }}`, `(( ))`).
|
193
|
+
2. Use the built in `prompt` object, which is a [TTY::Prompt](tty-prompt) instance, to prompt for input when running the command (for example: `{{ prompt.ask? "Your Name?" }}`)
|
194
|
+
3. Any unidentified ruby command will be forwarded to the `prompt` object, so `prompt.ask` is the same as just using `ask`.
|
195
|
+
4. If there is a file with the same name as the template, and with an `.rb` extension (for example `form.md` and `form.md.rb`), then the ruby file will be loaded into the ERB template as if it was written inside it.
|
196
|
+
5. If you prefer using a single template file (without the ruby appendix), you can simply use regular ERB/ERBX tags, like demonstrated below.
|
197
|
+
|
198
|
+

|
199
|
+
|
172
200
|
### Conditions and Loops with ERB
|
173
201
|
|
174
|
-

|
175
203
|
|
176
204
|
Template files are evaluated using ERB, so you can use any Ruby code for more
|
177
205
|
advanced templates (for conditions, loops etc.).
|
@@ -182,15 +210,12 @@ Use this syntax for ruby code:
|
|
182
210
|
<%- ruby code here -%> # for code that should not be printed
|
183
211
|
<%= ruby code here -%> # for code that should be printed
|
184
212
|
```
|
185
|
-
|
186
|
-
|
187
|
-
Interactive Mode
|
188
|
-
--------------------------------------------------
|
213
|
+
## Interactive Fallback
|
189
214
|
|
190
215
|
When Kojo encounters a variable that was not supplied (either through the command
|
191
216
|
line or through a configuration file), it will prompt for a value.
|
192
217
|
|
193
|
-

|
194
219
|
|
195
220
|
You can enable or disable interactive mode by setting the environment
|
196
221
|
variable `KOJO_INTERACTIVE` to `yes` or `no`.
|
@@ -201,21 +226,20 @@ running from within Ruby code.
|
|
201
226
|
When running from within Ruby code, you can also use `Kojo.interactive = true`
|
202
227
|
and `Kojo.interactive?` to get the current state.
|
203
228
|
|
204
|
-
|
205
|
-
Using from Ruby Code
|
206
|
-
--------------------------------------------------
|
229
|
+
## Using from Ruby Code
|
207
230
|
|
208
231
|
Although Kojo was primarily designed as a command line utility, you can also
|
209
232
|
use it as a library from your Ruby code.
|
210
233
|
|
211
234
|
These are the primary classes:
|
212
235
|
|
213
|
-
| Class | Description | CLI equivalent
|
214
|
-
|
215
|
-
| `Kojo::Template` | generate from a single template | `kojo file`
|
216
|
-
| `Kojo::FrontMatterTemplate` | generate from a template with a front matter | `kojo single`
|
217
|
-
| `Kojo::Config` | generate from a config file | `kojo config`
|
218
|
-
| `Kojo::Collection` | generate from a directory | `kojo dir`
|
236
|
+
| Class | Description | CLI equivalent |
|
237
|
+
| --------------------------- | -------------------------------------------- | -------------- |
|
238
|
+
| `Kojo::Template` | generate from a single template | `kojo file` |
|
239
|
+
| `Kojo::FrontMatterTemplate` | generate from a template with a front matter | `kojo single` |
|
240
|
+
| `Kojo::Config` | generate from a config file | `kojo config` |
|
241
|
+
| `Kojo::Collection` | generate from a directory | `kojo dir` |
|
242
|
+
| `Kojo::Form` | generate interactively | `kojo form` |
|
219
243
|
|
220
244
|
### Examples
|
221
245
|
|
@@ -249,6 +273,10 @@ params = { version: '0.1.1' }
|
|
249
273
|
template.render params do |path, content|
|
250
274
|
# code to handle results here
|
251
275
|
end
|
276
|
+
|
277
|
+
# Form
|
278
|
+
template = Kojo::Form.new 'examples/form/movie.md'
|
279
|
+
puts template.render
|
252
280
|
```
|
253
281
|
|
254
282
|
In addition, Kojo extends Ruby's `File` class with the `File.deep_write`
|
@@ -265,12 +293,13 @@ config.generate do |path, content|
|
|
265
293
|
end
|
266
294
|
```
|
267
295
|
|
268
|
-
Contributing / Support
|
269
|
-
--------------------------------------------------
|
296
|
+
## Contributing / Support
|
270
297
|
|
271
298
|
If you experience any issue, have a question or a suggestion, or if you wish
|
272
299
|
to contribute, feel free to [open an issue][issues].
|
273
300
|
|
274
301
|
---
|
275
302
|
|
276
|
-
[issues]: https://github.com/DannyBen/kojo/issues
|
303
|
+
[issues]: https://github.com/DannyBen/kojo/issues
|
304
|
+
[erbx]: https://github.com/DannyBen/erbx
|
305
|
+
[tty-prompt]: https://github.com/piotrmurach/tty-prompt#contents
|
data/lib/kojo/cli.rb
CHANGED
@@ -15,6 +15,8 @@ module Kojo
|
|
15
15
|
runner.route 'dir', to: Kojo::Commands::DirCmd
|
16
16
|
runner.route 'config', to: Kojo::Commands::ConfigCmd
|
17
17
|
runner.route 'single', to: Kojo::Commands::SingleCmd
|
18
|
+
runner.route 'form', to: Kojo::Commands::FormCmd
|
19
|
+
runner.route 'tojson', to: Kojo::Commands::ToJsonCmd
|
18
20
|
|
19
21
|
runner
|
20
22
|
end
|
@@ -4,9 +4,8 @@ module Kojo
|
|
4
4
|
module Commands
|
5
5
|
class CommandBase < MisterBin::Command
|
6
6
|
def save(file, output)
|
7
|
-
|
8
|
-
|
9
|
-
say "Saved #{outpath}"
|
7
|
+
File.deep_write file, output
|
8
|
+
say "Saved #{file}"
|
10
9
|
end
|
11
10
|
end
|
12
11
|
end
|
data/lib/kojo/commands/config.rb
CHANGED
@@ -3,7 +3,7 @@ require 'mister_bin'
|
|
3
3
|
|
4
4
|
module Kojo::Commands
|
5
5
|
# Handle calls to the +kojo config+ command
|
6
|
-
class ConfigCmd <
|
6
|
+
class ConfigCmd < CommandBase
|
7
7
|
using Kojo::Refinements
|
8
8
|
|
9
9
|
attr_reader :gen, :outdir, :opts, :import_base, :config_file
|
@@ -33,7 +33,7 @@ module Kojo::Commands
|
|
33
33
|
argfile = args['--args']
|
34
34
|
|
35
35
|
if argfile
|
36
|
-
fileopts = YAML.
|
36
|
+
fileopts = YAML.properly_load_file(argfile).symbolize_keys
|
37
37
|
@opts = fileopts.merge opts
|
38
38
|
end
|
39
39
|
|
@@ -59,13 +59,5 @@ module Kojo::Commands
|
|
59
59
|
say output
|
60
60
|
end
|
61
61
|
end
|
62
|
-
|
63
|
-
def save(path, output)
|
64
|
-
dir = File.dirname path
|
65
|
-
FileUtils.mkdir_p dir unless Dir.exist? dir
|
66
|
-
File.write path, output
|
67
|
-
say "Saved #{path}"
|
68
|
-
end
|
69
|
-
|
70
62
|
end
|
71
63
|
end
|
data/lib/kojo/commands/dir.rb
CHANGED
@@ -33,7 +33,7 @@ module Kojo
|
|
33
33
|
argfile = args['--args']
|
34
34
|
|
35
35
|
if argfile
|
36
|
-
fileopts = YAML.
|
36
|
+
fileopts = YAML.properly_load_file(argfile).symbolize_keys
|
37
37
|
@opts = fileopts.merge @opts
|
38
38
|
end
|
39
39
|
|
@@ -62,7 +62,7 @@ module Kojo
|
|
62
62
|
|
63
63
|
def write(collection)
|
64
64
|
collection.render @opts do |file, output|
|
65
|
-
save file, output
|
65
|
+
save "#{outdir}/#{file}", output
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
data/lib/kojo/commands/file.rb
CHANGED
@@ -3,7 +3,7 @@ require 'mister_bin'
|
|
3
3
|
module Kojo
|
4
4
|
module Commands
|
5
5
|
# Handle calls to the +kojo file+ command
|
6
|
-
class FileCmd <
|
6
|
+
class FileCmd < CommandBase
|
7
7
|
using Kojo::Refinements
|
8
8
|
|
9
9
|
attr_reader :opts, :outfile, :infile, :import_base
|
@@ -33,7 +33,7 @@ module Kojo
|
|
33
33
|
argfile = args['--args']
|
34
34
|
|
35
35
|
if argfile
|
36
|
-
fileopts = YAML.
|
36
|
+
fileopts = YAML.properly_load_file(argfile).symbolize_keys
|
37
37
|
@opts = fileopts.merge opts
|
38
38
|
end
|
39
39
|
|
@@ -48,8 +48,7 @@ module Kojo
|
|
48
48
|
output = template.render(opts)
|
49
49
|
|
50
50
|
if outfile
|
51
|
-
|
52
|
-
say "Saved #{outfile}"
|
51
|
+
save outfile, output
|
53
52
|
else
|
54
53
|
puts output
|
55
54
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'mister_bin'
|
2
|
+
|
3
|
+
module Kojo
|
4
|
+
module Commands
|
5
|
+
# Handle calls to the +kojo form+ command
|
6
|
+
class FormCmd < CommandBase
|
7
|
+
attr_reader :infile, :outdir
|
8
|
+
|
9
|
+
help "Fill a template form interactively"
|
10
|
+
|
11
|
+
usage "kojo form INFILE [--save FILE]"
|
12
|
+
usage "kojo form (-h|--help)"
|
13
|
+
|
14
|
+
option "-s --save FILE", "Save to file instead of printing"
|
15
|
+
|
16
|
+
param "INFILE", "ERBX template to transform"
|
17
|
+
|
18
|
+
example "kojo form report.md"
|
19
|
+
example "kojo form report.md --save output.md"
|
20
|
+
|
21
|
+
def run
|
22
|
+
infile = args['INFILE']
|
23
|
+
outfile = args['--save']
|
24
|
+
template = Kojo::Form.new infile
|
25
|
+
|
26
|
+
if outfile
|
27
|
+
save outfile, template.render
|
28
|
+
else
|
29
|
+
puts template.render
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/kojo/commands/single.rb
CHANGED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'mister_bin'
|
2
|
+
|
3
|
+
module Kojo
|
4
|
+
module Commands
|
5
|
+
# Handle calls to the +kojo dir+ command
|
6
|
+
class ToJsonCmd < CommandBase
|
7
|
+
using Kojo::Refinements
|
8
|
+
|
9
|
+
attr_reader :input, :save_files, :replace_files
|
10
|
+
|
11
|
+
help "Convert one or more YAML files to JSON"
|
12
|
+
|
13
|
+
usage "kojo tojson INPUT... [(--save | --replace)]"
|
14
|
+
usage "kojo tojson (-h|--help)"
|
15
|
+
|
16
|
+
option "-s --save", "Save each input file in the same directory"
|
17
|
+
option "-r --replace", "Save each input file in the same directory and delete the input file"
|
18
|
+
|
19
|
+
param "INPUT", "Path to a YAML file or multiple files using a glob pattern"
|
20
|
+
|
21
|
+
example "kojo tojson myfile.yaml"
|
22
|
+
example "kojo tojson myfile.yaml --save"
|
23
|
+
example "kojo tojson indir/*.yaml"
|
24
|
+
example "kojo tojson indir/*.yaml --replace"
|
25
|
+
example "kojo tojson indir/**/*.yml"
|
26
|
+
|
27
|
+
def run
|
28
|
+
@input = get_input_files
|
29
|
+
@save_files = args['--save'] || args['--replace']
|
30
|
+
@replace_files = args['--replace']
|
31
|
+
|
32
|
+
save_files ? write : show
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def tojson(path)
|
38
|
+
JSON.pretty_generate YAML.properly_load_file(path)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Glob patterns are usually handled by the shell, but in case
|
42
|
+
# we still have '*' in our string (for example, if it was sent
|
43
|
+
# quoted), we will do the globbing ourselves
|
44
|
+
def get_input_files
|
45
|
+
args['INPUT'].map do |path|
|
46
|
+
path.include?('*') ? Dir[path].sort : path
|
47
|
+
end.flatten
|
48
|
+
end
|
49
|
+
|
50
|
+
def show
|
51
|
+
input.each do |infile|
|
52
|
+
outfile = infile.gsub(/\.ya?ml/, '.json')
|
53
|
+
say "\n!txtgrn!# #{outfile}"
|
54
|
+
say tojson(infile)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def write
|
59
|
+
input.each do |infile|
|
60
|
+
outfile = infile.gsub(/\.ya?ml/, '.json')
|
61
|
+
save outfile, tojson(infile)
|
62
|
+
File.delete infile if replace_files
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/kojo/config.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
1
|
module Kojo
|
4
2
|
# The Config class handles multiple template generation from a
|
5
3
|
# definitions YAML file.
|
@@ -61,7 +59,7 @@ module Kojo
|
|
61
59
|
end
|
62
60
|
|
63
61
|
def config
|
64
|
-
@config ||= YAML.
|
62
|
+
@config ||= YAML.properly_load_file config_file
|
65
63
|
end
|
66
64
|
end
|
67
65
|
|
data/lib/kojo/form.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'erbx'
|
2
|
+
require 'tty-prompt'
|
3
|
+
|
4
|
+
module Kojo
|
5
|
+
# The Form class handles interactive ERBX templates
|
6
|
+
class Form
|
7
|
+
attr_reader :file
|
8
|
+
|
9
|
+
def initialize(file)
|
10
|
+
@file = file
|
11
|
+
end
|
12
|
+
|
13
|
+
def content
|
14
|
+
@content ||= content!
|
15
|
+
end
|
16
|
+
|
17
|
+
def content!
|
18
|
+
content = File.read file
|
19
|
+
ruby_code = File.exist?("#{file}.rb") ? File.read("#{file}.rb") : nil
|
20
|
+
content = "<%-\n#{ruby_code}\n-%>\n#{content}" if ruby_code
|
21
|
+
content
|
22
|
+
end
|
23
|
+
|
24
|
+
def render
|
25
|
+
ERBX.new(content).result(binding)
|
26
|
+
rescue TTY::Reader::InputInterrupt
|
27
|
+
# :nocov:
|
28
|
+
raise Kojo::Interrupt
|
29
|
+
# :nocov:
|
30
|
+
end
|
31
|
+
|
32
|
+
def prompt
|
33
|
+
@prompt ||= TTY::Prompt.new
|
34
|
+
end
|
35
|
+
|
36
|
+
def method_missing(method_name, *args, **kargs, &block)
|
37
|
+
if respond_to? method_name
|
38
|
+
prompt.send method_name, *args, **kargs, &block
|
39
|
+
else
|
40
|
+
super
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def respond_to?(method_name, include_private = false)
|
45
|
+
prompt.respond_to?(method_name) || super
|
46
|
+
end
|
47
|
+
|
48
|
+
# Below are TTY::Prompt functions that are not captured by the
|
49
|
+
# `mthod_missing`, so we specify them explicitly
|
50
|
+
|
51
|
+
def select(*args, &block)
|
52
|
+
prompt.select *args, &block
|
53
|
+
end
|
54
|
+
|
55
|
+
def warn(*args, &block)
|
56
|
+
prompt.warn *args, &block
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
1
|
module Kojo
|
4
2
|
# The FrontMatterTemplate class handles a single template file, that
|
5
3
|
# contains a YAML front matter.
|
@@ -34,7 +32,7 @@ module Kojo
|
|
34
32
|
def read_file(file)
|
35
33
|
raise Kojo::NotFoundError, "File not found: #{file}" unless File.exist? file
|
36
34
|
|
37
|
-
config = YAML.
|
35
|
+
config = YAML.properly_load_file file
|
38
36
|
content = File.read(file)[/^---\s*$\n(.*)/m, 1]
|
39
37
|
|
40
38
|
[config, content]
|
data/lib/kojo/version.rb
CHANGED
data/lib/kojo.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
require 'requires'
|
2
2
|
require 'byebug' if ENV['BYEBUG']
|
3
3
|
|
4
|
-
|
4
|
+
require 'yaml'
|
5
|
+
require 'json'
|
6
|
+
|
5
7
|
requires 'kojo/extensions'
|
8
|
+
requires 'kojo/refinements'
|
6
9
|
|
7
10
|
require 'kojo/exceptions'
|
8
11
|
require 'kojo/template'
|
9
12
|
require 'kojo/collection'
|
10
13
|
require 'kojo/config'
|
11
14
|
require 'kojo/front_matter_template'
|
15
|
+
require 'kojo/form'
|
12
16
|
|
13
17
|
module Kojo
|
14
18
|
class << self
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kojo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mister_bin
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: tty-prompt
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.21'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.21'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: erbx
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.1.1
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.1.1
|
55
83
|
description: Generate configuration files from templates, using variables and definition
|
56
84
|
files.
|
57
85
|
email: db@dannyben.com
|
@@ -69,10 +97,14 @@ files:
|
|
69
97
|
- lib/kojo/commands/config.rb
|
70
98
|
- lib/kojo/commands/dir.rb
|
71
99
|
- lib/kojo/commands/file.rb
|
100
|
+
- lib/kojo/commands/form.rb
|
72
101
|
- lib/kojo/commands/single.rb
|
102
|
+
- lib/kojo/commands/to_json.rb
|
73
103
|
- lib/kojo/config.rb
|
74
104
|
- lib/kojo/exceptions.rb
|
75
105
|
- lib/kojo/extensions/file.rb
|
106
|
+
- lib/kojo/extensions/yaml.rb
|
107
|
+
- lib/kojo/form.rb
|
76
108
|
- lib/kojo/front_matter_template.rb
|
77
109
|
- lib/kojo/refinements/array.rb
|
78
110
|
- lib/kojo/refinements/hash.rb
|
@@ -91,14 +123,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
123
|
requirements:
|
92
124
|
- - ">="
|
93
125
|
- !ruby/object:Gem::Version
|
94
|
-
version: 2.
|
126
|
+
version: 2.6.0
|
95
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
128
|
requirements:
|
97
129
|
- - ">="
|
98
130
|
- !ruby/object:Gem::Version
|
99
131
|
version: '0'
|
100
132
|
requirements: []
|
101
|
-
rubygems_version: 3.
|
133
|
+
rubygems_version: 3.2.15
|
102
134
|
signing_key:
|
103
135
|
specification_version: 4
|
104
136
|
summary: Configuration Ninja
|