kojo 0.0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +83 -7
- data/bin/kojo-compile.rb +45 -0
- data/bin/kojo-run.rb +9 -8
- data/lib/kojo/generator.rb +1 -9
- data/lib/kojo/template.rb +6 -2
- data/lib/kojo/version.rb +1 -1
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c58d14e183cbe6bbad4dc235351722f1fc8da21c04ccdba6df2a4e31e3c8afd7
|
4
|
+
data.tar.gz: dd80f41a56a7ee19c7dd4d3d66f3683607e071217c5177a6089c99bf9d256983
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0035c2e9229b9d5abe09ce695c12aac1a6591242bb516379aede669fce7319fd4c74a000cf40410cb9edbf86855644e11b3c09fe299a4bd466d693a464eb772
|
7
|
+
data.tar.gz: f87db6ee6fddc7efce65cba34e5d6513f6c4a553c1c417a03c7ec7119df2fa0e0e57133ee761ac277381ca1c4144c66f9a615e8edb05122b3da3885319fc58cf
|
data/README.md
CHANGED
@@ -1,16 +1,20 @@
|
|
1
|
-
|
1
|
+
<div align='center'>
|
2
|
+
|
3
|
+
![kojo](images/kojo.png)
|
2
4
|
|
3
5
|
Kojo - Configuration Ninja
|
4
6
|
==================================================
|
5
7
|
|
6
|
-
[![Gem](https://
|
7
|
-
[![Build](https://
|
8
|
-
[![Maintainability](https://
|
9
|
-
[![Issues](https://img.shields.io/codeclimate/issues/github/DannyBen/kojo.svg?style=flat-square)](https://codeclimate.com/github/DannyBen/kojo)
|
8
|
+
[![Gem Version](https://badge.fury.io/rb/kojo.svg)](https://badge.fury.io/rb/kojo)
|
9
|
+
[![Build Status](https://travis-ci.com/DannyBen/kojo.svg?branch=master)](https://travis-ci.com/DannyBen/kojo)
|
10
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/f24566ad04b5054a2251/maintainability)](https://codeclimate.com/github/DannyBen/kojo/maintainability)
|
10
11
|
|
11
|
-
---
|
12
12
|
|
13
|
+
Kojo helps you generate configuration files from templates, using variables
|
14
|
+
and definition files.
|
15
|
+
It is a command line utility, and it works on any text file format.
|
13
16
|
|
17
|
+
</div>
|
14
18
|
|
15
19
|
---
|
16
20
|
|
@@ -24,4 +28,76 @@ Installation
|
|
24
28
|
Usage
|
25
29
|
--------------------------------------------------
|
26
30
|
|
27
|
-
|
31
|
+
If you prefer to learn by example, see the [examples](examples) folder for
|
32
|
+
several use cases. Each example subfolder contains the command to run, the
|
33
|
+
relevant files, and the expected output.
|
34
|
+
|
35
|
+
|
36
|
+
### Variables
|
37
|
+
|
38
|
+
![kojo](images/features-vars.svg)
|
39
|
+
|
40
|
+
Include variables in your configuration templates using this syntax:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
%{varname}
|
44
|
+
```
|
45
|
+
|
46
|
+
- Variables can be provided through the command line, or when using `@import`.
|
47
|
+
- Variables from the top level will be forwarded downstream, and aggregated
|
48
|
+
with any additional variables that are defined in subsequent `@imports`.
|
49
|
+
|
50
|
+
|
51
|
+
### Import
|
52
|
+
|
53
|
+
![kojo](images/features-import.svg)
|
54
|
+
|
55
|
+
Use the `@import filename` directive anywhere to include another file in the
|
56
|
+
resulting configuration file.
|
57
|
+
|
58
|
+
- The `@import` directive should be the only thing in the line.
|
59
|
+
- The indentation will be respected when importing.
|
60
|
+
- The `filename` parameter does not have to include an extension - Kojo will
|
61
|
+
use the same extension as the parent file.
|
62
|
+
- The included file will be searched for relative to the file it is included
|
63
|
+
in.
|
64
|
+
- Arguments can be passed down to the included template by using this syntax:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
@import filename (arg: "value", arg2: "value")
|
68
|
+
```
|
69
|
+
|
70
|
+
The space after `filename` is optional.
|
71
|
+
|
72
|
+
|
73
|
+
### One to Many Generation
|
74
|
+
|
75
|
+
![kojo](images/features-config.svg)
|
76
|
+
|
77
|
+
In order to generate several configuration files that are based on the same
|
78
|
+
template, you should:
|
79
|
+
|
80
|
+
1. Create the configuration template, using `%{variables}` and `@imports`
|
81
|
+
where appropriate.
|
82
|
+
2. Create a configuration YAML file using this syntax:
|
83
|
+
|
84
|
+
```yaml
|
85
|
+
input: base-template.yml
|
86
|
+
|
87
|
+
output:
|
88
|
+
outfile1.yml:
|
89
|
+
argument1: value
|
90
|
+
argument2: value
|
91
|
+
|
92
|
+
outfile2.yml:
|
93
|
+
argument1: value
|
94
|
+
argument2: value
|
95
|
+
```
|
96
|
+
|
97
|
+
|
98
|
+
### Compile an Entire Folder
|
99
|
+
|
100
|
+
![kojo](images/features-compile.svg)
|
101
|
+
|
102
|
+
Process a folder containing templates and `@imports`, and generate a mirror
|
103
|
+
output folder, with all the variables and `@imports` evaluated.
|
data/bin/kojo-compile.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'kojo'
|
2
|
+
|
3
|
+
help "Compile a folder of templates to a similar output folder"
|
4
|
+
|
5
|
+
usage "kojo compile INDIR [--save DIR --import DIR] [ARGS...]"
|
6
|
+
usage "kojo compile (-h|--help)"
|
7
|
+
|
8
|
+
option "-s --save DIR", "Save output to directory instead of printing"
|
9
|
+
option "-i --import DIR", "Specify base directory for @import directives"
|
10
|
+
|
11
|
+
param "ARGS", "Optional key=value pairs"
|
12
|
+
|
13
|
+
example "kojo compile indir"
|
14
|
+
example "kojo compile in --save out env=production"
|
15
|
+
example "kojo compile in --save out --import snippets env=production"
|
16
|
+
|
17
|
+
action do |args|
|
18
|
+
opts = args['ARGS'].args_to_hash
|
19
|
+
indir = args['INDIR']
|
20
|
+
outdir = args['--save']
|
21
|
+
import_base = args['--import']
|
22
|
+
|
23
|
+
files = Dir["#{indir}/**/*"].reject { |file| File.directory? file }
|
24
|
+
|
25
|
+
files.each do |file|
|
26
|
+
template = Kojo::Template.new(file, opts)
|
27
|
+
template.import_base = import_base if import_base
|
28
|
+
output = template.render
|
29
|
+
|
30
|
+
if outdir
|
31
|
+
outpath = file.sub(/#{indir}/, outdir)
|
32
|
+
|
33
|
+
dir = File.dirname outpath
|
34
|
+
FileUtils.mkdir_p dir unless Dir.exist? dir
|
35
|
+
|
36
|
+
File.write outpath, output
|
37
|
+
say "Saved #{outpath}"
|
38
|
+
else
|
39
|
+
outpath = file.sub(/#{indir}/, '')
|
40
|
+
say "\n!txtgrn!# #{outpath}"
|
41
|
+
say output
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
data/bin/kojo-run.rb
CHANGED
@@ -18,18 +18,19 @@ action do |args|
|
|
18
18
|
gen = Kojo::Generator.new args['CONFIG']
|
19
19
|
outdir = args['--save']
|
20
20
|
|
21
|
-
if outdir
|
22
|
-
FileUtils.mkdir_p outdir
|
21
|
+
if outdir and !Dir.exist? outdir
|
22
|
+
FileUtils.mkdir_p outdir
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
25
|
+
gen.generate do |file, output|
|
26
|
+
path = "#{outdir}/#{file}"
|
27
|
+
if outdir
|
26
28
|
File.write path, output
|
27
29
|
say "Saved #{path}"
|
30
|
+
else
|
31
|
+
say "\n!txtgrn!# #{file}"
|
32
|
+
say output
|
28
33
|
end
|
29
|
-
|
30
|
-
else
|
31
|
-
puts gen.generate
|
32
|
-
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
data/lib/kojo/generator.rb
CHANGED
@@ -12,18 +12,10 @@ module Kojo
|
|
12
12
|
base_dir = File.dirname config_file
|
13
13
|
infile = "#{base_dir}/#{config['input']}"
|
14
14
|
|
15
|
-
result = []
|
16
|
-
|
17
15
|
config['output'].each do |outfile, opts|
|
18
16
|
output = render infile, opts.symbolize_keys
|
19
|
-
|
20
|
-
yield outfile, output
|
21
|
-
else
|
22
|
-
result << "\n# #{outfile}\n#{output}"
|
23
|
-
end
|
17
|
+
yield outfile, output
|
24
18
|
end
|
25
|
-
|
26
|
-
result.empty? ? nil : result.join("\n")
|
27
19
|
end
|
28
20
|
|
29
21
|
private
|
data/lib/kojo/template.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
module Kojo
|
2
2
|
class Template
|
3
3
|
attr_reader :file, :extension, :args, :dir
|
4
|
+
attr_accessor :import_base
|
4
5
|
|
5
6
|
def initialize(file, args={})
|
6
7
|
@file = file
|
7
8
|
@args = args
|
8
9
|
@extension = file[/(\..*)$/]
|
9
10
|
@dir = File.dirname file
|
11
|
+
@import_base = dir
|
10
12
|
end
|
11
13
|
|
12
14
|
def render
|
@@ -15,8 +17,10 @@ module Kojo
|
|
15
17
|
|
16
18
|
private
|
17
19
|
|
18
|
-
def import(file,
|
19
|
-
|
20
|
+
def import(file, import_args={})
|
21
|
+
filename = File.expand_path "#{file}#{extension}", import_base
|
22
|
+
all_args = args.merge import_args
|
23
|
+
self.class.new(filename, all_args).render
|
20
24
|
end
|
21
25
|
|
22
26
|
def evaluate(file, args={})
|
data/lib/kojo/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.1
|
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: 2018-08-
|
11
|
+
date: 2018-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mister_bin
|
@@ -108,10 +108,12 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0.15'
|
111
|
-
description:
|
111
|
+
description: Generate configuration files from templates, using variables and definition
|
112
|
+
files.
|
112
113
|
email: db@dannyben.com
|
113
114
|
executables:
|
114
115
|
- kojo
|
116
|
+
- kojo-compile.rb
|
115
117
|
- kojo-generate.rb
|
116
118
|
- kojo-run.rb
|
117
119
|
extensions: []
|
@@ -119,6 +121,7 @@ extra_rdoc_files: []
|
|
119
121
|
files:
|
120
122
|
- README.md
|
121
123
|
- bin/kojo
|
124
|
+
- bin/kojo-compile.rb
|
122
125
|
- bin/kojo-generate.rb
|
123
126
|
- bin/kojo-run.rb
|
124
127
|
- lib/kojo.rb
|
@@ -139,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
139
142
|
requirements:
|
140
143
|
- - ">="
|
141
144
|
- !ruby/object:Gem::Version
|
142
|
-
version: 2.
|
145
|
+
version: 2.5.0
|
143
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
147
|
requirements:
|
145
148
|
- - ">="
|
@@ -150,5 +153,5 @@ rubyforge_project:
|
|
150
153
|
rubygems_version: 2.7.6
|
151
154
|
signing_key:
|
152
155
|
specification_version: 4
|
153
|
-
summary: Configuration
|
156
|
+
summary: Configuration Ninja
|
154
157
|
test_files: []
|