ykxutils 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/.rubocop_todo.yml +125 -51
- data/Gemfile +13 -9
- data/Gemfile.lock +18 -6
- data/Rakefile +25 -8
- data/lib/ykxutils/erubyx.rb +52 -0
- data/lib/ykxutils/gridlist.rb +49 -0
- data/lib/ykxutils/nginxconfig.rb +40 -0
- data/lib/ykxutils/nginxconfigfiles.rb +33 -0
- data/lib/ykxutils/pstorex.rb +1 -1
- data/lib/ykxutils/version.rb +1 -1
- data/lib/ykxutils/yamlx.rb +24 -47
- data/lib/ykxutils.rb +4 -0
- data/test_data/4servers.erb +7 -0
- data/test_data/v103-3-189-127/4servers.erb +0 -0
- data/test_data/v103-3-189-127/a.northern-cross.net/base.yml +28 -0
- data/test_data/v103-3-189-127/a.northern-cross.net/value_host.yml +1 -0
- data/test_data/v103-3-189-127/b.northern-cross.net/base.yml +28 -0
- data/test_data/v103-3-189-127/b.northern-cross.net/value_host.yml +1 -0
- data/test_data/v103-3-189-127/c.northern-cross.net/base.yml +28 -0
- data/test_data/v103-3-189-127/c.northern-cross.net/value_host.yml +1 -0
- data/test_data/v103-3-189-127/d.northern-cross.info/base.yml +28 -0
- data/test_data/v103-3-189-127/d.northern-cross.info/value_host.yml +1 -0
- data/test_data/v103-3-189-127/d.northern-cross.net/base.yml +28 -0
- data/test_data/v103-3-189-127/d.northern-cross.net/value_host.yml +1 -0
- data/test_data/v103-3-189-127/e.northern-cross.info/base.yml +28 -0
- data/test_data/v103-3-189-127/e.northern-cross.info/value_host.yml +1 -0
- data/test_data/v103-3-189-127/e.northern-cross.net/base.yml +28 -0
- data/test_data/v103-3-189-127/e.northern-cross.net/value_host.yml +1 -0
- data/test_data/v103-3-189-127/f.northern-cross.info/base.yml +28 -0
- data/test_data/v103-3-189-127/f.northern-cross.info/value_host.yml +1 -0
- data/test_data/v103-3-189-127/f.northern-cross.net/base.yml +28 -0
- data/test_data/v103-3-189-127/f.northern-cross.net/value_host.yml +1 -0
- data/test_data/v103-3-189-127/t_server_1.erb +7 -0
- data/test_data/v103-3-189-127/template.erb +21 -0
- data/test_data/v103-3-189-127/template_ssl.erb +22 -0
- data/test_data/v103-3-189-127/template_ssl_www.erb +12 -0
- data/test_data/v103-3-189-127/template_www.erb +24 -0
- data/test_data/v103-3-189-127/value.yml +3 -0
- data/test_data/v103-3-189-127/value_ssl.yml +5 -0
- data/ykxutils.gemspec +33 -26
- metadata +86 -17
- data/.github/workflows/main.yml +0 -16
- data/.gitignore +0 -14
- data/bin/console +0 -15
- data/bin/setup +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb57978cd24ccbb824287f130d77a3c38a6703e0341914b32221adf60786bb73
|
4
|
+
data.tar.gz: 92fd92f8550542480f7f44e11870d0a18edc3c7412311d0511bd0c9e554eacbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 594acd0dd1516dfad347315770af817a49df02e09bbee5b3b78f6dae768a6272f450a160318a708e5e3d39b6070be5128bf2d327045da9c516bbe3e891b45e94
|
7
|
+
data.tar.gz: 1909511a5120c6a9564f74db65f45d602277df8ee594010f3ea6f7d2da2f7c3dab22bf2aec8739c29369fe75bbee547e6f10ee0171d0ee4b31af76a0940d9e99
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2022-
|
3
|
+
# on 2022-10-11 11:06:24 UTC using RuboCop version 1.36.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -8,98 +8,172 @@
|
|
8
8
|
|
9
9
|
# Offense count: 1
|
10
10
|
# This cop supports safe autocorrection (--autocorrect).
|
11
|
-
|
11
|
+
# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include.
|
12
|
+
# Include: **/*.gemfile, **/Gemfile, **/gems.rb
|
13
|
+
Bundler/OrderedGems:
|
12
14
|
Exclude:
|
13
|
-
|
15
|
+
# - 'Gemfile'
|
14
16
|
|
15
17
|
# Offense count: 1
|
16
18
|
# This cop supports safe autocorrection (--autocorrect).
|
17
|
-
|
19
|
+
# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include.
|
20
|
+
# Include: **/*.gemspec
|
21
|
+
Gemspec/OrderedDependencies:
|
18
22
|
Exclude:
|
19
|
-
|
23
|
+
# - 'ykxutils.gemspec'
|
20
24
|
|
21
25
|
# Offense count: 1
|
22
26
|
# This cop supports safe autocorrection (--autocorrect).
|
23
|
-
# Configuration parameters:
|
24
|
-
|
27
|
+
# Configuration parameters: EnforcedStyle.
|
28
|
+
# SupportedStyles: space, no_space
|
29
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
25
30
|
Exclude:
|
26
|
-
|
31
|
+
# - 'lib/ykxutils/pstorex.rb'
|
32
|
+
|
33
|
+
# Offense count: 10
|
34
|
+
Lint/UselessAssignment:
|
35
|
+
Exclude:
|
36
|
+
# - 'lib/ykxutils/yamlx.rb'
|
27
37
|
|
28
38
|
# Offense count: 1
|
29
|
-
#
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
39
|
+
# Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods, CountRepeatedAttributes.
|
40
|
+
Metrics/AbcSize:
|
41
|
+
Max: 19
|
42
|
+
|
43
|
+
# Offense count: 3
|
44
|
+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, AllowedMethods, AllowedPatterns, IgnoredMethods.
|
45
|
+
Metrics/MethodLength:
|
46
|
+
Max: 15
|
47
|
+
|
48
|
+
# Offense count: 1
|
49
|
+
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
|
50
|
+
Metrics/ParameterLists:
|
51
|
+
Max: 6
|
52
|
+
|
53
|
+
# Offense count: 1
|
54
|
+
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
|
55
|
+
# AllowedNames: as, at, by, db, id, in, io, ip, of, on, os, pp, to
|
56
|
+
Naming/MethodParameterName:
|
57
|
+
Exclude:
|
58
|
+
- 'lib/ykxutils/nginxconfigfiles.rb'
|
34
59
|
|
35
60
|
# Offense count: 1
|
36
61
|
# This cop supports safe autocorrection (--autocorrect).
|
37
|
-
# Configuration parameters:
|
38
|
-
#
|
39
|
-
|
62
|
+
# Configuration parameters: EnforcedStyle.
|
63
|
+
# SupportedStyles: be, be_nil
|
64
|
+
RSpec/BeNil:
|
65
|
+
Exclude:
|
66
|
+
- 'spec/ykxutils_spec.rb'
|
67
|
+
|
68
|
+
# Offense count: 1
|
69
|
+
RSpec/BeforeAfterAll:
|
40
70
|
Exclude:
|
41
|
-
|
71
|
+
- 'spec/spec_helper.rb'
|
72
|
+
- 'spec/rails_helper.rb'
|
73
|
+
- 'spec/support/**/*.rb'
|
74
|
+
- 'spec/ykxutils_spec.rb'
|
42
75
|
|
43
76
|
# Offense count: 2
|
44
|
-
#
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
77
|
+
# Configuration parameters: CountAsOne.
|
78
|
+
RSpec/ExampleLength:
|
79
|
+
Max: 9
|
80
|
+
|
81
|
+
# Offense count: 1
|
82
|
+
# Configuration parameters: AssignmentOnly.
|
83
|
+
RSpec/InstanceVariable:
|
49
84
|
Exclude:
|
50
|
-
|
85
|
+
- 'spec/ykxutils_spec.rb'
|
51
86
|
|
52
|
-
# Offense count:
|
53
|
-
|
54
|
-
# Configuration parameters: EnforcedStyle.
|
55
|
-
# SupportedStyles: space, compact, no_space
|
56
|
-
Layout/SpaceInsideParens:
|
87
|
+
# Offense count: 1
|
88
|
+
RSpec/NoExpectationExample:
|
57
89
|
Exclude:
|
58
|
-
|
90
|
+
- 'spec/ykxutils_spec.rb'
|
59
91
|
|
60
92
|
# Offense count: 1
|
61
93
|
# This cop supports safe autocorrection (--autocorrect).
|
62
94
|
# Configuration parameters: EnforcedStyle.
|
63
|
-
# SupportedStyles:
|
64
|
-
|
95
|
+
# SupportedStyles: not_to, to_not
|
96
|
+
RSpec/NotToNot:
|
65
97
|
Exclude:
|
66
|
-
|
98
|
+
- 'spec/ykxutils_spec.rb'
|
67
99
|
|
68
|
-
# Offense count:
|
100
|
+
# Offense count: 8
|
69
101
|
# This cop supports safe autocorrection (--autocorrect).
|
70
|
-
|
102
|
+
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, AllowedMethods, AllowedPatterns, IgnoredMethods, AllowBracesOnProceduralOneLiners, BracesRequiredMethods.
|
103
|
+
# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces
|
104
|
+
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
|
105
|
+
# FunctionalMethods: let, let!, subject, watch
|
106
|
+
# AllowedMethods: lambda, proc, it
|
107
|
+
Style/BlockDelimiters:
|
71
108
|
Exclude:
|
72
|
-
- '
|
109
|
+
- 'lib/ykxutils/erubyx.rb'
|
110
|
+
- 'lib/ykxutils/gridlist.rb'
|
111
|
+
- 'lib/ykxutils/nginxconfig.rb'
|
112
|
+
- 'lib/ykxutils/nginxconfigfiles.rb'
|
113
|
+
- 'spec/ykxutils_spec.rb'
|
73
114
|
|
74
|
-
# Offense count:
|
75
|
-
|
115
|
+
# Offense count: 5
|
116
|
+
# This cop supports safe autocorrection (--autocorrect).
|
117
|
+
Style/ColonMethodCall:
|
76
118
|
Exclude:
|
77
|
-
|
78
|
-
|
119
|
+
- 'lib/ykxutils/gridlist.rb'
|
120
|
+
- 'lib/ykxutils/nginxconfig.rb'
|
121
|
+
- 'spec/ykxutils_spec.rb'
|
79
122
|
|
80
123
|
# Offense count: 1
|
81
|
-
#
|
82
|
-
|
83
|
-
|
124
|
+
# This cop supports safe autocorrection (--autocorrect).
|
125
|
+
Style/EachWithObject:
|
126
|
+
Exclude:
|
127
|
+
- 'spec/ykxutils_spec.rb'
|
128
|
+
|
129
|
+
# Offense count: 3
|
130
|
+
# This cop supports safe autocorrection (--autocorrect).
|
131
|
+
# Configuration parameters: EnforcedStyle, EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
|
132
|
+
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
|
133
|
+
# SupportedShorthandSyntax: always, never, either, consistent
|
134
|
+
Style/HashSyntax:
|
135
|
+
Exclude:
|
136
|
+
- 'lib/ykxutils/gridlist.rb'
|
137
|
+
|
138
|
+
# Offense count: 2
|
139
|
+
# This cop supports safe autocorrection (--autocorrect).
|
140
|
+
Style/IfUnlessModifier:
|
141
|
+
Exclude:
|
142
|
+
- 'lib/ykxutils/erubyx.rb'
|
143
|
+
- 'lib/ykxutils/gridlist.rb'
|
84
144
|
|
85
145
|
# Offense count: 1
|
86
146
|
# This cop supports unsafe autocorrection (--autocorrect-all).
|
87
|
-
# Configuration parameters:
|
88
|
-
|
147
|
+
# Configuration parameters: EnforcedStyle.
|
148
|
+
# SupportedStyles: literals, strict
|
149
|
+
Style/MutableConstant:
|
89
150
|
Exclude:
|
90
|
-
|
151
|
+
- 'lib/ykxutils/gridlist.rb'
|
91
152
|
|
92
153
|
# Offense count: 2
|
93
|
-
# This cop supports
|
94
|
-
# Configuration parameters:
|
95
|
-
|
154
|
+
# This cop supports safe autocorrection (--autocorrect).
|
155
|
+
# Configuration parameters: EnforcedStyle, MinBodyLength.
|
156
|
+
# SupportedStyles: skip_modifier_ifs, always
|
157
|
+
Style/Next:
|
158
|
+
Exclude:
|
159
|
+
- 'lib/ykxutils/nginxconfig.rb'
|
160
|
+
- 'lib/ykxutils/nginxconfigfiles.rb'
|
161
|
+
|
162
|
+
# Offense count: 1
|
163
|
+
# This cop supports safe autocorrection (--autocorrect).
|
164
|
+
# Configuration parameters: PreferredDelimiters.
|
165
|
+
Style/PercentLiteralDelimiters:
|
96
166
|
Exclude:
|
97
|
-
|
167
|
+
- 'lib/ykxutils/gridlist.rb'
|
98
168
|
|
99
|
-
# Offense count:
|
169
|
+
# Offense count: 45
|
100
170
|
# This cop supports safe autocorrection (--autocorrect).
|
101
171
|
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
|
102
172
|
# SupportedStyles: single_quotes, double_quotes
|
103
173
|
Style/StringLiterals:
|
104
174
|
Exclude:
|
105
|
-
|
175
|
+
- 'Gemfile'
|
176
|
+
- 'lib/ykxutils/erubyx.rb'
|
177
|
+
- 'lib/ykxutils/gridlist.rb'
|
178
|
+
- 'lib/ykxutils/nginxconfigfiles.rb'
|
179
|
+
- 'ykxutils.gemspec'
|
data/Gemfile
CHANGED
@@ -1,18 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
source
|
3
|
+
source 'https://rubygems.org'
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in ykxutils.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
gem
|
9
|
-
|
10
|
-
gem
|
11
|
-
|
12
|
-
gem "rubocop", "~> 1.7"
|
13
|
-
gem "rubocop-rake", require: false
|
14
|
-
gem "rubocop-rspec", require: false
|
8
|
+
gem 'bundler'
|
9
|
+
gem 'erubi'
|
10
|
+
gem 'rake', '~> 13.0'
|
11
|
+
gem 'tilt'
|
15
12
|
|
16
13
|
group :development do
|
17
|
-
gem
|
14
|
+
gem 'yard'
|
15
|
+
end
|
16
|
+
|
17
|
+
group :test do
|
18
|
+
gem 'rspec', '~> 3.0'
|
19
|
+
gem 'rubocop'
|
20
|
+
gem 'rubocop-rake', require: false
|
21
|
+
gem 'rubocop-rspec', require: false
|
18
22
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,20 +1,25 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ykxutils (0.1.
|
4
|
+
ykxutils (0.1.8)
|
5
|
+
bundler
|
6
|
+
erubi
|
7
|
+
rake (~> 13.0)
|
8
|
+
tilt
|
5
9
|
|
6
10
|
GEM
|
7
11
|
remote: https://rubygems.org/
|
8
12
|
specs:
|
9
13
|
ast (2.4.2)
|
10
14
|
diff-lcs (1.5.0)
|
15
|
+
erubi (1.11.0)
|
11
16
|
json (2.6.2)
|
12
17
|
parallel (1.22.1)
|
13
18
|
parser (3.1.2.1)
|
14
19
|
ast (~> 2.4.1)
|
15
20
|
rainbow (3.1.1)
|
16
21
|
rake (13.0.6)
|
17
|
-
regexp_parser (2.
|
22
|
+
regexp_parser (2.6.0)
|
18
23
|
rexml (3.2.5)
|
19
24
|
rspec (3.11.0)
|
20
25
|
rspec-core (~> 3.11.0)
|
@@ -41,12 +46,16 @@ GEM
|
|
41
46
|
unicode-display_width (>= 1.4.0, < 3.0)
|
42
47
|
rubocop-ast (1.21.0)
|
43
48
|
parser (>= 3.1.1.0)
|
49
|
+
rubocop-performance (1.15.0)
|
50
|
+
rubocop (>= 1.7.0, < 2.0)
|
51
|
+
rubocop-ast (>= 0.4.0)
|
44
52
|
rubocop-rake (0.6.0)
|
45
53
|
rubocop (~> 1.0)
|
46
|
-
rubocop-rspec (2.13.
|
54
|
+
rubocop-rspec (2.13.2)
|
47
55
|
rubocop (~> 1.33)
|
48
56
|
ruby-progressbar (1.11.0)
|
49
|
-
|
57
|
+
tilt (2.0.11)
|
58
|
+
unicode-display_width (2.3.0)
|
50
59
|
webrick (1.7.0)
|
51
60
|
yard (0.9.28)
|
52
61
|
webrick (~> 1.7.0)
|
@@ -56,13 +65,16 @@ PLATFORMS
|
|
56
65
|
|
57
66
|
DEPENDENCIES
|
58
67
|
bundler
|
68
|
+
erubi
|
59
69
|
rake (~> 13.0)
|
60
70
|
rspec (~> 3.0)
|
61
|
-
rubocop
|
71
|
+
rubocop
|
72
|
+
rubocop-performance
|
62
73
|
rubocop-rake
|
63
74
|
rubocop-rspec
|
75
|
+
tilt
|
64
76
|
yard
|
65
77
|
ykxutils!
|
66
78
|
|
67
79
|
BUNDLED WITH
|
68
|
-
2.3.
|
80
|
+
2.3.22
|
data/Rakefile
CHANGED
@@ -1,12 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "bundler/gem_tasks"
|
4
|
-
require "rspec/core/rake_task"
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
begin
|
6
|
+
require "rspec/core/rake_task"
|
7
|
+
rescue LoadError => e
|
8
|
+
puts e.message
|
9
|
+
end
|
10
|
+
begin
|
11
|
+
RSpec::Core::RakeTask.new(:spec)
|
12
|
+
rescue NameError, LoadError => e
|
13
|
+
puts e.message
|
14
|
+
end
|
15
|
+
begin
|
16
|
+
require "rubocop/rake_task"
|
17
|
+
rescue LoadError => e
|
18
|
+
puts e.message
|
19
|
+
end
|
20
|
+
begin
|
21
|
+
RuboCop::RakeTask.new
|
22
|
+
rescue NameError, LoadError => e
|
23
|
+
puts e.message
|
24
|
+
end
|
25
|
+
begin
|
26
|
+
task default: %i[spec rubocop]
|
27
|
+
rescue LoadError => e
|
28
|
+
puts e.message
|
29
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'tilt'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Ykxutils
|
5
|
+
module Erubyx
|
6
|
+
module_function
|
7
|
+
|
8
|
+
def erubi_render(template_hash, scope, value_hash = {})
|
9
|
+
unless template_hash[:OBJ]
|
10
|
+
template_hash[:OBJ] = Tilt::ErubiTemplate.new { template_hash[:TEMPLATE] }
|
11
|
+
end
|
12
|
+
template_hash[:OBJ].render(scope, value_hash)
|
13
|
+
end
|
14
|
+
|
15
|
+
##
|
16
|
+
# `erubi_render_with_file` takes a template file path, a scope, and a value file path, reads the
|
17
|
+
# template file, loads the value file, and then calls `erubi_render` with the template hash, scope,
|
18
|
+
# and value hash
|
19
|
+
#
|
20
|
+
# Args:
|
21
|
+
# template_file_path: The path to the template file.
|
22
|
+
# scope: the scope of the template. This is the name of the directory that the template is in.
|
23
|
+
# value_file_path: The path to the YAML file that contains the values to be used in the template.
|
24
|
+
def erubi_render_with_file(template_file_path, scope, value_file_path_array)
|
25
|
+
template_text = File.read(template_file_path)
|
26
|
+
template_hash = { TEMPLATE: template_text,
|
27
|
+
OBJ: nil }
|
28
|
+
value_hash = value_file_path_array.reduce({}) { |hash, path|
|
29
|
+
# p path
|
30
|
+
hash0 = YAML.load_file(path)
|
31
|
+
# p hash0
|
32
|
+
hash = hash.merge(hash0)
|
33
|
+
# p hash
|
34
|
+
hash
|
35
|
+
}
|
36
|
+
# puts value_hash
|
37
|
+
erubi_render(template_hash, scope, value_hash)
|
38
|
+
end
|
39
|
+
|
40
|
+
def erubi_render_with_template_file(template_file_path, scope, value_hash = {})
|
41
|
+
template_text = File.read(template_file_path)
|
42
|
+
template_hash = make_template_hash(template_text)
|
43
|
+
# puts value_hash
|
44
|
+
erubi_render(template_hash, scope, value_hash)
|
45
|
+
end
|
46
|
+
|
47
|
+
def make_template_hash(text)
|
48
|
+
{ TEMPLATE: text,
|
49
|
+
OBJ: nil }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'ykxutils/erubyx'
|
2
|
+
|
3
|
+
module Ykxutils
|
4
|
+
module Gridlist
|
5
|
+
TAMPLETES = { :GRID_DEF =>
|
6
|
+
{ :TEMPLATE => %!
|
7
|
+
.g-<%= row %>-<%= colum %> {
|
8
|
+
grid-row-start: <%= row %>;
|
9
|
+
grid-row-end: ,<%= row + 1 %>;
|
10
|
+
grid-column-start: <%= colum %>;
|
11
|
+
grid-column-end: <%= colum + 1 %>;
|
12
|
+
}
|
13
|
+
!, :OBJ => nil } }
|
14
|
+
|
15
|
+
module_function
|
16
|
+
|
17
|
+
def make_one_grid(hash, row, colum)
|
18
|
+
unless hash[:OBJ]
|
19
|
+
hash[:OBJ] = Tilt::ErubiTemplate.new { hash[:TEMPLATE] }
|
20
|
+
end
|
21
|
+
hash[:OBJ].render(Object.new, { row: row, colum: colum })
|
22
|
+
end
|
23
|
+
|
24
|
+
def make_grid(template_hash, scope, min_row, max_row, min_colum, max_colum)
|
25
|
+
(min_row..max_row).map { |row|
|
26
|
+
(min_colum..max_colum).map { |colum|
|
27
|
+
# puts "#{row} #{colum}"
|
28
|
+
value_hash = { row: row, colum: colum }
|
29
|
+
# make_one_grid(template_hash, value_hash)
|
30
|
+
# p template_hash
|
31
|
+
# p value_hash
|
32
|
+
Ykxutils::Erubyx::erubi_render(template_hash, scope, value_hash)
|
33
|
+
}
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def make_grid_list(min_row, max_row, min_colum, max_colum)
|
38
|
+
template_hash = TAMPLETES[:GRID_DEF]
|
39
|
+
scope = nil
|
40
|
+
make_grid(template_hash, scope, min_row, max_row, min_colum, max_colum)
|
41
|
+
end
|
42
|
+
|
43
|
+
def make_grid_list_x(min_row, max_row, min_colum, max_colum)
|
44
|
+
template_hash = TAMPLETES[:GRID_DEF]
|
45
|
+
scope = nil
|
46
|
+
make_grid(template_hash, scope, min_row, max_row, min_colum, max_colum)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Ykxutils
|
2
|
+
class Nginxconfig
|
3
|
+
def initialize(yaml_path)
|
4
|
+
# p "yaml_path=#{yaml_path}"
|
5
|
+
yaml_pn = Pathname.new(yaml_path).cleanpath
|
6
|
+
@virtual_domain_dir_pn = yaml_pn.parent
|
7
|
+
@server_dir_pn = @virtual_domain_dir_pn.parent
|
8
|
+
@common_dir_pn = @server_dir_pn.parent
|
9
|
+
@hash = YAML.load_file(yaml_pn)
|
10
|
+
# p @hash
|
11
|
+
@root = @hash["_root"]
|
12
|
+
# p @root
|
13
|
+
root_template_0_pn = Pathname.new(@root["template"]).cleanpath
|
14
|
+
@root_template_pn = @common_dir_pn + root_template_0_pn
|
15
|
+
# puts "@root_template_pn=#{@root_template_pn}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def extract(scope)
|
19
|
+
hashx = {}
|
20
|
+
@hash.each do |k, v|
|
21
|
+
if k !~ /^_/
|
22
|
+
# puts k
|
23
|
+
# puts v
|
24
|
+
pn = Pathname.new(v["template"]).cleanpath
|
25
|
+
# Pathname.new(v).cleanpath
|
26
|
+
template_pn = @server_dir_pn + pn
|
27
|
+
# puts(template_pn)
|
28
|
+
value_file_path_array = v["value"].map { |x|
|
29
|
+
@virtual_domain_dir_pn + Pathname.new(x).cleanpath
|
30
|
+
}
|
31
|
+
hashx[k] = Ykxutils::Erubyx::erubi_render_with_file(template_pn, scope, value_file_path_array)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
template = File.read(@root_template_pn)
|
35
|
+
template_hash = { TEMPLATE: template,
|
36
|
+
OBJ: nil }
|
37
|
+
Ykxutils::Erubyx::erubi_render(template_hash, scope, hashx)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'find'
|
2
|
+
require_relative 'nginxconfig'
|
3
|
+
|
4
|
+
module Ykxutils
|
5
|
+
class Nginxconfigfiles
|
6
|
+
def get_file_list(start_dir, re)
|
7
|
+
@file_list = []
|
8
|
+
|
9
|
+
Find.find(start_dir) { |x|
|
10
|
+
if x =~ re
|
11
|
+
# puts x
|
12
|
+
@file_list << x
|
13
|
+
Find.prune
|
14
|
+
end
|
15
|
+
}
|
16
|
+
@file_list
|
17
|
+
end
|
18
|
+
|
19
|
+
def output(file_list)
|
20
|
+
file_list.map { |fname|
|
21
|
+
parent_dir_pn = Pathname.new(fname).cleanpath.parent
|
22
|
+
vdomain = parent_dir_pn.basename
|
23
|
+
output_fname = "#{vdomain}.conf"
|
24
|
+
cli = ::Ykxutils::Nginxconfig.new(fname)
|
25
|
+
scope = nil
|
26
|
+
File.open(output_fname, "w") { |f|
|
27
|
+
x = cli.extract(scope)
|
28
|
+
f.write(x)
|
29
|
+
}
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/ykxutils/pstorex.rb
CHANGED
data/lib/ykxutils/version.rb
CHANGED
data/lib/ykxutils/yamlx.rb
CHANGED
@@ -3,66 +3,43 @@ require "yaml"
|
|
3
3
|
module Ykxutils
|
4
4
|
module_function
|
5
5
|
|
6
|
-
def
|
7
|
-
setting = {}
|
8
|
-
valid = false
|
6
|
+
def yaml_load_file_aliases(yaml_file_path, use_aliases: true)
|
9
7
|
begin
|
10
|
-
|
11
|
-
|
8
|
+
use_aliases ? YAML.load_file(yaml_file_path, aliases: true) : YAML.load_file(yaml_file_path)
|
9
|
+
value = 0
|
12
10
|
rescue ArgumentError
|
13
|
-
#
|
14
|
-
|
15
|
-
# p ex.inspect
|
16
|
-
# p ex.message
|
17
|
-
# p ex.backtrace
|
18
|
-
# exit#
|
11
|
+
# puts e.message
|
12
|
+
value = 1
|
19
13
|
rescue StandardError
|
20
|
-
#
|
21
|
-
|
22
|
-
# p ex.inspect
|
23
|
-
# p ex.message
|
24
|
-
# p ex.backtrace
|
14
|
+
# puts e.message
|
15
|
+
value = 2
|
25
16
|
end
|
17
|
+
value
|
18
|
+
end
|
26
19
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
# valid = true
|
31
|
-
rescue ArgumentError
|
32
|
-
# p "yaml_load_file_compat 2"
|
33
|
-
# p ex.class
|
34
|
-
# p ex.inspect
|
35
|
-
# p ex.message
|
36
|
-
# p ex.backtrace
|
37
|
-
#
|
38
|
-
rescue StandardError
|
39
|
-
# p "yaml_load_file_compat 2-2"
|
40
|
-
# p ex.class
|
41
|
-
# p ex.inspect
|
42
|
-
# p ex.message
|
43
|
-
# p ex.backtrace
|
44
|
-
end
|
45
|
-
end
|
20
|
+
def yaml_load_file_compati(yaml_file_path)
|
21
|
+
setting = yaml_load_file_aliases(yaml_file_path, use_aliases: true)
|
22
|
+
setting = yaml_load_file_aliases(yaml_file_path, use_aliases: false) if setting.nil?
|
46
23
|
setting
|
47
24
|
end
|
48
25
|
|
49
|
-
def
|
50
|
-
setting = {}
|
51
|
-
valid = false
|
26
|
+
def yaml_load_aliases(content, use_aliases: true)
|
52
27
|
begin
|
53
|
-
|
54
|
-
|
28
|
+
use_aliases ? YAML.safe_load(content, aliases: true) : YAML.safe_load(content)
|
29
|
+
value = 0
|
55
30
|
rescue ArgumentError
|
31
|
+
# puts e.message
|
32
|
+
value = 1
|
56
33
|
rescue StandardError
|
34
|
+
# puts e.message
|
35
|
+
value = 2
|
57
36
|
end
|
37
|
+
value
|
38
|
+
end
|
58
39
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
rescue ArgumentError
|
63
|
-
rescue StandardError
|
64
|
-
end
|
65
|
-
end
|
40
|
+
def yaml_load_compati(content)
|
41
|
+
setting = yaml_load_aliases(content, use_aliases: true)
|
42
|
+
setting = yaml_load_aliases(content, use_aliases: false) if setting.nil?
|
66
43
|
setting
|
67
44
|
end
|
68
45
|
end
|