viperaptor 2.0.2 → 2.1.0

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: '05568a147ce6c94c0129756da124fbcdcccd0adadeda98470f8d74e7e6593e27'
4
- data.tar.gz: c4e0440b2aa1cddafc1ca301ecb5097bef675bace8d3819bdd76f3e8d90766c1
3
+ metadata.gz: f58922aa6f479200b1c9099a373bed766afdb88d9beaea7be8ea508a85b71440
4
+ data.tar.gz: 8d9e4a20456d7f2c675269b4574e72ce27dc5ca2f86d629a7895d65cbcaeb0e6
5
5
  SHA512:
6
- metadata.gz: 5208926beb1bab564491ddea68e61aa46a96091308491906e8df816a0da5b2f8709dbd1a86c10eaf26bc6c524d6df489198c5f1a9c1ea7f7928e2ee56116751d
7
- data.tar.gz: 2ae41d53a65ae9066ef1fd2b47113cc68c52d2485a88709c27da64548eea5bee8249142deb4f775e6ce52629f1702162b544a4b211ed33a5b135c5743d4a9155
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
@@ -9,6 +9,7 @@ module Viperaptor
9
9
  class ModuleGenerator
10
10
 
11
11
  def generate_module(name, code_module, template)
12
+
12
13
  # Setting up Xcode objects
13
14
  project = XcodeprojHelper.obtain_project(code_module.xcodeproj_path)
14
15
 
@@ -1,5 +1,5 @@
1
1
  module Viperaptor
2
- VERSION = '2.0.2'
3
- RELEASE_DATE = '29.01.2021'
2
+ VERSION = '2.1.0'
3
+ RELEASE_DATE = '01.02.2021'
4
4
  RELEASE_LINK = "https://github.com/ladeiko/Viperaptor/releases/tag/#{VERSION}"
5
5
  end
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.2
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-29 00:00:00.000000000 Z
11
+ date: 2021-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor