rndr 0.0.3 → 0.0.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/.rubocop.yml +3 -0
- data/CHANGELOG +6 -1
- data/README.md +15 -10
- data/Rakefile +9 -2
- data/lib/rndr/cli.rb +18 -6
- data/lib/rndr/util.rb +43 -15
- data/rndr.gemspec +7 -6
- data/spec/cli_spec.rb +90 -47
- data/{test/.rndrignore → spec/resources/rndrignore} +0 -0
- data/spec/resources/{rendered_merged.txt → spec_merged.txt} +0 -0
- data/spec/resources/spec_opts.txt +15 -0
- data/spec/resources/{rendered_replaced.txt → spec_replaced.txt} +0 -0
- data/{test → spec/resources}/templates/exttest.txt.tmplt +0 -0
- data/{test → spec/resources}/templates/failtest.txt.erb +0 -0
- data/{test/templates/ignoretest.txt.erb → spec/resources/templates/ignoretest.txt} +0 -0
- data/spec/resources/templates/ignoretest.txt.erb +0 -0
- data/{test → spec/resources}/templates/rendertest.txt.erb +0 -0
- data/{test → spec/resources}/vars/a.json +0 -0
- data/{test → spec/resources}/vars/b.yaml +0 -0
- data/spec/resources/vars_opts_bool.txt +16 -0
- data/spec/resources/vars_opts_string.txt +18 -0
- data/spec/spec_helper.rb +0 -1
- data/spec/template_spec.rb +4 -4
- data/spec/util_spec.rb +9 -11
- data/version.txt +1 -1
- metadata +53 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8466c3c45a0ee825f49d621e584d4a12ac6a965b
|
4
|
+
data.tar.gz: 4ecee6dcb0d4bdbd1c027413abb1ea38f602d692
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4cebd0a275001d39c721de703a64b65067cdfcdecbaa078a00550e2c9c3e1bd414ce4e10488b1ff4f2a2fd035667613135783878d810c7c5a82d6f7c2fe5964
|
7
|
+
data.tar.gz: 91c0211d83f6edc8c7051f841ae1c7f029ce58a0ac3867c174cc58c6d79a2cde78d5b9656ae64b324e2d587468ccf65cf4788978560153cf7acee6cfdfaae5ad
|
data/.rubocop.yml
CHANGED
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -4,6 +4,8 @@
|
|
4
4
|
|
5
5
|
Rndr is a small Ruby cli gem that provides a method of rendering discovered erb templates. Variables for use in template rendering can be used directly by providing a either a `yaml` or `json` file, or alternatively a directory may be supplied along with the variable merging strategy. Rndr supports both standard hash merges or recursive (default).
|
6
6
|
|
7
|
+
In addition to supporting recursive hash merges, additional hash control options may be passed via the `--merge-opts` hash directive. This supports the available options as supported by the [deep_merge](https://github.com/danielsdeleo/deep_merge) gem.
|
8
|
+
|
7
9
|
Paths can be ignored by either creating a `.rndrignore` file within the current working directly, or supplying a path to a desired ignore file.
|
8
10
|
|
9
11
|
|
@@ -35,16 +37,17 @@ Usage:
|
|
35
37
|
rndr check
|
36
38
|
|
37
39
|
Options:
|
38
|
-
e, [--extension=EXTENSION]
|
39
|
-
|
40
|
-
i, [--ignore=IGNORE]
|
41
|
-
|
42
|
-
m, [--merge], [--no-merge]
|
43
|
-
|
44
|
-
t, [--template=TEMPLATE]
|
45
|
-
|
46
|
-
V, [--vars=VARS]
|
47
|
-
|
40
|
+
e, [--extension=EXTENSION] # Extension of templates.
|
41
|
+
# Default: erb
|
42
|
+
i, [--ignore=IGNORE] # Path to file containing list of files to be ignored.
|
43
|
+
# Default: /Users/demo/ruby/rndr/.rndrignore
|
44
|
+
m, [--merge], [--no-merge] # Recursively merge variables instead of replacing.
|
45
|
+
# Default: true
|
46
|
+
t, [--template=TEMPLATE] # Path to erb template or directory.
|
47
|
+
# Default: /Users/demo/ruby/rndr
|
48
|
+
V, [--vars=VARS] # Path to var file or directory.
|
49
|
+
# Default: /Users/demo/ruby/rndr/vars
|
50
|
+
o, [--merge-opts=key:value] # Hash of options to pass to deep_merge function
|
48
51
|
|
49
52
|
Verifies discovered erb templates.
|
50
53
|
```
|
@@ -85,6 +88,7 @@ Options:
|
|
85
88
|
# Default: /Users/demo/ruby/rndr/rndr
|
86
89
|
V, [--vars=VARS] # Path to var file or directory.
|
87
90
|
# Default: /Users/demo/ruby/rndr/vars
|
91
|
+
o, [--merge-opts=key:value] # Hash of options to pass to deep_merge function
|
88
92
|
|
89
93
|
Renders discovered templates.
|
90
94
|
```
|
@@ -103,6 +107,7 @@ Options:
|
|
103
107
|
# Default: true
|
104
108
|
V, [--vars=VARS] # Path to var file or directory.
|
105
109
|
# Default: /Users/demo/ruby/rndr/vars
|
110
|
+
o, [--merge-opts=key:value] # Hash of options to pass to deep_merge function
|
106
111
|
|
107
112
|
Lists Combined Variables.
|
108
113
|
```
|
data/Rakefile
CHANGED
@@ -1,9 +1,16 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
require 'bundler/gem_tasks'
|
2
5
|
require 'coveralls/rake/task'
|
3
6
|
require 'rspec/core/rake_task'
|
7
|
+
require 'rubocop/rake_task'
|
4
8
|
|
5
9
|
RSpec::Core::RakeTask.new(:spec)
|
6
10
|
Coveralls::RakeTask.new
|
7
11
|
|
8
|
-
task :
|
9
|
-
task :
|
12
|
+
task default: :spec
|
13
|
+
task coveralls: [:spec, :features, 'coveralls:push']
|
14
|
+
RuboCop::RakeTask.new(:style) do |task|
|
15
|
+
task.options << '--display-cop-names'
|
16
|
+
end
|
data/lib/rndr/cli.rb
CHANGED
@@ -22,10 +22,14 @@ module Rndr
|
|
22
22
|
method_option :vars,
|
23
23
|
aliases: :V, type: :string, default: File.join(Dir.pwd, 'vars'),
|
24
24
|
desc: 'Path to var file or directory.'
|
25
|
+
method_option :merge_opts,
|
26
|
+
aliases: :o, type: :hash, default: {},
|
27
|
+
desc: 'Hash of options to pass to deep_merge function'
|
25
28
|
def check
|
26
29
|
results = Rndr.matches(path: options[:template], ext: options[:extension],
|
27
30
|
ignore_path: options[:ignore])
|
28
|
-
template_vars = Rndr.read_vars(path: options[:vars], merge: options[:merge]
|
31
|
+
template_vars = Rndr.read_vars(path: options[:vars], merge: options[:merge],
|
32
|
+
merge_opts: options[:merge_opts])
|
29
33
|
results.each do |path|
|
30
34
|
template = Template.new(path: path, vars: template_vars)
|
31
35
|
print_check_result(path: path, result: template.render?)
|
@@ -44,7 +48,7 @@ module Rndr
|
|
44
48
|
desc: 'Path to erb template or directory.'
|
45
49
|
def list
|
46
50
|
results = Rndr.matches(path: options[:template], ext: options[:extension],
|
47
|
-
ignore_path:
|
51
|
+
ignore_path: options[:ignore])
|
48
52
|
if results.empty?
|
49
53
|
puts 'No matching results.'
|
50
54
|
else
|
@@ -68,10 +72,14 @@ module Rndr
|
|
68
72
|
method_option :vars,
|
69
73
|
aliases: :V, type: :string, default: File.join(Dir.pwd, 'vars'),
|
70
74
|
desc: 'Path to var file or directory.'
|
71
|
-
|
75
|
+
method_option :merge_opts,
|
76
|
+
aliases: :o, type: :hash, default: {},
|
77
|
+
desc: 'Hash of options to pass to deep_merge function'
|
78
|
+
def render # rubocop:disable Metrics/AbcSize
|
72
79
|
results = Rndr.matches(path: options[:template], ext: options[:extension],
|
73
|
-
ignore_path:
|
74
|
-
template_vars = Rndr.read_vars(path: options[:vars], merge: options[:merge]
|
80
|
+
ignore_path: options[:ignore])
|
81
|
+
template_vars = Rndr.read_vars(path: options[:vars], merge: options[:merge],
|
82
|
+
merge_opts: options[:merge_opts])
|
75
83
|
results.each do |path|
|
76
84
|
template = Template.new(path: path, vars: template_vars)
|
77
85
|
render_path = path.gsub(/.#{options[:extension]}$/, '')
|
@@ -90,8 +98,12 @@ module Rndr
|
|
90
98
|
method_option :vars,
|
91
99
|
aliases: :V, type: :string, default: File.join(Dir.pwd, 'vars'),
|
92
100
|
desc: 'Path to var file or directory.'
|
101
|
+
method_option :merge_opts,
|
102
|
+
aliases: :o, type: :hash, default: {},
|
103
|
+
desc: 'Hash of options to pass to deep_merge function'
|
93
104
|
def vars
|
94
|
-
result = Rndr.read_vars(path: options[:vars], merge: options[:merge]
|
105
|
+
result = Rndr.read_vars(path: options[:vars], merge: options[:merge],
|
106
|
+
merge_opts: options[:merge_opts])
|
95
107
|
case options[:format].downcase
|
96
108
|
when 'json'
|
97
109
|
puts result.to_json
|
data/lib/rndr/util.rb
CHANGED
@@ -15,11 +15,9 @@ module Rndr
|
|
15
15
|
def self.matches(path:, ext: 'erb', ignore_path: File.join(Dir.pwd, '.rndrignore'))
|
16
16
|
matched_paths = match_files(path: File.absolute_path(path), ext: ext)
|
17
17
|
ignore_file_path = File.absolute_path(ignore_path)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
return matched_paths
|
22
|
-
end
|
18
|
+
return filter_ignored_paths(path_list: matched_paths, ignore_path: ignore_file_path) if
|
19
|
+
!matched_paths.empty? && File.exist?(ignore_file_path)
|
20
|
+
matched_paths
|
23
21
|
end
|
24
22
|
|
25
23
|
# Accepts a file or directory and will attempt to parse the discovered file(s) as either json
|
@@ -27,12 +25,14 @@ module Rndr
|
|
27
25
|
# template rendering in {Template#render}.
|
28
26
|
# @param path [String] The path to the vars file or directory. Will process both json and yaml.
|
29
27
|
# @param merge [Boolean] True to enable recursive merge of hashes.
|
28
|
+
# @param merge_opts [Hash] A hash of options to be passed to the deep_merge method
|
30
29
|
# @return [Hash] A hash containing the processed variables. Will be used to send to the binding
|
31
30
|
# of a rendered template. See {Template#render} for more information.
|
32
|
-
def self.read_vars(path:, merge: true)
|
31
|
+
def self.read_vars(path:, merge: true, merge_opts: {})
|
33
32
|
vars_path = File.absolute_path(path)
|
34
33
|
return read_vars_file(vars_path) if File.file?(vars_path)
|
35
|
-
return read_vars_dir(path: vars_path, merge: merge) if
|
34
|
+
return read_vars_dir(path: vars_path, merge: merge, merge_opts: merge_opts) if
|
35
|
+
File.directory?(vars_path)
|
36
36
|
{}
|
37
37
|
end
|
38
38
|
|
@@ -87,7 +87,7 @@ module Rndr
|
|
87
87
|
# @return [Hash, nil] Hash of processed data read from var passed var file.
|
88
88
|
def read_vars_file(path)
|
89
89
|
data = File.read(path)
|
90
|
-
return JSON.
|
90
|
+
return JSON.parse(data) if json?(data)
|
91
91
|
return YAML.load(data) if yaml?(data)
|
92
92
|
nil
|
93
93
|
end
|
@@ -97,15 +97,16 @@ module Rndr
|
|
97
97
|
# @param path [String] Path to directory containing files to be ingested and vars
|
98
98
|
# processed.
|
99
99
|
# @param merge [Boolean] True if variables from files should be recursively merged.
|
100
|
+
# @param merge_opts [Hash] A hash of options to be passed to the deep_merge method
|
100
101
|
# @return [Hash] Hash of processed variables read from files within the passed.
|
101
|
-
def read_vars_dir(path:, merge:)
|
102
|
+
def read_vars_dir(path:, merge:, merge_opts: {})
|
102
103
|
processed_vars = {}
|
103
104
|
Dir[File.join(path, '*')].each do |file|
|
104
105
|
file_vars = read_vars_file(file)
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
106
|
+
next if file_vars.nil?
|
107
|
+
processed_vars =
|
108
|
+
merge_vars(base_hash: processed_vars, hash: file_vars, merge: merge,
|
109
|
+
merge_opts: merge_opts)
|
109
110
|
end
|
110
111
|
processed_vars
|
111
112
|
end
|
@@ -130,15 +131,42 @@ module Rndr
|
|
130
131
|
false
|
131
132
|
end
|
132
133
|
|
134
|
+
# to_bool converts the passed string to its associated bool value
|
135
|
+
# @param value [String] String to be converted to bool value
|
136
|
+
# @return [Boolean] True, False, or nil depending on input.
|
137
|
+
def to_bool(value)
|
138
|
+
return true if value.casecmp('true')
|
139
|
+
return false if value.casecmp('false')
|
140
|
+
nil
|
141
|
+
end
|
142
|
+
|
143
|
+
# deep_merge_opts converts the passed hash to the format that the deep_merge
|
144
|
+
# function accepts.
|
145
|
+
# @param hash [Hash] The options hash to be converted
|
146
|
+
# @return [Hash] A converted options hash to be passed to the deep_merge method
|
147
|
+
def deep_merge_opts(hash)
|
148
|
+
opts = {}
|
149
|
+
bool_vars = %w(extend_existing_arrays keep_array_duplicates merge_debug merge_hash_arrays
|
150
|
+
overwrite_arrays preserve_unmergeables sort_merged_arrays)
|
151
|
+
string_vars = %w(knockout_prefix unpack_arrays)
|
152
|
+
hash.each do |k, v|
|
153
|
+
opts[k.to_sym] = v if string_vars.include?(k)
|
154
|
+
opts[k.to_sym] = to_bool(v) if bool_vars.include?(k)
|
155
|
+
end
|
156
|
+
opts
|
157
|
+
end
|
158
|
+
|
133
159
|
# merge_vars handles merging hashes, either with a recursive merge (default) or with
|
134
160
|
# a standard merge, which has a 'replace' effect.
|
135
161
|
# @param base_hash [Hash] Original Hash to have values merged into.
|
136
162
|
# @param hash [Hash] Secondary hash to be merged into base hash.
|
137
163
|
# @param merge [Boolean] True to enable recursive merging of hashes.
|
164
|
+
# @param merge_opts [Hash] A hash of options to be passed to the deep_merge method
|
138
165
|
# @return [Hash] The merged hash.
|
139
|
-
def merge_vars(base_hash:, hash:, merge: true)
|
166
|
+
def merge_vars(base_hash:, hash:, merge: true, merge_opts: {})
|
140
167
|
if base_hash.is_a?(Hash) && hash.is_a?(Hash)
|
141
|
-
return base_hash.deep_merge!(hash) if
|
168
|
+
return base_hash.deep_merge!(hash, deep_merge_opts(merge_opts)) if
|
169
|
+
merge == true
|
142
170
|
return base_hash.merge!(hash) if merge == false
|
143
171
|
end
|
144
172
|
{}
|
data/rndr.gemspec
CHANGED
@@ -20,11 +20,12 @@ Gem::Specification.new do |gem|
|
|
20
20
|
|
21
21
|
gem.required_ruby_version = '>= 2.3'
|
22
22
|
|
23
|
-
gem.add_dependency 'deep_merge', '
|
24
|
-
gem.add_dependency 'thor', '
|
23
|
+
gem.add_dependency 'deep_merge', '~> 1.1'
|
24
|
+
gem.add_dependency 'thor', '~> 0.19'
|
25
25
|
|
26
|
-
gem.add_development_dependency 'bundler', '
|
27
|
-
gem.add_development_dependency 'rake', '
|
28
|
-
gem.add_development_dependency 'rspec', '
|
29
|
-
gem.add_development_dependency '
|
26
|
+
gem.add_development_dependency 'bundler', '~> 1.12'
|
27
|
+
gem.add_development_dependency 'rake', '~> 11.2'
|
28
|
+
gem.add_development_dependency 'rspec', '~> 3.5'
|
29
|
+
gem.add_development_dependency 'rubocop', '~> 0.46'
|
30
|
+
gem.add_development_dependency 'coveralls', '~> 0.8'
|
30
31
|
end
|
data/spec/cli_spec.rb
CHANGED
@@ -5,19 +5,29 @@ require 'fileutils'
|
|
5
5
|
require 'rndr'
|
6
6
|
require_relative 'spec_helper'
|
7
7
|
|
8
|
-
module Rndr # rubocop:disable
|
9
|
-
RSpec.describe CLI do
|
10
|
-
before(:all) { Dir.chdir(File.join(Dir.pwd, '
|
11
|
-
after(:all) { Dir.chdir('../') }
|
12
|
-
|
8
|
+
module Rndr # rubocop:disable Metrics/ModuleLength
|
9
|
+
RSpec.describe CLI do # rubocop:disable Metrics/BlockLength
|
10
|
+
before(:all) { Dir.chdir(File.join(Dir.pwd, 'spec/resources')) }
|
13
11
|
let(:cli) { CLI.new }
|
14
|
-
|
15
|
-
describe '#check' do
|
12
|
+
describe '#check' do # rubocop:disable Metrics/BlockLength
|
16
13
|
context 'When the default options are supplied' do
|
17
14
|
before do
|
18
15
|
cli.options = {
|
19
|
-
extension: 'erb', ignore: '
|
20
|
-
|
16
|
+
extension: 'erb', ignore: 'rndrignore', merge: true,
|
17
|
+
merge_opts: {}, template: 'templates', vars: 'vars'
|
18
|
+
}
|
19
|
+
end
|
20
|
+
it 'should list the correctly matched results' do
|
21
|
+
expect { cli.check }.to output(/rendertest.txt.erb \[OK\]$/).to_stdout
|
22
|
+
expect { cli.check }.to_not output(/ignoretest.txt.erb [OK]$/).to_stdout
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'When a bool merge option is supplied' do
|
27
|
+
before do
|
28
|
+
cli.options = {
|
29
|
+
extension: 'erb', ignore: 'rndrignore', merge: true,
|
30
|
+
merge_opts: { 'overwrite_arrays' => 'true' }, template: 'templates', vars: 'vars'
|
21
31
|
}
|
22
32
|
end
|
23
33
|
it 'should list the correctly matched results' do
|
@@ -29,8 +39,8 @@ module Rndr # rubocop:disable Metris/ModuleLength
|
|
29
39
|
context 'When an alternate exntesion is provided' do
|
30
40
|
before do
|
31
41
|
cli.options = {
|
32
|
-
extension: 'tmplt', ignore: '
|
33
|
-
|
42
|
+
extension: 'tmplt', ignore: 'rndrignore', merge: true,
|
43
|
+
merge_opts: {}, template: 'templates', vars: 'vars'
|
34
44
|
}
|
35
45
|
end
|
36
46
|
it 'should list the correctly matched results' do
|
@@ -42,7 +52,7 @@ module Rndr # rubocop:disable Metris/ModuleLength
|
|
42
52
|
|
43
53
|
describe '#list' do
|
44
54
|
context 'When the default options are supplied' do
|
45
|
-
before { cli.options = { extension: 'erb', ignore: '
|
55
|
+
before { cli.options = { extension: 'erb', ignore: 'rndrignore', template: 'templates' } }
|
46
56
|
it 'should list the correctly matched results' do
|
47
57
|
expect { cli.list }.to output(/rendertest.txt.erb$/).to_stdout
|
48
58
|
expect { cli.list }.to_not output(/ignoretest.txt.erb/).to_stdout
|
@@ -50,7 +60,7 @@ module Rndr # rubocop:disable Metris/ModuleLength
|
|
50
60
|
end
|
51
61
|
context 'When an alternate extension is provided' do
|
52
62
|
before do
|
53
|
-
cli.options = { extension: 'tmplt', ignore: '
|
63
|
+
cli.options = { extension: 'tmplt', ignore: 'rndrignore', template: 'templates' }
|
54
64
|
end
|
55
65
|
it 'should list the correctly matched results' do
|
56
66
|
expect { cli.list }.to output(/exttest.txt.tmplt$/).to_stdout
|
@@ -59,70 +69,106 @@ module Rndr # rubocop:disable Metris/ModuleLength
|
|
59
69
|
end
|
60
70
|
end
|
61
71
|
|
62
|
-
describe '#render' do
|
63
|
-
let(:rendered_file) { File.absolute_path('
|
64
|
-
let(:rendered_ext) { File.absolute_path('
|
65
|
-
let(:
|
66
|
-
|
67
|
-
|
68
|
-
let(:rendered_replaced) do
|
69
|
-
File.join(File.dirname(__FILE__), 'resources/rendered_replaced.txt')
|
70
|
-
end
|
72
|
+
describe '#render' do # rubocop:disable Metrics/BlockLength
|
73
|
+
let(:rendered_file) { File.absolute_path('templates/rendertest.txt') }
|
74
|
+
let(:rendered_ext) { File.absolute_path('templates/exttest.txt') }
|
75
|
+
let(:spec_merged) { File.absolute_path('spec_merged.txt') }
|
76
|
+
let(:spec_opts) { File.absolute_path('spec_opts.txt') }
|
77
|
+
let(:spec_replaced) { File.absolute_path('spec_replaced.txt') }
|
71
78
|
after(:each) do
|
72
79
|
File.delete(rendered_file) if File.exist?(rendered_file)
|
73
80
|
File.delete(rendered_ext) if File.exist?(rendered_ext)
|
74
81
|
end
|
75
82
|
|
76
|
-
context 'When the defaults are
|
83
|
+
context 'When the defaults are supplied' do
|
84
|
+
before do
|
85
|
+
cli.options = {
|
86
|
+
extension: 'erb', ignore: 'rndrignore', merge: true,
|
87
|
+
merge_opts: {}, template: 'templates', vars: 'vars'
|
88
|
+
}
|
89
|
+
end
|
90
|
+
it 'should render items correctly' do
|
91
|
+
expect { cli.render }.to output(/rendertest.txt \[OK\]$/).to_stdout
|
92
|
+
expect { cli.render }.to_not output(/ignoretest.txt/).to_stdout
|
93
|
+
expect(FileUtils.compare_file(spec_merged, rendered_file)).to be_truthy
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'When a boolean merge option is supplied' do
|
77
98
|
before do
|
78
99
|
cli.options = {
|
79
|
-
extension: 'erb', ignore: '
|
80
|
-
|
100
|
+
extension: 'erb', ignore: 'rndrignore', merge: true,
|
101
|
+
merge_opts: { 'overwrite_arrays' => 'true' }, template: 'templates', vars: 'vars'
|
81
102
|
}
|
82
103
|
end
|
83
104
|
it 'should render items correctly' do
|
84
105
|
expect { cli.render }.to output(/rendertest.txt \[OK\]$/).to_stdout
|
85
106
|
expect { cli.render }.to_not output(/ignoretest.txt/).to_stdout
|
86
|
-
expect(FileUtils.compare_file(
|
107
|
+
expect(FileUtils.compare_file(spec_opts, rendered_file)).to be_truthy
|
87
108
|
end
|
88
109
|
end
|
89
110
|
|
90
|
-
context '
|
111
|
+
context 'When the replace merege strategy is specified' do
|
91
112
|
before do
|
92
113
|
cli.options = {
|
93
|
-
extension: 'erb', ignore: '
|
94
|
-
|
114
|
+
extension: 'erb', ignore: 'rndrignore', merge: false,
|
115
|
+
merge_opts: {}, template: 'templates', vars: 'vars'
|
95
116
|
}
|
96
117
|
end
|
97
118
|
it 'should render items correctly' do
|
98
119
|
expect { cli.render }.to output(/rendertest.txt \[OK\]$/).to_stdout
|
99
120
|
expect { cli.render }.to_not output(/ignoretest.txt/).to_stdout
|
100
|
-
expect(FileUtils.compare_file(
|
121
|
+
expect(FileUtils.compare_file(spec_replaced, rendered_file)).to be_truthy
|
101
122
|
end
|
102
123
|
end
|
103
124
|
|
104
125
|
context 'When provided an alternate extension' do
|
105
126
|
before do
|
106
127
|
cli.options = {
|
107
|
-
extension: 'tmplt', ignore: '
|
108
|
-
|
128
|
+
extension: 'tmplt', ignore: 'rndrignore', merge: true,
|
129
|
+
merge_opts: {}, template: 'templates', vars: 'vars'
|
109
130
|
}
|
110
131
|
end
|
111
132
|
it 'should render items correctly' do
|
112
133
|
expect { cli.render }.to output(/exttest.txt \[OK\]$/).to_stdout
|
113
134
|
expect { cli.render }.to_not output(/rendertest.txt/).to_stdout
|
114
|
-
expect(FileUtils.compare_file(
|
135
|
+
expect(FileUtils.compare_file(spec_merged, rendered_ext)).to be_truthy
|
115
136
|
end
|
116
137
|
end
|
117
138
|
end
|
118
139
|
|
119
|
-
describe '#vars' do
|
120
|
-
context 'When a directory is supplied.' do
|
140
|
+
describe '#vars' do # rubocop:disable Metrics/BlockLength
|
141
|
+
context 'When a directory is supplied.' do # rubocop:disable Metrics/BlockLength
|
121
142
|
context 'should serialize and recursively merge variables' do
|
122
143
|
before do
|
123
|
-
cli.options = { format: 'yaml', merge: true, vars: 'vars' }
|
124
|
-
@merged =
|
125
|
-
|
144
|
+
cli.options = { format: 'yaml', merge: true, merge_opts: {}, vars: 'vars' }
|
145
|
+
@merged = File.read(File.absolute_path('vars_merged.txt'))
|
146
|
+
end
|
147
|
+
it 'should perform a deep merge' do
|
148
|
+
expect { cli.vars }.to output(@merged).to_stdout
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context 'should serialize and recursively merge variables with a boolean merge option' do
|
153
|
+
before do
|
154
|
+
cli.options = {
|
155
|
+
format: 'yaml', merge: true,
|
156
|
+
merge_opts: { 'overwrite_arrays' => 'true' }, vars: 'vars'
|
157
|
+
}
|
158
|
+
@merged = File.read(File.absolute_path('vars_opts_bool.txt'))
|
159
|
+
end
|
160
|
+
it 'should perform a deep merge' do
|
161
|
+
expect { cli.vars }.to output(@merged).to_stdout
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'should serialize and recursively merge variables with a string merge option' do
|
166
|
+
before do
|
167
|
+
cli.options = {
|
168
|
+
format: 'yaml', merge: true,
|
169
|
+
merge_opts: { 'unpack_arrays' => ',' }, vars: 'vars'
|
170
|
+
}
|
171
|
+
@merged = File.read(File.absolute_path('vars_opts_string.txt'))
|
126
172
|
end
|
127
173
|
it 'should perform a deep merge' do
|
128
174
|
expect { cli.vars }.to output(@merged).to_stdout
|
@@ -131,9 +177,8 @@ module Rndr # rubocop:disable Metris/ModuleLength
|
|
131
177
|
|
132
178
|
context 'should serialize and merge variables with replace behaviour' do
|
133
179
|
before do
|
134
|
-
cli.options = { format: 'yaml', merge: false, vars: 'vars' }
|
135
|
-
@replaced =
|
136
|
-
File.read(File.join(File.dirname(__FILE__), 'resources/vars_replaced.txt'))
|
180
|
+
cli.options = { format: 'yaml', merge: false, merge_opts: {}, vars: 'vars' }
|
181
|
+
@replaced = File.read(File.absolute_path('vars_replaced.txt'))
|
137
182
|
end
|
138
183
|
it 'should perform a standard merge' do
|
139
184
|
expect { cli.vars }.to output(@replaced).to_stdout
|
@@ -143,9 +188,8 @@ module Rndr # rubocop:disable Metris/ModuleLength
|
|
143
188
|
|
144
189
|
context 'When a json file is supplied' do
|
145
190
|
before do
|
146
|
-
cli.options = { format: 'yaml', merge: true, vars: 'vars/a.json' }
|
147
|
-
@vars =
|
148
|
-
File.read(File.join(File.dirname(__FILE__), 'resources/vars_a.txt'))
|
191
|
+
cli.options = { format: 'yaml', merge: true, merge_opts: {}, vars: 'vars/a.json' }
|
192
|
+
@vars = File.read(File.absolute_path('vars_a.txt'))
|
149
193
|
end
|
150
194
|
it 'should serialize the data' do
|
151
195
|
expect { cli.vars }.to output(@vars).to_stdout
|
@@ -153,9 +197,8 @@ module Rndr # rubocop:disable Metris/ModuleLength
|
|
153
197
|
end
|
154
198
|
context 'When a yaml file is supplied' do
|
155
199
|
before do
|
156
|
-
cli.options = { format: 'yaml', merge: true, vars: 'vars/b.yaml' }
|
157
|
-
@vars =
|
158
|
-
File.read(File.join(File.dirname(__FILE__), 'resources/vars_b.txt'))
|
200
|
+
cli.options = { format: 'yaml', merge: true, merge_opts: {}, vars: 'vars/b.yaml' }
|
201
|
+
@vars = File.read(File.absolute_path('vars_b.txt'))
|
159
202
|
end
|
160
203
|
it 'should serialize the data' do
|
161
204
|
expect { cli.vars }.to output(@vars).to_stdout
|
File without changes
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
child:
|
3
|
+
childarray:
|
4
|
+
- arraykey3: arrayval3
|
5
|
+
- arraykey4: arrayval4
|
6
|
+
childhash:
|
7
|
+
childhashkey1: childhashval1
|
8
|
+
childhashkey2: childhashval2
|
9
|
+
childhashkey3: childhashval3
|
10
|
+
childhashkey4: childhashval4
|
11
|
+
|
12
|
+
|
13
|
+
{"boolkey":false,"numkey":2}
|
14
|
+
|
15
|
+
parent3: mergeval
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
---
|
2
|
+
parent1:
|
3
|
+
child:
|
4
|
+
childarray:
|
5
|
+
- arraykey3: arrayval3
|
6
|
+
- arraykey4: arrayval4
|
7
|
+
childhash:
|
8
|
+
childhashkey1: childhashval1
|
9
|
+
childhashkey2: childhashval2
|
10
|
+
childhashkey3: childhashval3
|
11
|
+
childhashkey4: childhashval4
|
12
|
+
parent2:
|
13
|
+
boolkey: false
|
14
|
+
numkey: 2
|
15
|
+
parent3:
|
16
|
+
mergetest: mergeval
|
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
parent1:
|
3
|
+
child:
|
4
|
+
childarray:
|
5
|
+
- '{"arraykey1"=>"arrayval1"}'
|
6
|
+
- '{"arraykey2"=>"arrayval2"}'
|
7
|
+
- '{"arraykey3"=>"arrayval3"}'
|
8
|
+
- '{"arraykey4"=>"arrayval4"}'
|
9
|
+
childhash:
|
10
|
+
childhashkey1: childhashval1
|
11
|
+
childhashkey2: childhashval2
|
12
|
+
childhashkey3: childhashval3
|
13
|
+
childhashkey4: childhashval4
|
14
|
+
parent2:
|
15
|
+
boolkey: false
|
16
|
+
numkey: 2
|
17
|
+
parent3:
|
18
|
+
mergetest: mergeval
|
data/spec/spec_helper.rb
CHANGED
data/spec/template_spec.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
# frozen_string_literal: true
|
3
|
+
# rubocop:disable Metrics/BlockLength
|
3
4
|
|
4
5
|
require 'rndr'
|
5
6
|
require 'yaml'
|
@@ -8,17 +9,15 @@ require_relative 'spec_helper'
|
|
8
9
|
module Rndr
|
9
10
|
RSpec.describe Template do
|
10
11
|
before(:all) do
|
11
|
-
Dir.chdir(File.join(Dir.pwd, 'test'))
|
12
12
|
@success_tmplt = File.absolute_path('templates/rendertest.txt.erb')
|
13
13
|
@fail_tmplt = File.absolute_path('templates/failtest.txt.erb')
|
14
14
|
@rendered_success = File.absolute_path('templates/rendertest.txt')
|
15
15
|
@rendered_fail = File.absolute_path('templates/failtest.txt')
|
16
|
-
@compare_success = File.
|
16
|
+
@compare_success = File.absolute_path('spec_merged.txt')
|
17
17
|
@vars =
|
18
|
-
YAML.load(File.read(File.
|
18
|
+
YAML.load(File.read(File.absolute_path('vars_merged.txt')))
|
19
19
|
end
|
20
20
|
after(:all) do
|
21
|
-
Dir.chdir('../')
|
22
21
|
File.delete(@rendered_success) if File.exist?(@rendered_success)
|
23
22
|
File.delete(@rendered_fail) if File.exist?(@rendered_fail)
|
24
23
|
end
|
@@ -59,3 +58,4 @@ module Rndr
|
|
59
58
|
end
|
60
59
|
end
|
61
60
|
end
|
61
|
+
# rubocop:enable Metrics/BlockLength
|
data/spec/util_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
# frozen_string_literal: true
|
3
|
-
|
3
|
+
# rubocop:disable Metrics/BlockLength
|
4
4
|
require 'json'
|
5
5
|
require 'rndr'
|
6
6
|
require 'rspec'
|
@@ -9,9 +9,6 @@ require_relative 'spec_helper'
|
|
9
9
|
|
10
10
|
module Rndr
|
11
11
|
RSpec.describe Rndr do
|
12
|
-
before(:all) { Dir.chdir(File.join(Dir.pwd, 'test')) }
|
13
|
-
after(:all) { Dir.chdir('../') }
|
14
|
-
|
15
12
|
describe '#matches' do
|
16
13
|
context 'When using the defaults' do
|
17
14
|
let(:matched) { [File.absolute_path('templates/rendertest.txt.erb')] }
|
@@ -19,7 +16,7 @@ module Rndr
|
|
19
16
|
[File.absolute_path('templates/ignoretest.txt.erb'),
|
20
17
|
File.absolute_path('templates/failtest.txt.erb')]
|
21
18
|
end
|
22
|
-
subject(:results) { Rndr.matches(path: 'templates') }
|
19
|
+
subject(:results) { Rndr.matches(path: 'templates', ignore_path: 'rndrignore') }
|
23
20
|
it 'should be an Array of filtered paths with default extension' do
|
24
21
|
expect(results).to be_a(Array)
|
25
22
|
expect(results).to match_array(matched)
|
@@ -32,7 +29,9 @@ module Rndr
|
|
32
29
|
[File.absolute_path('templates/ignoretest.txt.erb'),
|
33
30
|
File.absolute_path('templates/failtest.txt.erb')]
|
34
31
|
end
|
35
|
-
subject(:results)
|
32
|
+
subject(:results) do
|
33
|
+
Rndr.matches(path: 'templates', ext: 'tmplt', ignore_path: 'rndrignore')
|
34
|
+
end
|
36
35
|
it 'should be an Array of paths with alternate extension' do
|
37
36
|
expect(results).to be_a(Array)
|
38
37
|
expect(results).to match_array(matched)
|
@@ -43,9 +42,7 @@ module Rndr
|
|
43
42
|
describe '#read_vars' do
|
44
43
|
context 'When a directory is supplied' do
|
45
44
|
context 'should serialize and recursively merges variables' do
|
46
|
-
let(:results)
|
47
|
-
YAML.load(File.read(File.join(File.dirname(__FILE__), 'resources/vars_merged.txt')))
|
48
|
-
end
|
45
|
+
let(:results) { YAML.load(File.read('vars_merged.txt')) }
|
49
46
|
subject(:vars) { Rndr.read_vars(path: 'vars', merge: true) }
|
50
47
|
it 'should perform a deep merge' do
|
51
48
|
expect(vars).to eql(results)
|
@@ -53,7 +50,7 @@ module Rndr
|
|
53
50
|
end
|
54
51
|
context 'should serialize and merge variables with replace behaviour' do
|
55
52
|
let(:results) do
|
56
|
-
YAML.load(File.read(
|
53
|
+
YAML.load(File.read('vars_replaced.txt'))
|
57
54
|
end
|
58
55
|
subject(:vars) { Rndr.read_vars(path: 'vars', merge: false) }
|
59
56
|
it 'should perform a standard merge' do
|
@@ -63,7 +60,7 @@ module Rndr
|
|
63
60
|
end
|
64
61
|
|
65
62
|
context 'When a json file is supplied' do
|
66
|
-
let(:results) { JSON.
|
63
|
+
let(:results) { JSON.parse(File.read('vars/a.json')) }
|
67
64
|
subject(:vars) { Rndr.read_vars(path: 'vars/a.json', merge: true) }
|
68
65
|
it 'should serialize the data' do
|
69
66
|
expect(vars).to eql(results)
|
@@ -80,3 +77,4 @@ module Rndr
|
|
80
77
|
end
|
81
78
|
end
|
82
79
|
end
|
80
|
+
# rubocop:enable Metrics/BlockLength
|
data/version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
metadata
CHANGED
@@ -1,99 +1,113 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rndr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Killen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deep_merge
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.1
|
19
|
+
version: '1.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.1
|
26
|
+
version: '1.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: thor
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.19
|
33
|
+
version: '0.19'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.19
|
40
|
+
version: '0.19'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.12
|
47
|
+
version: '1.12'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.12
|
54
|
+
version: '1.12'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 11.2
|
61
|
+
version: '11.2'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 11.2
|
68
|
+
version: '11.2'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 3.5
|
75
|
+
version: '3.5'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 3.5
|
82
|
+
version: '3.5'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.46'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.46'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: coveralls
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
|
-
- - "
|
101
|
+
- - "~>"
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.8
|
103
|
+
version: '0.8'
|
90
104
|
type: :development
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
|
-
- - "
|
108
|
+
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.8
|
110
|
+
version: '0.8'
|
97
111
|
description: rndr is a tool that simply renders Ruby erb templates for use with other
|
98
112
|
applications.
|
99
113
|
email:
|
@@ -120,22 +134,26 @@ files:
|
|
120
134
|
- lib/rndr/version.rb
|
121
135
|
- rndr.gemspec
|
122
136
|
- spec/cli_spec.rb
|
123
|
-
- spec/resources/
|
124
|
-
- spec/resources/
|
137
|
+
- spec/resources/rndrignore
|
138
|
+
- spec/resources/spec_merged.txt
|
139
|
+
- spec/resources/spec_opts.txt
|
140
|
+
- spec/resources/spec_replaced.txt
|
141
|
+
- spec/resources/templates/exttest.txt.tmplt
|
142
|
+
- spec/resources/templates/failtest.txt.erb
|
143
|
+
- spec/resources/templates/ignoretest.txt
|
144
|
+
- spec/resources/templates/ignoretest.txt.erb
|
145
|
+
- spec/resources/templates/rendertest.txt.erb
|
146
|
+
- spec/resources/vars/a.json
|
147
|
+
- spec/resources/vars/b.yaml
|
125
148
|
- spec/resources/vars_a.txt
|
126
149
|
- spec/resources/vars_b.txt
|
127
150
|
- spec/resources/vars_merged.txt
|
151
|
+
- spec/resources/vars_opts_bool.txt
|
152
|
+
- spec/resources/vars_opts_string.txt
|
128
153
|
- spec/resources/vars_replaced.txt
|
129
154
|
- spec/spec_helper.rb
|
130
155
|
- spec/template_spec.rb
|
131
156
|
- spec/util_spec.rb
|
132
|
-
- test/.rndrignore
|
133
|
-
- test/templates/exttest.txt.tmplt
|
134
|
-
- test/templates/failtest.txt.erb
|
135
|
-
- test/templates/ignoretest.txt.erb
|
136
|
-
- test/templates/rendertest.txt.erb
|
137
|
-
- test/vars/a.json
|
138
|
-
- test/vars/b.yaml
|
139
157
|
- version.txt
|
140
158
|
homepage: https://github.com/arc-ts/rndr
|
141
159
|
licenses:
|