generamba-udf 2.0.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.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +10 -0
  3. data/.gitignore +4 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +17 -0
  6. data/CHANGELOG.md +191 -0
  7. data/Gemfile +6 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +62 -0
  10. data/Rakefile +6 -0
  11. data/VISION.md +41 -0
  12. data/bin/console +14 -0
  13. data/bin/generamba +5 -0
  14. data/bin/setup +7 -0
  15. data/docs/2.x/roadmap.md +365 -0
  16. data/generamba-1.6.0.gem +0 -0
  17. data/generamba-2.0.0.gem +0 -0
  18. data/generamba.gemspec +38 -0
  19. data/lib/generamba/cli/cli.rb +16 -0
  20. data/lib/generamba/cli/gen_command.rb +119 -0
  21. data/lib/generamba/cli/setup_command.rb +127 -0
  22. data/lib/generamba/cli/setup_username_command.rb +21 -0
  23. data/lib/generamba/cli/template/template_create_command.rb +40 -0
  24. data/lib/generamba/cli/template/template_group.rb +14 -0
  25. data/lib/generamba/cli/template/template_install_command.rb +21 -0
  26. data/lib/generamba/cli/template/template_list_command.rb +25 -0
  27. data/lib/generamba/cli/template/template_search_command.rb +30 -0
  28. data/lib/generamba/cli/thor_extension.rb +47 -0
  29. data/lib/generamba/cli/version_command.rb +25 -0
  30. data/lib/generamba/code_generation/Rambafile.liquid +44 -0
  31. data/lib/generamba/code_generation/code_module.rb +123 -0
  32. data/lib/generamba/code_generation/content_generator.rb +43 -0
  33. data/lib/generamba/code_generation/module_template.rb +31 -0
  34. data/lib/generamba/code_generation/rambafile_generator.rb +23 -0
  35. data/lib/generamba/configuration/user_preferences.rb +50 -0
  36. data/lib/generamba/constants/constants.rb +12 -0
  37. data/lib/generamba/constants/rambafile_constants.rb +41 -0
  38. data/lib/generamba/constants/rambaspec_constants.rb +22 -0
  39. data/lib/generamba/constants/user_preferences_constants.rb +5 -0
  40. data/lib/generamba/helpers/dependency_checker.rb +54 -0
  41. data/lib/generamba/helpers/gen_command_table_parameters_formatter.rb +41 -0
  42. data/lib/generamba/helpers/module_info_generator.rb +35 -0
  43. data/lib/generamba/helpers/module_validator.rb +85 -0
  44. data/lib/generamba/helpers/print_table.rb +17 -0
  45. data/lib/generamba/helpers/rambafile_validator.rb +18 -0
  46. data/lib/generamba/helpers/template_helper.rb +30 -0
  47. data/lib/generamba/helpers/xcodeproj_helper.rb +262 -0
  48. data/lib/generamba/module_generator.rb +148 -0
  49. data/lib/generamba/template/creator/new_template/Code/Service/service.h.liquid +11 -0
  50. data/lib/generamba/template/creator/new_template/Code/Service/service.m.liquid +13 -0
  51. data/lib/generamba/template/creator/new_template/Tests/Service/service_tests.m.liquid +35 -0
  52. data/lib/generamba/template/creator/new_template/template.rambaspec.liquid +20 -0
  53. data/lib/generamba/template/creator/template_creator.rb +39 -0
  54. data/lib/generamba/template/helpers/catalog_downloader.rb +58 -0
  55. data/lib/generamba/template/helpers/catalog_template_list_helper.rb +23 -0
  56. data/lib/generamba/template/helpers/catalog_template_search_helper.rb +27 -0
  57. data/lib/generamba/template/helpers/catalog_terminator.rb +21 -0
  58. data/lib/generamba/template/helpers/rambaspec_validator.rb +52 -0
  59. data/lib/generamba/template/installer/abstract_installer.rb +9 -0
  60. data/lib/generamba/template/installer/catalog_installer.rb +73 -0
  61. data/lib/generamba/template/installer/local_installer.rb +32 -0
  62. data/lib/generamba/template/installer/remote_installer.rb +50 -0
  63. data/lib/generamba/template/installer/template_installer_factory.rb +22 -0
  64. data/lib/generamba/template/processor/template_declaration.rb +36 -0
  65. data/lib/generamba/template/processor/template_processor.rb +75 -0
  66. data/lib/generamba/tools/string-colorize.rb +23 -0
  67. data/lib/generamba/version.rb +5 -0
  68. data/lib/generamba.rb +16 -0
  69. metadata +288 -0
@@ -0,0 +1,21 @@
1
+ module Generamba::CLI
2
+ class SetupUsernameCommand < Thor
3
+
4
+ no_commands {
5
+ def setup_username
6
+ username = Generamba::UserPreferences.obtain_username
7
+ unless username
8
+ puts('The author name is not configured!'.red)
9
+ git_username = Git.init.config['user.name']
10
+ if git_username != nil && yes?("Your name in git is configured as #{git_username}. Do you want to use it in code headers? (yes/no)")
11
+ username = git_username
12
+ else
13
+ username = ask_non_empty_string('The author name which will be used in the headers:', 'User name should not be empty')
14
+ end
15
+ Generamba::UserPreferences.save_username(username)
16
+ end
17
+
18
+ end
19
+ }
20
+ end
21
+ end
@@ -0,0 +1,40 @@
1
+ require 'generamba/helpers/print_table.rb'
2
+
3
+ module Generamba::CLI
4
+ class Template < Thor
5
+ include Generamba
6
+
7
+ desc 'create [TEMPLATE_NAME]', 'Creates a new Generamba template with a given name'
8
+ def create(template_name)
9
+ summary = ask('The brief description of your new template:')
10
+ author = ask('Who is the author of this template:')
11
+ license = ask('What license will be used (e.g. MIT):')
12
+
13
+ has_dependencies = yes?('Will your template contain any third-party dependencies (available via Cocoapods or Carthage)? (yes/no)')
14
+ if has_dependencies
15
+ dependencies = ask_loop('Enter the name of your dependency (empty string to stop):')
16
+ end
17
+
18
+ properties = {
19
+ TEMPLATE_NAME_KEY => template_name,
20
+ TEMPLATE_SUMMARY_KEY => summary,
21
+ TEMPLATE_AUTHOR_KEY => author,
22
+ TEMPLATE_LICENSE_KEY => license
23
+ }
24
+
25
+ if dependencies and !dependencies.empty?
26
+ properties[TEMPLATE_DEPENDENCIES_KEY] = dependencies
27
+ end
28
+
29
+ PrintTable.print_values(
30
+ values: properties,
31
+ title: "Summary for template create"
32
+ )
33
+
34
+ template_creator = Generamba::TemplateCreator.new
35
+ template_creator.create_template(properties)
36
+ puts("The template #{template_name} is successfully generated! Now add some file templates into it.".green)
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,14 @@
1
+ require 'generamba/cli/template/template_install_command.rb'
2
+ require 'generamba/cli/template/template_create_command.rb'
3
+ require 'generamba/cli/template/template_list_command.rb'
4
+ require 'generamba/cli/template/template_search_command.rb'
5
+
6
+ module Generamba::CLI
7
+ class Application < Thor
8
+ register(Generamba::CLI::Template, 'template', 'template <command>', 'Provides a set of commands for working with templates')
9
+ end
10
+
11
+ class Template < Thor
12
+
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ module Generamba::CLI
2
+ class Template < Thor
3
+
4
+ desc 'install', 'Installs all the templates specified in the Rambafile from the current directory'
5
+ def install
6
+ does_rambafile_exist = Dir[RAMBAFILE_NAME].count > 0
7
+
8
+ unless does_rambafile_exist
9
+ puts('Rambafile not found! Run `generamba setup` in the working directory instead!'.red)
10
+ return
11
+ end
12
+
13
+ catalog_downloader = Generamba::CatalogDownloader.new
14
+ installer_factory = Generamba::TemplateInstallerFactory.new
15
+ template_processor = Generamba::TemplateProcessor.new(catalog_downloader, installer_factory)
16
+
17
+ rambafile = YAML.load_file(RAMBAFILE_NAME)
18
+ template_processor.install_templates(rambafile)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ require 'generamba/template/helpers/catalog_downloader'
2
+ require 'generamba/template/helpers/catalog_template_list_helper'
3
+
4
+ module Generamba::CLI
5
+ class Template < Thor
6
+ include Generamba
7
+
8
+ desc 'list', 'Prints out the list of all templates available in the shared GitHub catalog'
9
+ def list
10
+ downloader = CatalogDownloader.new
11
+ catalog_template_list_helper = CatalogTemplateListHelper.new
12
+
13
+ templates = []
14
+ catalog_paths = downloader.update_all_catalogs_and_return_filepaths
15
+ catalog_paths.each do |path|
16
+ templates += catalog_template_list_helper.obtain_all_templates_from_a_catalog(path)
17
+ templates = templates.uniq
18
+ end
19
+
20
+ templates.each do |template_name|
21
+ puts(template_name)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,30 @@
1
+ require 'generamba/template/helpers/catalog_downloader.rb'
2
+ require 'generamba/template/helpers/catalog_template_search_helper'
3
+
4
+ module Generamba::CLI
5
+ class Template < Thor
6
+ include Generamba
7
+
8
+ desc 'search [SEARCH_STRING]', 'Searches a template with a given name in the shared GitHub catalog'
9
+ def search(term)
10
+ downloader = CatalogDownloader.new
11
+ catalog_template_search_helper = CatalogTemplateSearchHelper.new
12
+
13
+ catalog_paths = downloader.update_all_catalogs_and_return_filepaths
14
+
15
+ templates = []
16
+ catalog_paths.each do |path|
17
+ templates += catalog_template_search_helper.search_templates_in_a_catalog(path, term)
18
+ templates = templates.uniq
19
+ end
20
+
21
+ templates.map { |template_name|
22
+ keywords = term.squeeze.strip.split(' ').compact.uniq
23
+ matcher = Regexp.new('(' + keywords.join('|') + ')')
24
+ template_name.gsub(matcher) { |match| "#{match}".yellow }
25
+ }.each { |template_name|
26
+ puts(template_name)
27
+ }
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,47 @@
1
+ require 'thor'
2
+
3
+ module Generamba::CLI
4
+ class ::Thor
5
+ no_commands do
6
+ def ask_index(message, array)
7
+ value_index = ask_with_validation(message,->(value){ (value.to_i >= 0 and value.to_i < array.count) },"Invalid selection. Please enter number from 0 to #{array.count-1}")
8
+ return array[value_index.to_i]
9
+ end
10
+
11
+ def ask_non_empty_string(message, description = 'Value should be nonempty string')
12
+ return ask_with_validation(message,->(value){value.length > 0 },description)
13
+ end
14
+
15
+ def ask_loop(message)
16
+ array = Array.new
17
+ loop do
18
+ value = ask(message)
19
+ break if value.empty?
20
+ array.push(value)
21
+ end
22
+ return array
23
+ end
24
+
25
+ def ask_with_validation(message, is_valid_value, description = 'Invalid value')
26
+ loop do
27
+ value = ask(message)
28
+ return value if is_valid_value.call(value)
29
+ puts(description.red)
30
+ end
31
+ end
32
+
33
+ def ask_file_with_path(pattern, message_file_name)
34
+ project_files = Dir[pattern]
35
+ count = project_files.count
36
+ default_message = "The path to a #{message_file_name}:"
37
+ if count == 1
38
+ is_right_path = yes?"The path to a #{message_file_name} is '#{project_files[0]}'. Do you want to use it? (yes/no)"
39
+ xcode_path = is_right_path ? project_files[0] : ask(default_message)
40
+ else
41
+ xcode_path = ask(default_message)
42
+ end
43
+ return xcode_path
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,25 @@
1
+ require 'thor'
2
+ require 'generamba/version.rb'
3
+
4
+ module Generamba::CLI
5
+ class Application < Thor
6
+ include Generamba
7
+
8
+ desc 'version', 'Prints out Generamba current version'
9
+ def version
10
+ options = {}
11
+ options['Version'] = Generamba::VERSION.green
12
+ options['Release date'] = Generamba::RELEASE_DATE.green
13
+ options['Change notes'] = Generamba::RELEASE_LINK.green
14
+
15
+ values = []
16
+
17
+ options.each do |title, value|
18
+ values.push("#{title}: #{value}")
19
+ end
20
+
21
+ output = values.join("\n")
22
+ puts(output)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,44 @@
1
+ ### Headers settings
2
+ company: {{ company }}
3
+
4
+ ### Xcode project settings
5
+ project_name: {{ project_name }}
6
+ xcodeproj_path: {{ xcodeproj_path }}
7
+ {% if prefix != "" %}prefix: {{ prefix }}{% endif %}
8
+
9
+ {% if (project_target != nil and project_target != "") or (project_file_path != nil and project_file_path != "") or (project_group_path != nil and project_group_path != "") %}### Code generation settings section
10
+ {% if project_target != nil and project_target != "" %}# The main project target name
11
+ project_target: {{ project_target }}{% endif %}
12
+
13
+ {% if project_file_path != nil and project_file_path != "" %}# The file path for new modules
14
+ project_file_path: {{ project_file_path }}{% endif %}
15
+
16
+ {% if project_group_path != nil and project_group_path != "" %}# The Xcode group path to new modules
17
+ project_group_path: {{ project_group_path }}{% endif %}
18
+ {% endif %}
19
+
20
+ {% if (test_target != nil and test_target != "") or (test_file_path != nil and test_file_path != "") or (test_group_path != nil and test_group_path != "") %}### Tests generation settings section
21
+ {% if test_target != nil and test_target != "" %}# The tests target name
22
+ test_target: {{ test_target }}{% endif %}
23
+
24
+ {% if test_file_path != nil and test_file_path != "" %}# The file path for new tests
25
+ test_file_path: {{ test_file_path }}{% endif %}
26
+
27
+ {% if test_group_path != nil and test_group_path != "" %}# The Xcode group path to new tests
28
+ test_group_path: {{ test_group_path }}{% endif %}
29
+ {% endif %}
30
+
31
+ {% if create_logical_groups != nil and create_logical_groups %}# Create Groups in Xcode without folders in filesystem
32
+ create_logical_groups: {{ create_logical_groups }} {% endif %}
33
+
34
+ {% if podfile_path != nil or cartfile_path != nil %}### Dependencies settings section{% endif %}
35
+ {% if podfile_path != nil %}podfile_path: {{ podfile_path }}{% endif %}
36
+ {% if cartfile_path != nil %}cartfile_path: {{ cartfile_path }}{% endif %}
37
+
38
+ ### Templates
39
+ templates:
40
+ {% if templates.size > 0 %}{% for item in templates %}- {{ item }}
41
+ {% endfor %}{% else %}#- {name: local_template_name, local: 'absolute/file/path'}
42
+ #- {name: remote_template_name, git: 'https://github.com/igrekde/remote_template'}
43
+ #- {name: catalog_template_name}
44
+ {% endif %}
@@ -0,0 +1,123 @@
1
+ module Generamba
2
+
3
+ SLASH_REGEX = /^\/|\/$/
4
+ C99IDENTIFIER = /[^\w]/
5
+
6
+ PATH_TYPE_PROJECT = 'project'
7
+ PATH_TYPE_TEST = 'test'
8
+
9
+ # Represents currently generating code module
10
+ class CodeModule
11
+ attr_reader :name,
12
+ :description,
13
+ :author,
14
+ :company,
15
+ :year,
16
+ :prefix,
17
+ :project_name,
18
+ :product_module_name,
19
+ :xcodeproj_path,
20
+ :project_file_path,
21
+ :project_file_root,
22
+ :project_group_path,
23
+ :test_file_path,
24
+ :test_file_root,
25
+ :test_group_path,
26
+ :project_targets,
27
+ :test_targets,
28
+ :podfile_path,
29
+ :cartfile_path,
30
+ :custom_parameters,
31
+ :create_logical_groups,
32
+ :test_unit_target,
33
+ :test_unit_path,
34
+ :test_unit_testable_import,
35
+ :test_snapshot_target,
36
+ :test_snapshot_path,
37
+ :test_snapshot_testable_import
38
+
39
+ def initialize(name, rambafile, options)
40
+ # Base initialization
41
+ @name = name
42
+ @description = options[:description] ? options[:description] : "#{name} module"
43
+ @author = rambafile[AUTHOR_NAME_KEY] ? rambafile[AUTHOR_NAME_KEY] : UserPreferences.obtain_username
44
+ @company = rambafile[COMPANY_KEY]
45
+ @year = Time.now.year.to_s
46
+
47
+ @prefix = rambafile[PROJECT_PREFIX_KEY]
48
+ @project_name = rambafile[PROJECT_NAME_KEY]
49
+
50
+ @product_module_name = rambafile[PRODUCT_MODULE_NAME_KEY]
51
+ @product_module_name = @project_name.gsub(C99IDENTIFIER, '_') if !@product_module_name && @project_name
52
+
53
+ @xcodeproj_path = rambafile[XCODEPROJ_PATH_KEY]
54
+
55
+ setup_file_and_group_paths(rambafile[PROJECT_FILE_PATH_KEY], rambafile[PROJECT_GROUP_PATH_KEY], PATH_TYPE_PROJECT)
56
+ setup_file_and_group_paths(rambafile[TEST_FILE_PATH_KEY], rambafile[TEST_GROUP_PATH_KEY], PATH_TYPE_TEST)
57
+
58
+ @create_logical_groups = rambafile[CREATE_LOGICAL_GROUPS_KEY] if rambafile[CREATE_LOGICAL_GROUPS_KEY]
59
+ if create_logical_groups
60
+ @project_file_root = Pathname.new(rambafile[PROJECT_FILE_PATH_KEY])
61
+ @test_file_root = Pathname.new(rambafile[TEST_FILE_PATH_KEY])
62
+ end
63
+
64
+ @project_targets = [rambafile[PROJECT_TARGET_KEY]] if rambafile[PROJECT_TARGET_KEY]
65
+ @project_targets = rambafile[PROJECT_TARGETS_KEY] if rambafile[PROJECT_TARGETS_KEY]
66
+
67
+ @test_targets = [rambafile[TEST_TARGET_KEY]] if rambafile[TEST_TARGET_KEY]
68
+ @test_targets = rambafile[TEST_TARGETS_KEY] if rambafile[TEST_TARGETS_KEY]
69
+
70
+ @test_unit_target = rambafile[TEST_UNIT_TARGET_KEY] if rambafile[TEST_UNIT_TARGET_KEY]
71
+ @test_unit_path = Pathname.new(rambafile[TEST_UNIT_PATH_KEY]).join(@name) if rambafile[TEST_UNIT_PATH_KEY]
72
+ @test_unit_testable_import = rambafile[TEST_UNIT_TESTABLE_IMPORT] if rambafile[TEST_UNIT_TESTABLE_IMPORT]
73
+
74
+ @test_snapshot_target = rambafile[TEST_SNAPSHOT_TARGET_KEY] if rambafile[TEST_SNAPSHOT_TARGET_KEY]
75
+ @test_snapshot_path = Pathname.new(rambafile[TEST_SNAPSHOT_PATH_KEY]) if rambafile[TEST_SNAPSHOT_PATH_KEY]
76
+ @test_snapshot_testable_import = rambafile[TEST_SNAPSHOT_TESTABLE_IMPORT] if rambafile[TEST_SNAPSHOT_TESTABLE_IMPORT]
77
+
78
+ # Custom parameters
79
+ @custom_parameters = options[:custom_parameters]
80
+
81
+ # Options adaptation
82
+ @author = options[:author] if options[:author]
83
+ @project_targets = options[:project_targets].split(',') if options[:project_targets]
84
+ @test_targets = options[:test_targets].split(',') if options[:test_targets]
85
+
86
+ setup_file_and_group_paths(options[:project_file_path], options[:project_group_path], PATH_TYPE_PROJECT)
87
+ setup_file_and_group_paths(options[:test_file_path], options[:test_group_path], PATH_TYPE_TEST)
88
+
89
+ # The priority is given to `module_path` and 'test_path' options
90
+ setup_file_and_group_paths(options[:module_path], options[:module_path], PATH_TYPE_PROJECT)
91
+ setup_file_and_group_paths(options[:test_path], options[:test_path], PATH_TYPE_TEST)
92
+
93
+ @podfile_path = rambafile[PODFILE_PATH_KEY] if rambafile[PODFILE_PATH_KEY]
94
+ @cartfile_path = rambafile[CARTFILE_PATH_KEY] if rambafile[CARTFILE_PATH_KEY]
95
+ end
96
+
97
+ private
98
+
99
+ def setup_file_and_group_paths(file_path, group_path, path_type)
100
+ if file_path || group_path
101
+ variable_name = "#{path_type}_file_path"
102
+
103
+ if file_path || !instance_variable_get("@#{variable_name}")
104
+ file_path = group_path unless file_path
105
+
106
+ variable_value = file_path.gsub(SLASH_REGEX, '')
107
+ variable_value = Pathname.new(variable_value).join(@name)
108
+ instance_variable_set("@#{variable_name}", variable_value)
109
+ end
110
+
111
+ variable_name = "#{path_type}_group_path"
112
+
113
+ if group_path || !instance_variable_get("@#{variable_name}")
114
+ group_path = file_path unless group_path
115
+
116
+ variable_value = group_path.gsub(SLASH_REGEX, '')
117
+ variable_value = Pathname.new(variable_value).join(@name)
118
+ instance_variable_set("@#{variable_name}", variable_value)
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,43 @@
1
+ require 'liquid'
2
+
3
+ module Generamba
4
+
5
+ # Responsible for generating code using provided liquid templates
6
+ class ContentGenerator
7
+
8
+ # Generates and returns a filename and a body of a specific code file.
9
+ # @param file [Hash<String,String>] A hashmap with template's filename and filepath
10
+ # @param scope [Hash<String,String>] A hashmap with module info
11
+ # @param template [ModuleTemplate] The model describing a Generamba template used for code generation
12
+ #
13
+ # @return [String], [String] The generated file_name and body
14
+ def self.create_file(file, scope, template)
15
+ file_source = IO.read(template.template_path.join(file[TEMPLATE_FILE_PATH_KEY]))
16
+ Liquid::Template.file_system = Liquid::LocalFileSystem.new(template.template_path.join('snippets'), '%s.liquid')
17
+
18
+ template = Liquid::Template.parse(file_source)
19
+ filename_template = self.file_name_template(file)
20
+
21
+ file_basename = File.basename(file[TEMPLATE_FILE_NAME_KEY])
22
+
23
+ module_info = scope['module_info']
24
+
25
+ module_info['file_basename'] = file_basename
26
+
27
+ file_name = filename_template.render(scope)
28
+
29
+ module_info['file_name'] = file_name
30
+ module_info.delete('file_basename')
31
+
32
+ content = template.render(scope)
33
+
34
+ return file_name, content
35
+ end
36
+
37
+ def self.file_name_template(file)
38
+ template_default_text = '{{ prefix }}{{ module_info.name }}{{ module_info.file_basename }}'
39
+ template_text = file[TEMPLATE_FILE_CUSTOM_NAME_KEY] || template_default_text
40
+ return Liquid::Template.parse(template_text)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,31 @@
1
+ require 'generamba/helpers/template_helper.rb'
2
+
3
+ module Generamba
4
+
5
+ # Represents a single Generamba module template
6
+ class ModuleTemplate
7
+ attr_reader :template_name, :template_path, :code_files, :test_files, :test_unit_files, :test_snapshot_files, :dependencies
8
+
9
+ def initialize(name, options = nil)
10
+ spec_path = TemplateHelper.obtain_spec(name)
11
+
12
+ unless options
13
+ spec = YAML.load_file(spec_path)
14
+ else
15
+ spec_source = IO.read(spec_path)
16
+ spec_template = Liquid::Template.parse(spec_source)
17
+ spec_content = spec_template.render(options)
18
+ spec = YAML.load(spec_content)
19
+ end
20
+
21
+ @code_files = spec[TEMPLATE_CODE_FILES_KEY]
22
+ @test_files = spec[TEMPLATE_TEST_FILES_KEY]
23
+ @test_unit_files = spec[TEMPLATE_TEST_UNIT_FILES_KEY] if spec[TEMPLATE_TEST_UNIT_FILES_KEY]
24
+ @test_snapshot_files = spec[TEMPLATE_TEST_SNAPSHOT_FILES_KEY] if spec[TEMPLATE_TEST_SNAPSHOT_FILES_KEY]
25
+
26
+ @template_name = spec[TEMPLATE_NAME_KEY]
27
+ @template_path = TemplateHelper.obtain_path(name)
28
+ @dependencies = spec[TEMPLATE_DEPENDENCIES_KEY]
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,23 @@
1
+ require 'liquid'
2
+
3
+ module Generamba
4
+
5
+ # Responsible for creating Generamba configs
6
+ class RambafileGenerator
7
+
8
+ # Creates a Rambafile using the provided properties hashmap
9
+ # @param properties Rambafile properties
10
+ #
11
+ # @return void
12
+ def self.create_rambafile(properties)
13
+ file_source = IO.read(File.dirname(__FILE__) + '/Rambafile.liquid')
14
+
15
+ template = Liquid::Template.parse(file_source)
16
+ output = template.render(properties).gsub!(/[\n]{3,}/, "\n\n");
17
+
18
+ File.open(RAMBAFILE_NAME, 'w+') {|f|
19
+ f.write(output)
20
+ }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,50 @@
1
+ require 'generamba/constants/user_preferences_constants.rb'
2
+
3
+ module Generamba
4
+
5
+ # A class that provides methods for working with user-specific information.
6
+ # Currently it has methods for obtaining and saving username, later it may be improved to something more general.
7
+ class UserPreferences
8
+
9
+ def self.obtain_username
10
+ path = obtain_user_preferences_path
11
+
12
+ file_contents = open(path).read
13
+ preferences = file_contents.empty? ? {} : YAML.load(file_contents).to_hash
14
+
15
+ return preferences[USERNAME_KEY]
16
+ end
17
+
18
+ def self.save_username(username)
19
+ path = obtain_user_preferences_path
20
+
21
+ file_contents = open(path).read
22
+ preferences = file_contents.empty? ? {} : YAML.load(file_contents).to_hash
23
+
24
+ preferences[USERNAME_KEY] = username
25
+ File.open(path, 'w+') { |f| f.write(preferences.to_yaml) }
26
+ end
27
+
28
+ private
29
+
30
+ def self.obtain_user_preferences_path
31
+ home_path = Pathname.new(ENV['HOME'])
32
+ .join(GENERAMBA_HOME_DIR)
33
+
34
+ path_exists = Dir.exist?(home_path)
35
+
36
+ unless path_exists
37
+ FileUtils.mkdir_p home_path
38
+ end
39
+
40
+ preferences_path = home_path.join(USER_PREFERENCES_FILE)
41
+ preferences_exist = File.file?(preferences_path)
42
+
43
+ unless preferences_exist
44
+ File.open(preferences_path, 'w+') { |f| f.write('') }
45
+ end
46
+
47
+ return preferences_path
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,12 @@
1
+ module Generamba
2
+
3
+ # General constants
4
+ RAMBAFILE_NAME = 'Rambafile'
5
+ RAMBASPEC_EXTENSION = '.rambaspec'
6
+ TEMPLATES_FOLDER = 'Templates'
7
+ RAMBLER_CATALOG_REPO = 'https://github.com/rambler-digital-solutions/generamba-catalog'
8
+ GENERAMBA_CATALOG_NAME = 'generamba-catalog'
9
+ GENERAMBA_HOME_DIR = '.generamba'
10
+ CATALOGS_DIR = 'catalogs'
11
+ USER_PREFERENCES_FILE = 'user_preferences.yml'
12
+ end
@@ -0,0 +1,41 @@
1
+ module Generamba
2
+
3
+ # Keys of Rambafile files
4
+ COMPANY_KEY = 'company'
5
+ AUTHOR_NAME_KEY = 'author'
6
+ PROJECT_NAME_KEY = 'project_name'
7
+ PROJECT_PREFIX_KEY = 'prefix'
8
+ XCODEPROJ_PATH_KEY = 'xcodeproj_path'
9
+
10
+ PROJECT_TARGET_KEY = 'project_target'
11
+ PROJECT_TARGETS_KEY = 'project_targets'
12
+ PROJECT_FILE_PATH_KEY = 'project_file_path'
13
+ PROJECT_GROUP_PATH_KEY = 'project_group_path'
14
+
15
+ PRODUCT_MODULE_NAME_KEY = 'product_module_name'
16
+
17
+ TEST_TARGET_KEY = 'test_target'
18
+ TEST_TARGETS_KEY = 'test_targets'
19
+ TEST_FILE_PATH_KEY = 'test_file_path'
20
+ TEST_GROUP_PATH_KEY = 'test_group_path'
21
+
22
+ TEST_UNIT_TARGET_KEY = 'test_unit_target'
23
+ TEST_UNIT_PATH_KEY = 'test_unit_path'
24
+ TEST_UNIT_TESTABLE_IMPORT = 'test_unit_testable_import'
25
+
26
+ TEST_SNAPSHOT_TARGET_KEY = 'test_snapshot_target'
27
+ TEST_SNAPSHOT_PATH_KEY = 'test_snapshot_path'
28
+ TEST_SNAPSHOT_TESTABLE_IMPORT = 'test_snapshot_testable_import'
29
+
30
+ PODFILE_PATH_KEY = 'podfile_path'
31
+ CARTFILE_PATH_KEY = 'cartfile_path'
32
+
33
+ CREATE_LOGICAL_GROUPS_KEY = 'create_logical_groups'
34
+
35
+ CATALOGS_KEY = 'catalogs'
36
+ TEMPLATES_KEY = 'templates'
37
+ TEMPLATE_DECLARATION_NAME_KEY = 'name'
38
+ TEMPLATE_DECLARATION_LOCAL_KEY = 'local'
39
+ TEMPLATE_DECLARATION_GIT_KEY = 'git'
40
+ TEMPLATE_DECLARATION_BRANCH_KEY = 'branch'
41
+ end
@@ -0,0 +1,22 @@
1
+ module Generamba
2
+
3
+ # Keys of .rambaspec files
4
+ TEMPLATE_NAME_KEY = 'name'
5
+ TEMPLATE_SUMMARY_KEY = 'summary'
6
+ TEMPLATE_AUTHOR_KEY = 'author'
7
+ TEMPLATE_VERSION_KEY = 'version'
8
+ TEMPLATE_LICENSE_KEY = 'license'
9
+
10
+ TEMPLATE_CODE_FILES_KEY = 'code_files'
11
+ TEMPLATE_TEST_FILES_KEY = 'test_files'
12
+
13
+ TEMPLATE_TEST_UNIT_FILES_KEY = 'test_unit_files'
14
+ TEMPLATE_TEST_SNAPSHOT_FILES_KEY = 'test_snapshot_files'
15
+
16
+ TEMPLATE_FILE_NAME_KEY = 'name'
17
+ TEMPLATE_FILE_CUSTOM_NAME_KEY = 'custom_name'
18
+ TEMPLATE_FILE_PATH_KEY = 'path'
19
+ TEMPLATE_FILE_IS_RESOURCE_KEY = 'is_resource'
20
+
21
+ TEMPLATE_DEPENDENCIES_KEY = 'dependencies'
22
+ end
@@ -0,0 +1,5 @@
1
+ module Generamba
2
+
3
+ # Keys of file user_preferences.yml
4
+ USERNAME_KEY = 'username'
5
+ end