viperaptor 2.0.2 → 2.1.0
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/lib/viperaptor/code_generation/content_generator.rb +6 -1
- data/lib/viperaptor/code_generation/module_template.rb +36 -1
- data/lib/viperaptor/constants/rambaspec_constants.rb +1 -0
- data/lib/viperaptor/module_generator.rb +1 -0
- data/lib/viperaptor/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f58922aa6f479200b1c9099a373bed766afdb88d9beaea7be8ea508a85b71440
|
4
|
+
data.tar.gz: 8d9e4a20456d7f2c675269b4574e72ce27dc5ca2f86d629a7895d65cbcaeb0e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb3a10779f5e0dfb0edc9d83a7114fe4a43c8baa5ca507b882c09f006fcda61986264e8aae8a480ddd91946f863b527d4bbe075c6579ae61a2371b4299924860
|
7
|
+
data.tar.gz: 838bc157c71d2216fe479db47af6a20349b5b4dd15ac9e240491053de314b5c78e6e6ee7a72eb4e9f854de8c5b4bed52558b4967c88f100f39e58f1648361f88
|
@@ -9,9 +9,14 @@ module Viperaptor
|
|
9
9
|
# @param file [Hash<String,String>] A hashmap with template's filename and filepath
|
10
10
|
# @param scope [Hash<String,String>] A hashmap with module info
|
11
11
|
# @param template [ModuleTemplate] The model describing a Viperaptor template used for code generation
|
12
|
+
# @param variables [Hash<String,String>] Custom variables of template
|
12
13
|
#
|
13
14
|
# @return [String], [String] The generated file_name and body
|
14
15
|
def self.create_file(file, scope, template)
|
16
|
+
|
17
|
+
custom_parameters = template.custom_parameters
|
18
|
+
scope['custom_parameters'] = (scope['custom_parameters'] || {}).merge(custom_parameters)
|
19
|
+
|
15
20
|
file_source = IO.read(template.template_path.join(file[TEMPLATE_FILE_PATH_KEY]))
|
16
21
|
Liquid::Template.file_system = Liquid::LocalFileSystem.new(template.template_path.join('snippets'), '%s.liquid')
|
17
22
|
|
@@ -21,7 +26,7 @@ module Viperaptor
|
|
21
26
|
file_basename = File.basename(file[TEMPLATE_FILE_NAME_KEY])
|
22
27
|
|
23
28
|
module_info = scope['module_info']
|
24
|
-
|
29
|
+
|
25
30
|
module_info['file_basename'] = file_basename
|
26
31
|
|
27
32
|
file_name = filename_template.render(scope)
|
@@ -1,10 +1,37 @@
|
|
1
1
|
require 'viperaptor/helpers/template_helper.rb'
|
2
|
+
require "tty-prompt"
|
2
3
|
|
3
4
|
module Viperaptor
|
4
5
|
|
5
6
|
# Represents a single Viperaptor module template
|
6
7
|
class ModuleTemplate
|
7
|
-
attr_reader :template_name, :template_path, :code_files, :test_files, :dependencies
|
8
|
+
attr_reader :template_name, :template_path, :code_files, :test_files, :dependencies, :custom_parameters
|
9
|
+
|
10
|
+
def load_variables_from_spec(spec)
|
11
|
+
custom_parameters = spec[TEMPLATE_CUSTOM_PARAMETERS_KEY]
|
12
|
+
@custom_parameters = {}
|
13
|
+
unless custom_parameters.nil?
|
14
|
+
custom_parameters.sort_by { |a| (a['order'] || 0) }.map do |desc|
|
15
|
+
if desc["type"].is_a?(Array)
|
16
|
+
prompt = TTY::Prompt.new
|
17
|
+
choices = desc["type"]
|
18
|
+
value = prompt.select("Select #{desc["description"]}?", choices, per_page: choices.count)
|
19
|
+
@custom_parameters[desc["name"]] = value
|
20
|
+
elsif desc["type"] == 'boolean'
|
21
|
+
prompt = TTY::Prompt.new
|
22
|
+
value = prompt.yes?("#{desc["description"]}?")
|
23
|
+
@custom_parameters[desc["name"]] = value
|
24
|
+
elsif desc["type"] == 'text'
|
25
|
+
prompt = TTY::Prompt.new
|
26
|
+
value = prompt.ask("#{desc["description"]}?")
|
27
|
+
@custom_parameters[desc["name"]] = value
|
28
|
+
else
|
29
|
+
puts("ERROR: Invalid variable type of template custom parameter '#{desc['name']}'".red)
|
30
|
+
exit(1)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
8
35
|
|
9
36
|
def initialize(name, options = nil)
|
10
37
|
spec_path = TemplateHelper.obtain_spec(name)
|
@@ -18,6 +45,14 @@ module Viperaptor
|
|
18
45
|
spec = YAML.load(spec_content)
|
19
46
|
end
|
20
47
|
|
48
|
+
load_variables_from_spec(spec)
|
49
|
+
if !@custom_parameters.empty? && !options.nil?
|
50
|
+
spec_source = IO.read(spec_path)
|
51
|
+
spec_template = Liquid::Template.parse(spec_source)
|
52
|
+
spec_content = spec_template.render(options.merge(@custom_parameters))
|
53
|
+
spec = YAML.load(spec_content)
|
54
|
+
end
|
55
|
+
|
21
56
|
@code_files = spec[TEMPLATE_CODE_FILES_KEY]
|
22
57
|
@test_files = spec[TEMPLATE_TEST_FILES_KEY]
|
23
58
|
@template_name = spec[TEMPLATE_NAME_KEY]
|
@@ -13,6 +13,7 @@ module Viperaptor
|
|
13
13
|
TEMPLATE_FILE_CUSTOM_NAME_KEY = 'custom_name'
|
14
14
|
TEMPLATE_FILE_PATH_KEY = 'path'
|
15
15
|
TEMPLATE_FILE_IS_RESOURCE_KEY = 'is_resource'
|
16
|
+
TEMPLATE_CUSTOM_PARAMETERS_KEY = 'custom_parameters'
|
16
17
|
|
17
18
|
TEMPLATE_DEPENDENCIES_KEY = 'dependencies'
|
18
19
|
end
|
data/lib/viperaptor/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: viperaptor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Siarhei Ladzeika
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01
|
11
|
+
date: 2021-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|