kojo 0.3.8 → 0.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31deffc66dbb1ff100bb90f669f8d2995f8eeac92c78919434caffbb9ecfee69
4
- data.tar.gz: 6c4b75d7e13b627520d403d8885333a9c30b06cd40c56889e2cd4823ac125b12
3
+ metadata.gz: fa6bcd67142ce2bbde7f22e49d2884dd258046db5a786c4591ca9657cb697ab9
4
+ data.tar.gz: a72337674e2a3d8892f63f3705d87cf91723f93ade219ce87f5a8d1331ece91a
5
5
  SHA512:
6
- metadata.gz: b6731a253afc7c3ccdb8f718e4a78d70d6bfcea9079c269f0b9ca1d8da3596abcbfd5b895fa2e32bbc2b14629c4b5a022cd7996fb3428a6260cb5b5b64b97aa8
7
- data.tar.gz: 0c285f0dcaeff09fb183fe2f02e8f25a9905b4431bca7908dfc0824bfd5caba74d215476e661b519733c790b2b79ea599c9d325f03bdab7c847f98761c815ffc
6
+ metadata.gz: 6e302b53329de878ca3a177f98a8e43d0f12b8b9be88093c2638515c0e514b6e60512a4e217a0896fbc29edaf15fc2f3bd45a05d992efa7e2dbc43f8d46c5475
7
+ data.tar.gz: ec8504461e7bb58bbd1782dcaa1113fc2fb49729463794995e10b7d67e36e2c475946acc0a34e5663726954c592a340a81a8bbb047f80465b4829d4b9db6baae
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.
@@ -84,11 +89,19 @@ resulting configuration file.
84
89
  @import filename (arg: "value", arg2: "value")
85
90
  ```
86
91
 
87
- The space after `filename` is optional.
92
+ The space after `filename` is optional, and the arguments list can be split to
93
+ multiple lines:
94
+
95
+ ```ruby
96
+ @import filename (
97
+ arg: "value",
98
+ arg2: "value"
99
+ )
100
+ ```
88
101
 
89
102
  ### Transform an Entire Folder
90
103
 
91
- ![kojo](images/features-dir.svg)
104
+ ![kojo](support/features-dir.svg)
92
105
 
93
106
  Process a folder containing templates and `@imports`, and generate a mirror
94
107
  output folder, with all the variables and `@imports` evaluated.
@@ -97,7 +110,7 @@ You may use `%{variables}` in filenames.
97
110
 
98
111
  ### Transform One to Many using Config
99
112
 
100
- ![kojo](images/features-config.svg)
113
+ ![kojo](support/features-config.svg)
101
114
 
102
115
  Using the `kojo config` command together with a simple definitions file, you
103
116
  can:
@@ -142,7 +155,7 @@ output:
142
155
 
143
156
  ### Transform One to Many using Front Matter
144
157
 
145
- ![kojo](images/features-single.svg)
158
+ ![kojo](support/features-single.svg)
146
159
 
147
160
  Define a template that contains the instructions on how to transform it as a
148
161
  YAML front matter.
@@ -150,7 +163,7 @@ YAML front matter.
150
163
  The YAML front matter should be structured like this:
151
164
 
152
165
  ```yaml
153
- filename2:
166
+ filename1:
154
167
  arg: value
155
168
  another_arg: value
156
169
 
@@ -165,9 +178,22 @@ Your template that uses %{arg} goes here
165
178
  Additional arguments provided to the command line, will also be transferred
166
179
  to the template.
167
180
 
181
+ ### Convert YAML to JSON
182
+
183
+ ![kojo](support/features-tojson.svg)
184
+
185
+ Convert one or more YAML files to JSON.
186
+
187
+ This can be useful when you require JSON files as output, but wish to edit
188
+ (or generate using Kojo) using the less error-prone and more aesthetically
189
+ pleasing YAML format.
190
+
191
+ Note that this Kojo command does not provide any additional preprocessing - the
192
+ input files should be valid YAML.
193
+
168
194
  ### Interactive Form Templates
169
195
 
170
- ![kojo](images/features-form.svg)
196
+ ![kojo](support/features-form.svg)
171
197
 
172
198
  Using the `kojo form` command lets you define an ERB or [ERBX][erbx] template, and include interactive prompts to enter the input.
173
199
 
@@ -177,11 +203,11 @@ Using the `kojo form` command lets you define an ERB or [ERBX][erbx] template, a
177
203
  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
204
  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
205
 
180
- ![kojo](images/features-form-inline.svg)
206
+ ![kojo](support/features-form-inline.svg)
181
207
 
182
208
  ### Conditions and Loops with ERB
183
209
 
184
- ![kojo](images/features-erb.svg)
210
+ ![kojo](support/features-erb.svg)
185
211
 
186
212
  Template files are evaluated using ERB, so you can use any Ruby code for more
187
213
  advanced templates (for conditions, loops etc.).
@@ -197,7 +223,7 @@ Use this syntax for ruby code:
197
223
  When Kojo encounters a variable that was not supplied (either through the command
198
224
  line or through a configuration file), it will prompt for a value.
199
225
 
200
- ![kojo](images/interactive-mode.gif)
226
+ ![kojo](support/interactive-mode.gif)
201
227
 
202
228
  You can enable or disable interactive mode by setting the environment
203
229
  variable `KOJO_INTERACTIVE` to `yes` or `no`.
@@ -0,0 +1,9 @@
1
+ require 'yaml'
2
+
3
+ module YAML
4
+ # Make YAML.load behave the same in all Ruby versions
5
+ # ref: https://bugs.ruby-lang.org/issues/17866
6
+ class << self
7
+ alias_method :load, :unsafe_load if YAML.respond_to? :unsafe_load
8
+ end
9
+ end
@@ -46,6 +46,12 @@ module Kojo
46
46
  raise Kojo::TemplateError, "#{e.message}\nin: #{filename}"
47
47
  end
48
48
 
49
+ def compress_imports
50
+ gsub /^ *@import +[^(\s]+\s*\([\S\s]*?\) *$/ do |match|
51
+ match.gsub /\r?\n\s*/, " "
52
+ end
53
+ end
54
+
49
55
  private
50
56
 
51
57
  def get_user_input
@@ -57,7 +63,7 @@ module Kojo
57
63
  end
58
64
 
59
65
  def erb(template, vars)
60
- ERB.new(template, nil, '-').result(OpenStruct.new(vars).instance_eval { binding })
66
+ ERB.new(template, trim_mode: '-').result(OpenStruct.new(vars).instance_eval { binding })
61
67
  end
62
68
 
63
69
  end
data/lib/kojo/template.rb CHANGED
@@ -38,8 +38,8 @@ module Kojo
38
38
 
39
39
  def eval_imports(content)
40
40
  result = []
41
-
42
- content.lines.each do |line|
41
+
42
+ content.compress_imports.lines.each do |line|
43
43
  line.chomp!
44
44
  spaces = line[/^\s*/].size
45
45
 
@@ -64,7 +64,7 @@ module Kojo
64
64
  end
65
65
 
66
66
  def indent(text, spaces)
67
- text.lines.collect { |line| "#{' ' * spaces}#{line}" }.join
67
+ text.lines.collect { |line| "#{' ' * spaces}#{line}" }.join.gsub(/^\s*$/, '')
68
68
  end
69
69
 
70
70
  end
data/lib/kojo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kojo
2
- VERSION = "0.3.8"
2
+ VERSION = "0.4.1"
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.4.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: 2020-10-30 00:00:00.000000000 Z
11
+ date: 2022-03-12 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.3.3
133
134
  signing_key:
134
135
  specification_version: 4
135
136
  summary: Configuration Ninja