Contents

spectraldragon/templar

For beginning you are must install Templar in your project.

How to use?

$ templar generate [templateName] [moduleName]

Templar will asks the user questions from your template config file and will replace each pattern on answer. Pretty simple, right?

How to write template?

The first you going to create template file and set patterns for replace. Like example it will CLASS_NAME

class __CLASS_NAME__ViewController: UIViewController {
  // Other code
}

After that you should add path to your template file and path to finish directory in your template config.

# Template file

varsion: 1.0.0
...
files:
 - path: View/ViewController.swift
   templatePath: View/ViewController.swift.templar

Okay, that it. When you will generate template, Templar will create the file using [moduleName] like name of your files. Like example View/MyPrettyViewController.swift.

Templar will replacing each pattern using user answers from questions.

Next chapter:

Pattern can be modified with next separated keys:

  • =lowercase=
  • =firstLowercased=
  • =uppercase=
  • =firstUppercased=
  • =snake_case=

Notifce: All modifier can be use for each pattern once. Also modifier case sensative!

Example with modifiers:

class __CLASS_NAME__Presenter {

   func __CLASS_NAME__=firstLowercased=ViewControllerDidLoad() {
     // Code
   }
   
}

Default patterns

Templar there is default patterns for replacing.

  • NAME - module name taken from argument [moduleName]
  • FILE - file name
  • PROJECT - project name taken from templar config -> xcodeproj -> name or nil. Can be modified with template settings template -> settings -> projectName
  • AUTHOR - author name, taken from template -> author. If author name not exists in template, this key will not replace.
  • YEAR - current year.
  • DATE - current date with format dd/MM/YYYY. Can be modified with template settings template -> settings -> dateFormat
  • COMPANY_NAME - your company name taken from templar -> companyName or nil.
  • (FUTURE) LICENSE - will replace key on license file in project root directory. Path can be modified with template settings template -> settings -> licensePath. OR take license template and replace each key using default patterns.

Template settings

Settings will contains specification for replacing or some action will add in future.

# Template file

version: 1.0.0
...
settings:
  dateFormat: dd/MM/YY
  projectName: Templar
  licensePath: LICENSE #will add in future release
...

Scripts?

Yup, Templar supported scripts. Scripts will run when template did finish successfully and will execute using bash.

For creating scripts just use command: templar template new [templateName] --use-scripts or set manual scripts: parameter to your template.

Like example generate a new xcodeproj for your SPM project:

# Template file

...
scripts:
  - swift package generate-xcodeproj

Installing

Using Makefile

$ git clone https://github.com/SpectralDragon/Templar.git
$ cd Templar
$ make

Using Mint 🌱

$ mint install SpectralDragon/Templar

Using the Swift Package Manager 🛠

$ git clone https://github.com/SpectralDragon/Templar.git
$ cd Templar
$ swift build -c release -Xswiftc -static-stdlib
$ cd .build/release
$ cp -f templar /usr/local/bin/templar

Author

Vladislav Prusakov, twitter

License

Templar is available under the MIT license. See the LICENSE file for more info.

Package Metadata

Repository: spectraldragon/templar

Default branch: master

README: README.md