kojo 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31deffc66dbb1ff100bb90f669f8d2995f8eeac92c78919434caffbb9ecfee69
4
- data.tar.gz: 6c4b75d7e13b627520d403d8885333a9c30b06cd40c56889e2cd4823ac125b12
3
+ metadata.gz: 1952c33f6d6360f1a027ee30eefcfea5636a062c2c28c02d83916d99e51ed7c1
4
+ data.tar.gz: 9554ea0de969c79e11d40b237d4ffb24c3bceead6dc863511124af6b4753841b
5
5
  SHA512:
6
- metadata.gz: b6731a253afc7c3ccdb8f718e4a78d70d6bfcea9079c269f0b9ca1d8da3596abcbfd5b895fa2e32bbc2b14629c4b5a022cd7996fb3428a6260cb5b5b64b97aa8
7
- data.tar.gz: 0c285f0dcaeff09fb183fe2f02e8f25a9905b4431bca7908dfc0824bfd5caba74d215476e661b519733c790b2b79ea599c9d325f03bdab7c847f98761c815ffc
6
+ metadata.gz: 40bdbcfa32871516c1776923dffd3d78b0757463941da85708b4292e9a84f5c8308dd655e1707493e6da9411771a12c18a57d7098ae0d85cc1c537bf41d3fcb7
7
+ data.tar.gz: 76d43feccd9c0210bd3239f86b089a27527fdbd293daaf771dcb3d8170dd5d57a864e2a7fc399a00b6989d963659eb1e7ea9a7b8e7f23561a288a27e7187d941
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  <div align='center'>
2
2
 
3
- ![kojo](images/kojo.png)
3
+ ![kojo](support/kojo.png)
4
4
 
5
5
  # Kojo Configuration Ninja
6
6
 
@@ -26,6 +26,7 @@ format.
26
26
  - [Transform an Entire Folder](#transform-an-entire-folder)
27
27
  - [Transform One to Many using Config](#transform-one-to-many-using-config)
28
28
  - [Transform One to Many using Front Matter](#transform-one-to-many-using-front-matter)
29
+ - [Convert YAML to JSON](#convert-yaml-to-json)
29
30
  - [Interactive Form Templates](#interactive-form-templates)
30
31
  - [Conditions and Loops with ERB](#conditions-and-loops-with-erb)
31
32
  - [Interactive Fallback](#interactive-fallback)
@@ -54,7 +55,7 @@ relevant files, and the expected output.
54
55
 
55
56
  ### Variables
56
57
 
57
- ![kojo](images/features-vars.svg)
58
+ ![kojo](support/features-vars.svg)
58
59
 
59
60
  Include variables in your configuration templates by using this syntax:
60
61
  `%{varname}`
@@ -65,9 +66,13 @@ Include variables in your configuration templates by using this syntax:
65
66
  - Variables from the top level will be forwarded downstream, and aggregated
66
67
  with any additional variables that are defined in subsequent `@imports`.
67
68
 
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.
72
+
68
73
  ### Import
69
74
 
70
- ![kojo](images/features-import.svg)
75
+ ![kojo](support/features-import.svg)
71
76
 
72
77
  Use the `@import filename` directive anywhere to include another file in the
73
78
  resulting configuration file.
@@ -88,7 +93,7 @@ The space after `filename` is optional.
88
93
 
89
94
  ### Transform an Entire Folder
90
95
 
91
- ![kojo](images/features-dir.svg)
96
+ ![kojo](support/features-dir.svg)
92
97
 
93
98
  Process a folder containing templates and `@imports`, and generate a mirror
94
99
  output folder, with all the variables and `@imports` evaluated.
@@ -97,7 +102,7 @@ You may use `%{variables}` in filenames.
97
102
 
98
103
  ### Transform One to Many using Config
99
104
 
100
- ![kojo](images/features-config.svg)
105
+ ![kojo](support/features-config.svg)
101
106
 
102
107
  Using the `kojo config` command together with a simple definitions file, you
103
108
  can:
@@ -142,7 +147,7 @@ output:
142
147
 
143
148
  ### Transform One to Many using Front Matter
144
149
 
145
- ![kojo](images/features-single.svg)
150
+ ![kojo](support/features-single.svg)
146
151
 
147
152
  Define a template that contains the instructions on how to transform it as a
148
153
  YAML front matter.
@@ -150,7 +155,7 @@ YAML front matter.
150
155
  The YAML front matter should be structured like this:
151
156
 
152
157
  ```yaml
153
- filename2:
158
+ filename1:
154
159
  arg: value
155
160
  another_arg: value
156
161
 
@@ -165,9 +170,22 @@ Your template that uses %{arg} goes here
165
170
  Additional arguments provided to the command line, will also be transferred
166
171
  to the template.
167
172
 
173
+ ### Convert YAML to JSON
174
+
175
+ ![kojo](support/features-tojson.svg)
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
+
168
186
  ### Interactive Form Templates
169
187
 
170
- ![kojo](images/features-form.svg)
188
+ ![kojo](support/features-form.svg)
171
189
 
172
190
  Using the `kojo form` command lets you define an ERB or [ERBX][erbx] template, and include interactive prompts to enter the input.
173
191
 
@@ -177,11 +195,11 @@ Using the `kojo form` command lets you define an ERB or [ERBX][erbx] template, a
177
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.
178
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.
179
197
 
180
- ![kojo](images/features-form-inline.svg)
198
+ ![kojo](support/features-form-inline.svg)
181
199
 
182
200
  ### Conditions and Loops with ERB
183
201
 
184
- ![kojo](images/features-erb.svg)
202
+ ![kojo](support/features-erb.svg)
185
203
 
186
204
  Template files are evaluated using ERB, so you can use any Ruby code for more
187
205
  advanced templates (for conditions, loops etc.).
@@ -197,7 +215,7 @@ Use this syntax for ruby code:
197
215
  When Kojo encounters a variable that was not supplied (either through the command
198
216
  line or through a configuration file), it will prompt for a value.
199
217
 
200
- ![kojo](images/interactive-mode.gif)
218
+ ![kojo](support/interactive-mode.gif)
201
219
 
202
220
  You can enable or disable interactive mode by setting the environment
203
221
  variable `KOJO_INTERACTIVE` to `yes` or `no`.
@@ -33,7 +33,7 @@ module Kojo::Commands
33
33
  argfile = args['--args']
34
34
 
35
35
  if argfile
36
- fileopts = YAML.load_file(argfile).symbolize_keys
36
+ fileopts = YAML.properly_load_file(argfile).symbolize_keys
37
37
  @opts = fileopts.merge opts
38
38
  end
39
39
 
@@ -33,7 +33,7 @@ module Kojo
33
33
  argfile = args['--args']
34
34
 
35
35
  if argfile
36
- fileopts = YAML.load_file(argfile).symbolize_keys
36
+ fileopts = YAML.properly_load_file(argfile).symbolize_keys
37
37
  @opts = fileopts.merge @opts
38
38
  end
39
39
 
@@ -33,7 +33,7 @@ module Kojo
33
33
  argfile = args['--args']
34
34
 
35
35
  if argfile
36
- fileopts = YAML.load_file(argfile).symbolize_keys
36
+ fileopts = YAML.properly_load_file(argfile).symbolize_keys
37
37
  @opts = fileopts.merge opts
38
38
  end
39
39
 
@@ -35,7 +35,7 @@ module Kojo
35
35
  private
36
36
 
37
37
  def tojson(path)
38
- JSON.pretty_generate YAML.load_file(path)
38
+ JSON.pretty_generate YAML.properly_load_file(path)
39
39
  end
40
40
 
41
41
  # Glob patterns are usually handled by the shell, but in case
data/lib/kojo/config.rb CHANGED
@@ -59,7 +59,7 @@ module Kojo
59
59
  end
60
60
 
61
61
  def config
62
- @config ||= YAML.load_file config_file
62
+ @config ||= YAML.properly_load_file config_file
63
63
  end
64
64
  end
65
65
 
@@ -0,0 +1,10 @@
1
+ require 'yaml'
2
+
3
+ module YAML
4
+ # ref: https://bugs.ruby-lang.org/issues/17866
5
+ def self.properly_load_file(path)
6
+ YAML.load_file path, aliases: true
7
+ rescue ArgumentError
8
+ YAML.load_file path
9
+ end
10
+ end
@@ -32,7 +32,7 @@ module Kojo
32
32
  def read_file(file)
33
33
  raise Kojo::NotFoundError, "File not found: #{file}" unless File.exist? file
34
34
 
35
- config = YAML.load_file file
35
+ config = YAML.properly_load_file file
36
36
  content = File.read(file)[/^---\s*$\n(.*)/m, 1]
37
37
 
38
38
  [config, content]
@@ -57,7 +57,7 @@ module Kojo
57
57
  end
58
58
 
59
59
  def erb(template, vars)
60
- ERB.new(template, nil, '-').result(OpenStruct.new(vars).instance_eval { binding })
60
+ ERB.new(template, trim_mode: '-').result(OpenStruct.new(vars).instance_eval { binding })
61
61
  end
62
62
 
63
63
  end
data/lib/kojo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kojo
2
- VERSION = "0.3.8"
2
+ VERSION = "0.3.9"
3
3
  end
data/lib/kojo.rb CHANGED
@@ -4,8 +4,8 @@ require 'byebug' if ENV['BYEBUG']
4
4
  require 'yaml'
5
5
  require 'json'
6
6
 
7
- requires 'kojo/refinements'
8
7
  requires 'kojo/extensions'
8
+ requires 'kojo/refinements'
9
9
 
10
10
  require 'kojo/exceptions'
11
11
  require 'kojo/template'
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.8
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: 2020-10-30 00:00:00.000000000 Z
11
+ date: 2022-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mister_bin
@@ -103,6 +103,7 @@ files:
103
103
  - lib/kojo/config.rb
104
104
  - lib/kojo/exceptions.rb
105
105
  - lib/kojo/extensions/file.rb
106
+ - lib/kojo/extensions/yaml.rb
106
107
  - lib/kojo/form.rb
107
108
  - lib/kojo/front_matter_template.rb
108
109
  - lib/kojo/refinements/array.rb
@@ -122,14 +123,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
123
  requirements:
123
124
  - - ">="
124
125
  - !ruby/object:Gem::Version
125
- version: 2.5.0
126
+ version: 2.6.0
126
127
  required_rubygems_version: !ruby/object:Gem::Requirement
127
128
  requirements:
128
129
  - - ">="
129
130
  - !ruby/object:Gem::Version
130
131
  version: '0'
131
132
  requirements: []
132
- rubygems_version: 3.1.4
133
+ rubygems_version: 3.2.15
133
134
  signing_key:
134
135
  specification_version: 4
135
136
  summary: Configuration Ninja