Skip to content

Molt is a simple VIPER module generator for Swift apps.

License

Notifications You must be signed in to change notification settings

MarcoCabazal/Molt

Repository files navigation

Molt

Molt is a simple VIPER module generator for Swift apps.

Gem Version Build Status CircleCI

Table of Contents

  1. Installation
  2. Template Sets
  3. Creating (generating) a module
  4. Notes about the bundled VIPER_TableView template set
  5. TODOs
  6. Contributing
  7. License
  8. Code of Conduct

Installation

$ gem install molt

Global Configuration

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: [email protected]
  company: Genco Olive Oil Imports

project:
  name: CapoRegime

Per-Project Configuration

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

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.

To list available template sets (search order: current project directory, global, bundled):

$ 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

To list available template sets and the template files they contain:

$ 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

Creating your own template sets

Just duplicate the respective folders under ~/.molt/template_sets, rename the folder, then customize to suit your taste.

Creating (generating) a module

$ molt create_module Friends VIPER_TableView
+-------------------------------------------------------------+-------------------------------------------------------+
| Developer                                                   | Tom Hagen                                             |
| Email                                                       | [email protected]                                        |
| 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.

Additional options/overrides when generating modules

$ 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

Exporting template sets as Xcode templates

$ 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.

Notes about the bundled VIPER_TableView template set

  1. The RemoteDataManager makes use of Alamofire and ObjectMapper
  2. The LocalDataManager makes use of Core Data
  3. The Interactor and RemoteDataManager talks to each other using promises via Hydra
  4. You'll notice there aren't any mention of segues here, but Storyboards and Scenes are in.
  5. 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.

TODOs

  1. Demo a working app done created using generators
  2. Write more comprehensive tests

Contributing

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.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Molt project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

About

Molt is a simple VIPER module generator for Swift apps.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages