Skip to content

Latest commit

 

History

History
87 lines (67 loc) · 1.71 KB

template.md

File metadata and controls

87 lines (67 loc) · 1.71 KB

Customize

Variable

The prepared variables can be used for the files prepared under the KuriTemplate folder.

  • __PREFIX__ - If you execute kuri generate Item, __PREFIX__ is Item.
  • __USERNAME__ - Equal echo $USER
  • __TARGET__ - Generate for Xcode target name.
  • __DATE__ - Current system date format from yyyy/MM/dd
  • __YEAR__ - Current system year.
  • __MONTH__ - Current system month.
  • __DAY__ - Current system day.

e.g.

Prepare this kind of template

//
//  __PREFIX__Repository.swift
//  Kuri
//
//  Created by __USERNAME__ on __DATE__.
//  Copyright © __YEAR__ __USERNAME__. All rights reserved.
//

import Foundation

protocol __PREFIX__Repository {
    func fetch(_ closure: (__PREFIX__Entity) -> Void) throws
}


struct __PREFIX__RepositoryImpl: __PREFIX__Repository {
    private let dataStore: __PREFIX__DataStore

    init(
        dataStore: __PREFIX__DataStore
        ) {
        self.dataStore = dataStore
    }

    func fetch(_ closure: (__PREFIX__Entity) -> Void) throws  {
        return try dataStore.fetch(closure)
    }
}

exec kuri generate.

echo $USER
 yourname

kuri generate Kuri

The output looks like this

//
//  KuriRepository.swift
//  Kuri
//
//  Created by hirose on 2017/4/11.
//  Copyright © 2017 hirose. All rights reserved.
//

import Foundation

protocol KuriRepository {
    func fetch(_ closure: (KuriEntity) -> Void) throws 
}


struct KuriRepositoryImpl: KuriRepository {
    private let dataStore: KuriDataStore
    
    init(
        dataStore: KuriDataStore
        ) {
        self.dataStore = dataStore
    }
    
    func fetch(_ closure: (KuriEntity) -> Void) throws  {
        return try dataStore.fetch(closure)
    }
}