Molt
Molt is a simple VIPER module generator for Swift apps.
Table of Contents
- Installation
- Global Configuration
- Per-Project Configuration
- Template Sets
- List available template sets
- Creating your own template sets
- Creating (generating) a module
- Additional options/overrides when generating modules
- Exporting template sets as Xcode templates
- Notes about the bundled
VIPER_TableView
template set - TODOs
- Contributing
- License
- Code of Conduct
$ gem install molt
To initialize global configuration in ~/.molt
:
$ molt setup
create ~/.molt
create ~/.molt/models/Entity+CoreData.swift.liquid
create ~/.molt/models/Entity.swift.liquid
create ~/.molt/models/Model.swift.liquid
create ~/.molt/partials/_header.liquid
create ~/.molt/swift_helpers/ErrorTypes/APIError.swift
create ~/.molt/swift_helpers/ErrorTypes/ErrorTypes.swift
create ~/.molt/swift_helpers/ErrorTypes/PersistenceError.swift
create ~/.molt/swift_helpers/ISODateTransform.swift
create ~/.molt/swift_helpers/Identifiable.swift
create ~/.molt/swift_helpers/Loadable.swift
create ~/.molt/swift_helpers/Networking/APIRouter.swift
create ~/.molt/swift_helpers/StoryboardExtensions.swift
create ~/.molt/template_sets/VIPER_Detail/Presenter.swift.liquid
create ~/.molt/template_sets/VIPER_Detail/Protocols.swift.liquid
create ~/.molt/template_sets/VIPER_Detail/View.swift.liquid
create ~/.molt/template_sets/VIPER_Detail/Wireframe.swift.liquid
create ~/.molt/template_sets/VIPER_TableView/DataManagers/LocalDataManager.swift.liquid
create ~/.molt/template_sets/VIPER_TableView/DataManagers/RemoteDataManager.swift.liquid
create ~/.molt/template_sets/VIPER_TableView/Interactor.swift.liquid
create ~/.molt/template_sets/VIPER_TableView/Presenter.swift.liquid
create ~/.molt/template_sets/VIPER_TableView/Protocols.swift.liquid
create ~/.molt/template_sets/VIPER_TableView/View.swift.liquid
create ~/.molt/template_sets/VIPER_TableView/Wireframe.swift.liquid
create ~/.molt/config.yml
This will create the folder `~/.molt`, copy bundled template sets and helper Swift extensions onto it.
This will also create a base config file (config.yml
). If you have a global git config at ~/.gitconfig
, some of the developer details would already be filled out for you. The details you put here would be used to populate meta data in the header files of the generated source code.
You should customize this with your information before you proceed with generating new modules.
developer:
name: Tom Hagen
email: tom@omerta.org
company: Genco Olive Oil Imports
project:
name: CapoRegime
On the other hand, to setup per-project configuration, go to your project's root folder, then:
$ molt setup:project
create .molt
create .molt/models/Entity+CoreData.swift.liquid
create .molt/models/Entity.swift.liquid
create .molt/models/Model.swift.liquid
create .molt/partials/_header.liquid
create .molt/swift_helpers/ErrorTypes/APIError.swift
create .molt/swift_helpers/ErrorTypes/ErrorTypes.swift
create .molt/swift_helpers/ErrorTypes/PersistenceError.swift
create .molt/swift_helpers/ISODateTransform.swift
create .molt/swift_helpers/Identifiable.swift
create .molt/swift_helpers/Loadable.swift
create .molt/swift_helpers/Networking/APIRouter.swift
create .molt/swift_helpers/StoryboardExtensions.swift
create .molt/template_sets/VIPER_Detail/Presenter.swift.liquid
create .molt/template_sets/VIPER_Detail/Protocols.swift.liquid
create .molt/template_sets/VIPER_Detail/View.swift.liquid
create .molt/template_sets/VIPER_Detail/Wireframe.swift.liquid
create .molt/template_sets/VIPER_TableView/DataManagers/LocalDataManager.swift.liquid
create .molt/template_sets/VIPER_TableView/DataManagers/RemoteDataManager.swift.liquid
create .molt/template_sets/VIPER_TableView/Interactor.swift.liquid
create .molt/template_sets/VIPER_TableView/Presenter.swift.liquid
create .molt/template_sets/VIPER_TableView/Protocols.swift.liquid
create .molt/template_sets/VIPER_TableView/View.swift.liquid
create .molt/template_sets/VIPER_TableView/Wireframe.swift.liquid
create .molt/config.yml
Template sets are groups of Liquid template files which make up a VIPER module. This gem comes with two sample sets that can be used to generate a module for use with a UITableView
(VIPER_TableView
) and a detail screen (VIPER_Detail
). These should serve as good starting points for your own customizations. Just duplicate the respective folders under ~/.molt/template_sets
, then customize to suit your taste.
The template system makes use of Liquid
and supports partials which are located in .molt/partials
.
$ molt template_sets
./.molt:
./.molt/template_sets/VIPER_TableView
./.molt/template_sets/some_project_specific_template
~/.molt:
~/.molt/template_sets/VIPER_TableView
~/.molt/template_sets/VIPER_Detail
Add --verbose to list all files in each template set
$ molt template_sets --verbose
./.molt:
./.molt/models/Entity+CoreData.swift.liquid
./.molt/models/Model.swift.liquid
./.molt/models/Entity.swift.liquid
./.molt/template_sets/VIPER_TableView/Protocols.swift.liquid
./.molt/template_sets/VIPER_TableView/Presenter.swift.liquid
./.molt/template_sets/VIPER_TableView/DataManagers/RemoteDataManager.swift.liquid
./.molt/template_sets/VIPER_TableView/DataManagers/LocalDataManager.swift.liquid
./.molt/template_sets/VIPER_TableView/View.swift.liquid
./.molt/template_sets/VIPER_TableView/Wireframe.swift.liquid
./.molt/template_sets/VIPER_TableView/Interactor.swift.liquid
./.molt/template_sets/some_project_specific_template/Protocols.swift.liquid
./.molt/template_sets/some_project_specific_template/Presenter.swift.liquid
./.molt/template_sets/some_project_specific_template/View.swift.liquid
./.molt/template_sets/some_project_specific_template/Wireframe.swift.liquid
~/.molt:
~/.molt/models/Entity+CoreData.swift.liquid
~/.molt/models/Model.swift.liquid
~/.molt/models/Entity.swift.liquid
~/.molt/template_sets/VIPER_TableView/Protocols.swift.liquid
~/.molt/template_sets/VIPER_TableView/Presenter.swift.liquid
~/.molt/template_sets/VIPER_TableView/DataManagers/RemoteDataManager.swift.liquid
~/.molt/template_sets/VIPER_TableView/DataManagers/LocalDataManager.swift.liquid
~/.molt/template_sets/VIPER_TableView/View.swift.liquid
~/.molt/template_sets/VIPER_TableView/Wireframe.swift.liquid
~/.molt/template_sets/VIPER_TableView/Interactor.swift.liquid
~/.molt/template_sets/VIPER_Detail/Protocols.swift.liquid
~/.molt/template_sets/VIPER_Detail/Presenter.swift.liquid
~/.molt/template_sets/VIPER_Detail/View.swift.liquid
~/.molt/template_sets/VIPER_Detail/Wireframe.swift.liquid
Just duplicate the respective folders under ~/.molt/template_sets
, rename the folder, then customize to suit your taste.
$ molt create_module Friends VIPER_TableView
+-------------------------------------------------------------+-------------------------------------------------------+
| Developer | Tom Hagen |
| Email | tom@omerta.org |
| Company | Genco Olive Oil Imports |
| Project | CapoRegime |
| | |
| Template Set | VIPER_TableView |
| | |
| Source | Destination |
| VIPER_TableView/Protocols.swift.liquid | ./Friends/FriendsProtocols.swift |
| VIPER_TableView/Presenter.swift.liquid | ./Friends/FriendsPresenter.swift |
| VIPER_TableView/DataManagers/RemoteDataManager.swift.liquid | ./Friends/DataManagers/FriendsRemoteDataManager.swift |
| VIPER_TableView/DataManagers/LocalDataManager.swift.liquid | ./Friends/DataManagers/FriendsLocalDataManager.swift |
| VIPER_TableView/View.swift.liquid | ./Friends/FriendsView.swift |
| VIPER_TableView/Wireframe.swift.liquid | ./Friends/FriendsWireframe.swift |
| VIPER_TableView/Interactor.swift.liquid | ./Friends/FriendsInteractor.swift |
+-------------------------------------------------------------+-------------------------------------------------------+
That was just a dry-run. If this looks good to you, don't forget to add --do-it
Note that generating a new module will never touch your Xcode project, but it's just a matter of dragging the resulting folder onto Xcode.
$ molt help create_module
Usage:
molt create_module MODULE_NAME TEMPLATE_SET
Options:
--name NAME # Author name
--email EMAIL # Author email
-company COMPANY # Author company
-project PROJECT # Project name
-output-folder DIRECTORY # Create module folder in this directory. Defaults to "./"
-model MODEL # Model name. If unspecified, Xcode placeholders will be used instead
-create-model # If specified, it creates corresponding Mappable struct (ObjectMapper) and Core Data entity; requires --model to be set
-do-it # Release the Kraken and write the files
$ molt xcode VIPER_TableView
+-------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+
| Template Set | VIPER_TableView |
| | |
| Source | Destination |
| VIPER_TableView/Protocols.swift.liquid | ~/Library/Developer/Xcode/Templates/File Templates/Molt/VIPER TableView.xctemplate/___FILEBASENAME___Protocols.swift |
| VIPER_TableView/Presenter.swift.liquid | ~/Library/Developer/Xcode/Templates/File Templates/Molt/VIPER TableView.xctemplate/___FILEBASENAME___Presenter.swift |
| VIPER_TableView/DataManagers/RemoteDataManager.swift.liquid | ~/Library/Developer/Xcode/Templates/File Templates/Molt/VIPER TableView.xctemplate/___FILEBASENAME___RemoteDataManager.swift |
| VIPER_TableView/DataManagers/LocalDataManager.swift.liquid | ~/Library/Developer/Xcode/Templates/File Templates/Molt/VIPER TableView.xctemplate/___FILEBASENAME___LocalDataManager.swift |
| VIPER_TableView/View.swift.liquid | ~/Library/Developer/Xcode/Templates/File Templates/Molt/VIPER TableView.xctemplate/___FILEBASENAME___View.swift |
| VIPER_TableView/Wireframe.swift.liquid | ~/Library/Developer/Xcode/Templates/File Templates/Molt/VIPER TableView.xctemplate/___FILEBASENAME___Wireframe.swift |
| VIPER_TableView/Interactor.swift.liquid | ~/Library/Developer/Xcode/Templates/File Templates/Molt/VIPER TableView.xctemplate/___FILEBASENAME___Interactor.swift |
+-------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+
This command basically exports a template set and makes it available as an Xcode template, which makes your often-used template instantly available from within Xcode itself. When you do create a new file from within Xcode, you will be prompted for the module name and the model. Other meta details normally available in create_module
won't be necessary during the export.
- The
RemoteDataManager
makes use ofAlamofire
andObjectMapper
- The
LocalDataManager
makes use ofCore Data
- The
Interactor
andRemoteDataManager
talks to each other using promises viaHydra
- You'll notice there aren't any mention of segues here, but Storyboards and Scenes are in.
- The template makes use of some Swift extensions, all of which are made available in
.molt/swift_helpers
To appreciate, please see the sample rendered source code for Friends.
- Demo a working app done created using generators
- Write more comprehensive tests
Bug reports and pull requests are welcome on GitHub at https://github.com/MarcoCabazal/molt. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Molt project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.