From 6ca1af2936c845d9e4690ba6b7b779fa48b1c171 Mon Sep 17 00:00:00 2001 From: Edouard Siegel Date: Thu, 28 Sep 2023 11:21:53 +0200 Subject: [PATCH 01/12] Fix typo --- lib/ccios/config.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ccios/config.rb b/lib/ccios/config.rb index bf556b5..a64dfd2 100644 --- a/lib/ccios/config.rb +++ b/lib/ccios/config.rb @@ -9,7 +9,7 @@ def self.parse(source_path) config = YAML.load_file(source_path) self.new config, source_path else - puts "File #{source_path} does not exists. Using default config." + puts "File #{source_path} does not exist. Using default config." self.default end end From a161942e3a89c2bb59b8024add27da536afc0038 Mon Sep 17 00:00:00 2001 From: Edouard Siegel Date: Thu, 28 Sep 2023 11:23:10 +0200 Subject: [PATCH 02/12] Rename some variables --- lib/ccios.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/ccios.rb b/lib/ccios.rb index 874266a..0f4174c 100644 --- a/lib/ccios.rb +++ b/lib/ccios.rb @@ -14,20 +14,20 @@ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v| options[:verbose] = v end - opts.on("-pName", "--presenter=Name", "Generate NamePresenter, NamePresenterImplementation, NameViewContract and NameViewController") do |v| - options[:presenter] = v + opts.on("-pName", "--presenter=Name", "Generate NamePresenter, NamePresenterImplementation, NameViewContract and NameViewController") do |name| + options[:presenter] = name end - opts.on("-cName", "--coordinator=Name", "Generate NameCoordinator") do |v| - options[:coordinator] = v + opts.on("-cName", "--coordinator=Name", "Generate NameCoordinator") do |name| + options[:coordinator] = name end - opts.on("-iName", "--interactor=Name", "Generate NameInteractor and NameInteractorImplementation") do |v| - options[:interactor] = v + opts.on("-iName", "--interactor=Name", "Generate NameInteractor and NameInteractorImplementation") do |name| + options[:interactor] = name end - opts.on("-rName", "--repository=Name", "Generate NameRepository and NameRepositoryImplementation") do |v| - options[:repository] = v + opts.on("-rName", "--repository=Name", "Generate NameRepository and NameRepositoryImplementation") do |name| + options[:repository] = name end - opts.on("-d", "--delegate", "Add delegate for curent generation") do |v| - options[:generate_delegate] = v + opts.on("-d", "--delegate", "Add delegate for curent generation") do |add_delegate| + options[:generate_delegate] = add_delegate end opts.on("-h", "--help", "Print this help") do puts opts From 78e993aad65cd4d6dca72d5148b43937a26e8c3a Mon Sep 17 00:00:00 2001 From: Edouard Siegel Date: Thu, 28 Sep 2023 13:24:31 +0200 Subject: [PATCH 03/12] Add templates path parameter to overload templates --- lib/ccios/code_templater.rb | 5 ++-- lib/ccios/config.rb | 23 +++++++++++++-- lib/ccios/coordinator_generator.rb | 2 +- lib/ccios/file_creator.rb | 7 +++-- lib/ccios/interactor_generator.rb | 2 +- lib/ccios/presenter_generator.rb | 2 +- lib/ccios/repository_generator.rb | 4 +-- test/test_code_templater.rb | 3 +- test/test_config.rb | 45 ++++++++++++++++++++++++++++-- 9 files changed, 76 insertions(+), 17 deletions(-) diff --git a/lib/ccios/code_templater.rb b/lib/ccios/code_templater.rb index de4aee0..fd624ae 100644 --- a/lib/ccios/code_templater.rb +++ b/lib/ccios/code_templater.rb @@ -2,14 +2,15 @@ require 'active_support/core_ext/string' class CodeTemplater - def initialize(options = {}) + def initialize(options = {}, templates_path) @options = options + @templates_path = templates_path end def content_for_suffix(prefix, suffix) template_name = suffix.underscore options = @options.merge({name: prefix, lowercased_name: prefix.camelize(:lower)}) - template_file = File.join(File.dirname(__FILE__), "templates/#{template_name}.mustache") + template_file = File.join(@templates_path, "#{template_name}.mustache") Mustache.render(File.read(template_file), options) end end diff --git a/lib/ccios/config.rb b/lib/ccios/config.rb index a64dfd2..47cb5a6 100644 --- a/lib/ccios/config.rb +++ b/lib/ccios/config.rb @@ -2,7 +2,7 @@ class Config - attr_reader :app, :core, :data + attr_reader :app, :core, :data, :templates def self.parse(source_path) if File.exist?(source_path) @@ -30,7 +30,8 @@ def self.default_config_hash "data" => { "project" => project, "repository" => {"group" => "Classes/Data"} - } + }, + "templates" => self.default_templates_hash } end @@ -38,12 +39,21 @@ def self.default self.new default_config_hash end + def self.default_templates_hash + { "path" => File.join(File.dirname(__FILE__), "templates") } + end + def initialize(config_hash, source_path = nil) @source_path = source_path validate config_hash @app = AppConfig.new config_hash["app"] @core = CoreConfig.new config_hash["core"] @data = DataConfig.new config_hash["data"] + if config_hash["templates"].nil? + @templates = TemplatesConfig.new Config.default_templates_hash + else + @templates = TemplatesConfig.new config_hash["templates"] + end end def validate(hash) @@ -107,10 +117,17 @@ def initialize(hash) end class ObjectConfig - attr_reader :group def initialize(hash) @group = hash["group"] end end + +class TemplatesConfig + attr_reader :path + + def initialize(hash) + @path = hash["path"] + end +end diff --git a/lib/ccios/coordinator_generator.rb b/lib/ccios/coordinator_generator.rb index c82f4f3..94095d3 100644 --- a/lib/ccios/coordinator_generator.rb +++ b/lib/ccios/coordinator_generator.rb @@ -10,7 +10,7 @@ def initialize(parser, config) def generate(coordinator_name, options = {}) coordinator_group = @parser.coordinator_group - file_creator = FileCreator.new(options) + file_creator = FileCreator.new(options, @config) target = @parser.app_target coordinator_name = coordinator_name.gsub("Coordinator", "") file_creator.create_file(coordinator_name, 'Coordinator', coordinator_group, target) diff --git a/lib/ccios/file_creator.rb b/lib/ccios/file_creator.rb index a2f6ac6..0602ef3 100644 --- a/lib/ccios/file_creator.rb +++ b/lib/ccios/file_creator.rb @@ -24,8 +24,9 @@ def logger FileCreator.logger end - def initialize(options = {}) + def initialize(options = {}, config) @options = options + @config = config end def templater_options(target) @@ -50,7 +51,7 @@ def create_file(prefix, suffix, group, target) file = File.new(file_path, 'w') templater_options = templater_options(target) - code_templater = CodeTemplater.new(templater_options) + code_templater = CodeTemplater.new(templater_options, @config.templates.path) file_content = code_templater.content_for_suffix(prefix, suffix) file.puts(file_content) @@ -70,7 +71,7 @@ def create_empty_directory(group) def print_file_content(prefix, suffix) file_name = suffix + '.swift' - code_templater = CodeTemplater.new(@options) + code_templater = CodeTemplater.new(@options, @config.templates.path) template = code_templater.content_for_suffix(prefix, suffix) logger.info "Add this snippet to #{file_name}" diff --git a/lib/ccios/interactor_generator.rb b/lib/ccios/interactor_generator.rb index 774aeae..3b2205e 100644 --- a/lib/ccios/interactor_generator.rb +++ b/lib/ccios/interactor_generator.rb @@ -23,7 +23,7 @@ def generate(interactor_name, options = {}) path: new_group_path ) - file_creator = FileCreator.new(options) + file_creator = FileCreator.new(options, @config) target = @parser.core_target file_creator.create_file(interactor_name, 'Interactor', new_group, target) file_creator.create_file(interactor_name, 'InteractorImplementation', new_group, target) diff --git a/lib/ccios/presenter_generator.rb b/lib/ccios/presenter_generator.rb index 3898406..0c1eda1 100644 --- a/lib/ccios/presenter_generator.rb +++ b/lib/ccios/presenter_generator.rb @@ -56,7 +56,7 @@ def generate(presenter_name, options = {}) path: model_group_path ) - file_creator = FileCreator.new(options) + file_creator = FileCreator.new(options, @config) target = @parser.app_target file_creator.create_file(presenter_name, 'ViewContract', ui_group, target) file_creator.create_file(presenter_name, 'ViewController', view_controller_group, target) diff --git a/lib/ccios/repository_generator.rb b/lib/ccios/repository_generator.rb index b3cdf88..c940e19 100644 --- a/lib/ccios/repository_generator.rb +++ b/lib/ccios/repository_generator.rb @@ -31,11 +31,11 @@ def generate(repository_name, options = {}) path: data_new_group_path ) - file_creator = FileCreator.new(options) + file_creator = FileCreator.new(options, @config) core_target = @parser.core_target file_creator.create_file(repository_name, 'Repository', core_data_new_group, core_target) - file_creator = FileCreator.new(options) + file_creator = FileCreator.new(options, @config) data_target = @parser.data_target file_creator.create_file(repository_name, 'RepositoryImplementation', data_new_group, data_target) diff --git a/test/test_code_templater.rb b/test/test_code_templater.rb index d57f616..6e7f755 100644 --- a/test/test_code_templater.rb +++ b/test/test_code_templater.rb @@ -7,7 +7,8 @@ def test_all_templates basename = basename_for_path template_path generate_delegate = !basename.slice!("_delegate").nil? # Removes _delegate from basename as well - templater = CodeTemplater.new(options(generate_delegate)) + templates_dir = Config.default.templates.path + templater = CodeTemplater.new(options(generate_delegate), templates_dir) template_content = templater.content_for_suffix("Test", basename) assert_equal_content_of_file(template_path, template_content) end diff --git a/test/test_config.rb b/test/test_config.rb index 573b472..7711bdc 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -9,9 +9,9 @@ def test_default_config assert_config_is_ok config end - def test_file_config + def test_file_config_no_templates Tempfile.create do |f| - f << file_config_content + f << file_config_content_no_templates f.rewind config = Config.parse f.path @@ -19,6 +19,17 @@ def test_file_config end end + def test_file_config_with_templates + Tempfile.create do |f| + f << file_config_content_with_templates + f.rewind + + config = Config.parse f.path + assert_config_is_ok config + assert_equal config.templates.path, "ccios/templates" + end + end + def test_file_not_valid Tempfile.create do |f| f << "this is not yaml" @@ -45,9 +56,34 @@ def assert_config_is_ok(config) refute_nil config.data.project refute_nil config.data.repository.group + + refute_nil config.templates.path + end + + def file_config_content_no_templates + <<-eos +app: + project: MyProject.xcodeproj + presenter: + group: Classes/App + coordinator: + group: Classes/Coordinator + +core: + project: MyProject.xcodeproj + interactor: + group: Classes/Core/Interactor + repository: + group: Classes/Core/Data + +data: + project: MyProject.xcodeproj + repository: + group: Classes/Data +eos end - def file_config_content + def file_config_content_with_templates <<-eos app: project: MyProject.xcodeproj @@ -67,6 +103,9 @@ def file_config_content project: MyProject.xcodeproj repository: group: Classes/Data + +templates: + path: ccios/templates eos end end From 2f4a2577ed2aeaf470cf1284e79eedc13e1f9a16 Mon Sep 17 00:00:00 2001 From: Edouard Siegel Date: Thu, 28 Sep 2023 15:50:24 +0200 Subject: [PATCH 04/12] Update CHANGELOG.md --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 435416b..71a3dac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +## [4.1.0] + +### Added +- Allow user to overload templates with local version thanks to the new config parameter in `.ccios.yml` + ## [4.0.2] ### Fixed From d3f7935bcbc2914030db94639bd150e31cb531f4 Mon Sep 17 00:00:00 2001 From: Edouard Siegel Date: Thu, 28 Sep 2023 15:53:44 +0200 Subject: [PATCH 05/12] Update README.md --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 34bc98a..cb5f278 100644 --- a/README.md +++ b/README.md @@ -154,8 +154,14 @@ data: target: MyProjectData # optional repository: group: MyProjectData/Sources/Repositories - ``` *Note*: The path of the new files will be infered from the path of the group. It works with *Group with folder* and *Group without folder* in Xcode. +And lastly you may want to use your own templates, by adding this parameter to the file: +``` +templates: + path: Path/To/Users/Templates +``` + + From a108888ca5db788d5b2611756f52e5a32d3cedac Mon Sep 17 00:00:00 2001 From: Edouard Siegel Date: Thu, 28 Sep 2023 15:42:08 +0200 Subject: [PATCH 06/12] Bump version to 4.1.0 --- Gemfile.lock | 6 +++--- ccios.gemspec | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 97c131a..d6cc9e2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - ccios (4.0.2) + ccios (4.1.0) activesupport (> 4) mustache (~> 1.0) xcodeproj (~> 1.4) @@ -22,7 +22,7 @@ GEM concurrent-ruby (1.1.8) i18n (1.8.9) concurrent-ruby (~> 1.0) - minitest (5.14.2) + minitest (5.20.0) mustache (1.1.1) nanaimo (0.3.0) rake (12.3.3) @@ -45,4 +45,4 @@ DEPENDENCIES rake (~> 12.3) BUNDLED WITH - 1.17.3 + 2.4.10 diff --git a/ccios.gemspec b/ccios.gemspec index 76b9ab0..78f736e 100644 --- a/ccios.gemspec +++ b/ccios.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'ccios' - s.version = '4.0.2' + s.version = '4.1.0' s.executables << 'ccios' s.date = '2016-08-03' s.summary = "Clean Code iOS Generator" From c965bc4b56df87db75126d9de4069a6cc742639c Mon Sep 17 00:00:00 2001 From: Edouard Siegel Date: Fri, 29 Sep 2023 09:16:01 +0200 Subject: [PATCH 07/12] Remove warnings silencing --- Gemfile.lock | 19 ++++++++++--------- test/test_parser.rb | 24 ++++++++++-------------- test/test_xcodeproj_with_folder.rb | 8 +++----- test/test_xcodeproj_without_folder.rb | 8 +++----- 4 files changed, 26 insertions(+), 33 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index d6cc9e2..22d9bc0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,32 +9,33 @@ PATH GEM remote: https://rubygems.org/ specs: - CFPropertyList (3.0.3) - activesupport (6.1.3) + CFPropertyList (3.0.6) + rexml + activesupport (7.0.8) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) - zeitwerk (~> 2.3) atomos (0.1.3) - claide (1.0.3) + claide (1.1.0) colored2 (3.1.2) - concurrent-ruby (1.1.8) - i18n (1.8.9) + concurrent-ruby (1.2.2) + i18n (1.14.1) concurrent-ruby (~> 1.0) minitest (5.20.0) mustache (1.1.1) nanaimo (0.3.0) rake (12.3.3) - tzinfo (2.0.4) + rexml (3.2.6) + tzinfo (2.0.6) concurrent-ruby (~> 1.0) - xcodeproj (1.19.0) + xcodeproj (1.23.0) CFPropertyList (>= 2.3.3, < 4.0) atomos (~> 0.1.3) claide (>= 1.0.2, < 2.0) colored2 (~> 3.1) nanaimo (~> 0.3.0) - zeitwerk (2.4.2) + rexml (~> 3.2.4) PLATFORMS ruby diff --git a/test/test_parser.rb b/test/test_parser.rb index b01173a..d117711 100644 --- a/test/test_parser.rb +++ b/test/test_parser.rb @@ -5,25 +5,21 @@ class ParserTest < Minitest::Test def test_projects_are_equal - Kernel.silence_warnings do # xcodeproj emit lots of warnings during `rake test` and not in irb - dir = File.join(File.dirname(__FILE__), "project") - config = Config.default - parser = PBXProjParser.new(dir, config) + dir = File.join(File.dirname(__FILE__), "project") + config = Config.default + parser = PBXProjParser.new(dir, config) - assert parser.app_project.equal? parser.core_project - assert parser.app_project.equal? parser.data_project - end + assert parser.app_project.equal? parser.core_project + assert parser.app_project.equal? parser.data_project end def test_targets_are_equal - Kernel.silence_warnings do # xcodeproj emit lots of warnings during `rake test` and not in irb - dir = File.join(File.dirname(__FILE__), "project") - config = Config.default - parser = PBXProjParser.new(dir, config) + dir = File.join(File.dirname(__FILE__), "project") + config = Config.default + parser = PBXProjParser.new(dir, config) - assert parser.app_target.equal? parser.core_target - assert parser.app_target.equal? parser.data_target - end + assert parser.app_target.equal? parser.core_target + assert parser.app_target.equal? parser.data_target end end diff --git a/test/test_xcodeproj_with_folder.rb b/test/test_xcodeproj_with_folder.rb index b2862c0..51efdd9 100644 --- a/test/test_xcodeproj_with_folder.rb +++ b/test/test_xcodeproj_with_folder.rb @@ -107,11 +107,9 @@ def setup_parser io.puts ccios_yml_with_folders_content end - Kernel.silence_warnings do # xcodeproj emit lots of warnings during `rake test` and not in irb - config = Config.parse yml_path - parser = PBXProjParser.new(@test_dir, config) - yield(config, parser) - end + config = Config.parse yml_path + parser = PBXProjParser.new(@test_dir, config) + yield(config, parser) end def generate_and_assert(xcodeproj_group:, source_path:, generator_class:, name:, expected_files:) diff --git a/test/test_xcodeproj_without_folder.rb b/test/test_xcodeproj_without_folder.rb index d4f34f4..33ec651 100644 --- a/test/test_xcodeproj_without_folder.rb +++ b/test/test_xcodeproj_without_folder.rb @@ -87,11 +87,9 @@ def setup_parser io.puts ccios_yml_without_folders_content end - Kernel.silence_warnings do # xcodeproj emit lots of warnings during `rake test` and not in irb - config = Config.parse yml_path - parser = PBXProjParser.new(@test_dir, config) - yield(config, parser) - end + config = Config.parse yml_path + parser = PBXProjParser.new(@test_dir, config) + yield(config, parser) end def generate_and_assert(xcodeproj_group:, source_path:, generator_class:, name:, expected_files:) From dc9d7b31c7e80f13587affb4b16c0f23844493c9 Mon Sep 17 00:00:00 2001 From: Edouard Siegel Date: Fri, 29 Sep 2023 09:19:38 +0200 Subject: [PATCH 08/12] Update ruby version --- .github/workflows/ruby.yml | 8 ++++---- .ruby-version | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 .ruby-version diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 4ca52a1..a4ba1d2 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -8,11 +8,11 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 - - name: Set up Ruby 2.6 - uses: actions/setup-ruby@v1 + - uses: actions/checkout@v4 + - name: Set up Ruby 3.2 + uses: ruby/setup-ruby@v1 with: - ruby-version: 2.6.x + bundler-cache: true - name: Build and test with Rake run: | gem install bundler diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..be94e6f --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.2.2 From 7781fab8e01f19c1a40b3ede46a5aba8cd01880f Mon Sep 17 00:00:00 2001 From: Edouard Siegel Date: Fri, 29 Sep 2023 09:32:15 +0200 Subject: [PATCH 09/12] Add async templates --- templates_library/async/coordinator.mustache | 41 +++++++++++++++++++ .../async/dependency_provider.mustache | 14 +++++++ templates_library/async/interactor.mustache | 13 ++++++ .../async/interactor_assembly.mustache | 5 +++ .../async/interactor_implementation.mustache | 22 ++++++++++ templates_library/async/presenter.mustache | 21 ++++++++++ .../async/presenter_assembly.mustache | 15 +++++++ .../async/presenter_implementation.mustache | 35 ++++++++++++++++ templates_library/async/repository.mustache | 13 ++++++ .../async/repository_assembly.mustache | 6 +++ .../async/repository_implementation.mustache | 21 ++++++++++ .../async/view_contract.mustache | 14 +++++++ .../async/view_controller.mustache | 23 +++++++++++ templates_library/default/README.md | 1 + 14 files changed, 244 insertions(+) create mode 100644 templates_library/async/coordinator.mustache create mode 100644 templates_library/async/dependency_provider.mustache create mode 100644 templates_library/async/interactor.mustache create mode 100644 templates_library/async/interactor_assembly.mustache create mode 100644 templates_library/async/interactor_implementation.mustache create mode 100644 templates_library/async/presenter.mustache create mode 100644 templates_library/async/presenter_assembly.mustache create mode 100644 templates_library/async/presenter_implementation.mustache create mode 100644 templates_library/async/repository.mustache create mode 100644 templates_library/async/repository_assembly.mustache create mode 100644 templates_library/async/repository_implementation.mustache create mode 100644 templates_library/async/view_contract.mustache create mode 100644 templates_library/async/view_controller.mustache create mode 100644 templates_library/default/README.md diff --git a/templates_library/async/coordinator.mustache b/templates_library/async/coordinator.mustache new file mode 100644 index 0000000..0224674 --- /dev/null +++ b/templates_library/async/coordinator.mustache @@ -0,0 +1,41 @@ +// +// {{name}}Coordinator.swift +// {{project_name}} +// +// Created by {{full_username}} on {{date}}. +// +// + +import Foundation +import ADCoordinator + +{{#generate_delegate}} +@MainActor +protocol {{name}}CoordinatorDelegate: AnyObject { + +} + +{{/generate_delegate}} +@MainActor +class {{name}}Coordinator: Coordinator { + + {{#generate_delegate}} + weak var delegate: {{name}}CoordinatorDelegate? + {{/generate_delegate}} + private let dependencyProvider: ApplicationDependencyProvider + private unowned var navigationController: UINavigationController + + nonisolated init(navigationController: UINavigationController, + dependencyProvider: ApplicationDependencyProvider) { + self.navigationController = navigationController + self.dependencyProvider = dependencyProvider + } + + // MARK: - Public + + func start() { + let viewController = UIViewController() + navigationController.pushViewController(viewController, animated: false) + bindToLifecycle(of: viewController) + } +} diff --git a/templates_library/async/dependency_provider.mustache b/templates_library/async/dependency_provider.mustache new file mode 100644 index 0000000..d70e8e4 --- /dev/null +++ b/templates_library/async/dependency_provider.mustache @@ -0,0 +1,14 @@ +{{#generate_delegate}} +func {{lowercased_name}}Presenter(viewContract: {{name}}ViewContract, presenterDelegate: {{name}}PresenterDelegate) -> {{name}}Presenter? { + return presenterAssembler + .resolver + .resolve({{name}}Presenter.self, arguments: viewContract, presenterDelegate) +} +{{/generate_delegate}} +{{^generate_delegate}} +func {{lowercased_name}}Presenter(viewContract: {{name}}ViewContract) -> {{name}}Presenter? { + return presenterAssembler + .resolver + .resolve({{name}}Presenter.self, argument: viewContract) +} +{{/generate_delegate}} diff --git a/templates_library/async/interactor.mustache b/templates_library/async/interactor.mustache new file mode 100644 index 0000000..3130bd9 --- /dev/null +++ b/templates_library/async/interactor.mustache @@ -0,0 +1,13 @@ +// +// {{name}}Interactor.swift +// {{project_name}} +// +// Created by {{full_username}} on {{date}}. +// +// + +import Foundation + +public protocol {{name}}Interactor { + func execute() async throws +} diff --git a/templates_library/async/interactor_assembly.mustache b/templates_library/async/interactor_assembly.mustache new file mode 100644 index 0000000..ec6e684 --- /dev/null +++ b/templates_library/async/interactor_assembly.mustache @@ -0,0 +1,5 @@ +container.register({{name}}Interactor.self) { _ in + {{name}}InteractorImplementation( + + ) +} diff --git a/templates_library/async/interactor_implementation.mustache b/templates_library/async/interactor_implementation.mustache new file mode 100644 index 0000000..ab8e084 --- /dev/null +++ b/templates_library/async/interactor_implementation.mustache @@ -0,0 +1,22 @@ +// +// {{name}}InteractorImplementation.swift +// {{project_name}} +// +// Created by {{full_username}} on {{date}}. +// +// + +import Foundation + +public class {{name}}InteractorImplementation: {{name}}Interactor { + + public init() { + + } + + // MARK: - {{name}}Interactor + + public func execute() async throws { + + } +} diff --git a/templates_library/async/presenter.mustache b/templates_library/async/presenter.mustache new file mode 100644 index 0000000..8da4215 --- /dev/null +++ b/templates_library/async/presenter.mustache @@ -0,0 +1,21 @@ +// +// {{name}}Presenter.swift +// {{project_name}} +// +// Created by {{full_username}} on {{date}}. +// +// + +import Foundation + +@MainActor +protocol {{name}}Presenter { + func start() +} +{{#generate_delegate}} + +@MainActor +protocol {{name}}PresenterDelegate: AnyObject { + +} +{{/generate_delegate}} diff --git a/templates_library/async/presenter_assembly.mustache b/templates_library/async/presenter_assembly.mustache new file mode 100644 index 0000000..8f318b0 --- /dev/null +++ b/templates_library/async/presenter_assembly.mustache @@ -0,0 +1,15 @@ +{{#generate_delegate}} +container.register({{name}}Presenter.self) { _, viewContract, delegate in + {{name}}PresenterImplementation( + viewContract: viewContract, + delegate: delegate + ) +} +{{/generate_delegate}} +{{^generate_delegate}} +container.register({{name}}Presenter.self) { _, viewContract in + {{name}}PresenterImplementation( + viewContract: viewContract + ) +} +{{/generate_delegate}} diff --git a/templates_library/async/presenter_implementation.mustache b/templates_library/async/presenter_implementation.mustache new file mode 100644 index 0000000..1910c25 --- /dev/null +++ b/templates_library/async/presenter_implementation.mustache @@ -0,0 +1,35 @@ +// +// {{name}}PresenterImplementation.swift +// {{project_name}} +// +// Created by {{full_username}} on {{date}}. +// +// + +import Foundation + +class {{name}}PresenterImplementation: {{name}}Presenter { + + private weak var viewContract: {{name}}ViewContract? + {{#generate_delegate}} + private weak var delegate: {{name}}PresenterDelegate? + {{/generate_delegate}} + + {{#generate_delegate}} + nonisolated init(viewContract: {{name}}ViewContract, delegate: {{name}}PresenterDelegate) { + self.viewContract = viewContract + self.delegate = delegate + } + {{/generate_delegate}} + {{^generate_delegate}} + nonisolated init(viewContract: {{name}}ViewContract) { + self.viewContract = viewContract + } + {{/generate_delegate}} + + // MARK: - {{name}}Presenter + + func start() { + + } +} diff --git a/templates_library/async/repository.mustache b/templates_library/async/repository.mustache new file mode 100644 index 0000000..bdd8bc9 --- /dev/null +++ b/templates_library/async/repository.mustache @@ -0,0 +1,13 @@ +// +// {{name}}Repository.swift +// {{project_name}} +// +// Created by {{full_username}} on {{date}}. +// +// + +import Foundation + +public protocol {{name}}Repository { + +} diff --git a/templates_library/async/repository_assembly.mustache b/templates_library/async/repository_assembly.mustache new file mode 100644 index 0000000..a7769f2 --- /dev/null +++ b/templates_library/async/repository_assembly.mustache @@ -0,0 +1,6 @@ +container.register({{name}}Repository.self) { _ in + {{name}}RepositoryImplementation( + + ) +} +.inObjectScope(.container) diff --git a/templates_library/async/repository_implementation.mustache b/templates_library/async/repository_implementation.mustache new file mode 100644 index 0000000..848b40b --- /dev/null +++ b/templates_library/async/repository_implementation.mustache @@ -0,0 +1,21 @@ +// +// {{name}}RepositoryImplementation.swift +// {{project_name}} +// +// Created by {{full_username}} on {{date}}. +// +// +// + +import Foundation +import Core + +public class {{name}}RepositoryImplementation: {{name}}Repository { + + public init() { + + } + + // MARK: - {{name}}Repository + +} diff --git a/templates_library/async/view_contract.mustache b/templates_library/async/view_contract.mustache new file mode 100644 index 0000000..d90edc6 --- /dev/null +++ b/templates_library/async/view_contract.mustache @@ -0,0 +1,14 @@ +// +// {{name}}ViewContract.swift +// {{project_name}} +// +// Created by {{full_username}} on {{date}}. +// +// + +import Foundation + +@MainActor +protocol {{name}}ViewContract: AnyObject { + +} diff --git a/templates_library/async/view_controller.mustache b/templates_library/async/view_controller.mustache new file mode 100644 index 0000000..22c6825 --- /dev/null +++ b/templates_library/async/view_controller.mustache @@ -0,0 +1,23 @@ +// +// {{name}}ViewController.swift +// {{project_name}} +// +// Created by {{full_username}} on {{date}}. +// +// + +import Foundation +import UIKit + +@MainActor +class {{name}}ViewController: SharedViewController, {{name}}ViewContract { + var presenter: {{name}}Presenter? + + override func viewDidLoad() { + super.viewDidLoad() + presenter?.start() + } + + // MARK: - {{name}}ViewContract + +} diff --git a/templates_library/default/README.md b/templates_library/default/README.md new file mode 100644 index 0000000..ead5ca1 --- /dev/null +++ b/templates_library/default/README.md @@ -0,0 +1 @@ +Default templates are in /lib/ccios/templates From 45f1ba960ad384c49e482765d139b35445c919a3 Mon Sep 17 00:00:00 2001 From: Edouard Siegel Date: Fri, 29 Sep 2023 09:57:05 +0200 Subject: [PATCH 10/12] Fix template inconsistency --- lib/ccios/templates/repository_implementation.mustache | 1 - templates_library/async/repository_implementation.mustache | 1 - 2 files changed, 2 deletions(-) diff --git a/lib/ccios/templates/repository_implementation.mustache b/lib/ccios/templates/repository_implementation.mustache index 848b40b..cbf6bd0 100644 --- a/lib/ccios/templates/repository_implementation.mustache +++ b/lib/ccios/templates/repository_implementation.mustache @@ -5,7 +5,6 @@ // Created by {{full_username}} on {{date}}. // // -// import Foundation import Core diff --git a/templates_library/async/repository_implementation.mustache b/templates_library/async/repository_implementation.mustache index 848b40b..cbf6bd0 100644 --- a/templates_library/async/repository_implementation.mustache +++ b/templates_library/async/repository_implementation.mustache @@ -5,7 +5,6 @@ // Created by {{full_username}} on {{date}}. // // -// import Foundation import Core From 3777fdf533add2f06fb4aa21b19a3844e9ac2884 Mon Sep 17 00:00:00 2001 From: Edouard Siegel Date: Fri, 29 Sep 2023 09:58:35 +0200 Subject: [PATCH 11/12] fix test --- test/templates/repository_implementation.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/test/templates/repository_implementation.swift b/test/templates/repository_implementation.swift index 69517f9..04dd512 100644 --- a/test/templates/repository_implementation.swift +++ b/test/templates/repository_implementation.swift @@ -5,7 +5,6 @@ // Created by Georges Abitbol on 01/01/1970. // // -// import Foundation import Core From 789eb7fba56d0bb5e1db19446686850c42d7d630 Mon Sep 17 00:00:00 2001 From: Edouard Siegel Date: Mon, 2 Oct 2023 09:27:21 +0200 Subject: [PATCH 12/12] Fix indentation in new template --- templates_library/async/coordinator.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates_library/async/coordinator.mustache b/templates_library/async/coordinator.mustache index 0224674..4c01e05 100644 --- a/templates_library/async/coordinator.mustache +++ b/templates_library/async/coordinator.mustache @@ -26,7 +26,7 @@ class {{name}}Coordinator: Coordinator { private unowned var navigationController: UINavigationController nonisolated init(navigationController: UINavigationController, - dependencyProvider: ApplicationDependencyProvider) { + dependencyProvider: ApplicationDependencyProvider) { self.navigationController = navigationController self.dependencyProvider = dependencyProvider }