Class: Generamba::CLI::Template
- Inherits:
-
Thor
- Object
- Thor
- Generamba::CLI::Template
show all
- Includes:
- Generamba
- Defined in:
- lib/generamba/cli/template/template_group.rb,
lib/generamba/cli/template/template_list_command.rb,
lib/generamba/cli/template/template_create_command.rb,
lib/generamba/cli/template/template_search_command.rb,
lib/generamba/cli/template/template_install_command.rb
Constant Summary
Constants included
from Generamba
AUTHOR_NAME_KEY, Generamba::C99IDENTIFIER, Generamba::CARTFILE_PATH_KEY, Generamba::CATALOGS_DIR, Generamba::CATALOGS_KEY, Generamba::COMPANY_KEY, GENERAMBA_CATALOG_NAME, GENERAMBA_HOME_DIR, PATH_TYPE_PROJECT, PATH_TYPE_TEST, PODFILE_PATH_KEY, PRODUCT_MODULE_NAME_KEY, PROJECT_FILE_PATH_KEY, PROJECT_GROUP_PATH_KEY, PROJECT_NAME_KEY, PROJECT_PREFIX_KEY, PROJECT_TARGETS_KEY, PROJECT_TARGET_KEY, RAMBAFILE_NAME, RAMBASPEC_EXTENSION, RAMBLER_CATALOG_REPO, RELEASE_DATE, RELEASE_LINK, SLASH_REGEX, TEMPLATES_FOLDER, TEMPLATES_KEY, TEMPLATE_AUTHOR_KEY, TEMPLATE_CODE_FILES_KEY, TEMPLATE_DECLARATION_BRANCH_KEY, TEMPLATE_DECLARATION_GIT_KEY, TEMPLATE_DECLARATION_LOCAL_KEY, TEMPLATE_DECLARATION_NAME_KEY, TEMPLATE_DEPENDENCIES_KEY, TEMPLATE_FILE_CUSTOM_NAME_KEY, TEMPLATE_FILE_IS_RESOURCE_KEY, TEMPLATE_FILE_NAME_KEY, TEMPLATE_FILE_PATH_KEY, TEMPLATE_LICENSE_KEY, TEMPLATE_NAME_KEY, TEMPLATE_SUMMARY_KEY, TEMPLATE_TEST_FILES_KEY, TEMPLATE_VERSION_KEY, TEST_FILE_PATH_KEY, TEST_GROUP_PATH_KEY, TEST_TARGETS_KEY, TEST_TARGET_KEY, USERNAME_KEY, USER_PREFERENCES_FILE, VERSION, XCODEPROJ_PATH_KEY
Instance Method Summary
collapse
Instance Method Details
#create(template_name) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/generamba/cli/template/template_create_command.rb', line 8
def create(template_name)
summary = ask('The brief description of your new template:')
author = ask('Who is the author of this template:')
license = ask('What license will be used (e.g. MIT):')
has_dependencies = yes?('Will your template contain any third-party dependencies (available via Cocoapods or Carthage)? (yes/no)')
if has_dependencies
dependencies = ask_loop('Enter the name of your dependency (empty string to stop):')
end
properties = {
TEMPLATE_NAME_KEY => template_name,
TEMPLATE_SUMMARY_KEY => summary,
TEMPLATE_AUTHOR_KEY => author,
TEMPLATE_LICENSE_KEY => license
}
if dependencies and !dependencies.empty?
properties[TEMPLATE_DEPENDENCIES_KEY] = dependencies
end
PrintTable.print_values(
values: properties,
title: "Summary for template create"
)
template_creator = Generamba::TemplateCreator.new
template_creator.create_template(properties)
puts("The template #{template_name} is successfully generated! Now add some file templates into it.".green)
end
|
#install ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/generamba/cli/template/template_install_command.rb', line 5
def install
does_rambafile_exist = Dir[RAMBAFILE_NAME].count > 0
unless does_rambafile_exist
puts('Rambafile not found! Run `generamba setup` in the working directory instead!'.red)
return
end
catalog_downloader = Generamba::CatalogDownloader.new
installer_factory = Generamba::TemplateInstallerFactory.new
template_processor = Generamba::TemplateProcessor.new(catalog_downloader, installer_factory)
rambafile = YAML.load_file(RAMBAFILE_NAME)
template_processor.install_templates(rambafile)
end
|
#list ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/generamba/cli/template/template_list_command.rb', line 9
def list
downloader = CatalogDownloader.new
catalog_template_list_helper = CatalogTemplateListHelper.new
templates = []
catalog_paths = downloader.update_all_catalogs_and_return_filepaths
catalog_paths.each do |path|
templates += catalog_template_list_helper.obtain_all_templates_from_a_catalog(path)
templates = templates.uniq
end
templates.each do |template_name|
puts(template_name)
end
end
|
#search(term) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/generamba/cli/template/template_search_command.rb', line 9
def search(term)
downloader = CatalogDownloader.new
catalog_template_search_helper = CatalogTemplateSearchHelper.new
catalog_paths = downloader.update_all_catalogs_and_return_filepaths
templates = []
catalog_paths.each do |path|
templates += catalog_template_search_helper.search_templates_in_a_catalog(path, term)
templates = templates.uniq
end
templates.map { |template_name|
keywords = term.squeeze.strip.split(' ').compact.uniq
matcher = Regexp.new('(' + keywords.join('|') + ')')
template_name.gsub(matcher) { |match| "#{match}".yellow }
}.each { |template_name|
puts(template_name)
}
end
|