-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmvvmGenIOS.py
More file actions
68 lines (57 loc) · 3.09 KB
/
mvvmGenIOS.py
File metadata and controls
68 lines (57 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# encoding: utf-8
import click
import os
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
@click.command()
@click.option('--name', prompt='Name of the group to generate', help='Name of the group to generate.')
#@click.option('--name', prompt='Your name', help='The person to greet.')
def build(name):
capitalizedName = name.capitalize()
click.echo('Creating group named %s!' % name)
os.mkdir(name)
os.chdir(name)
vc = open(capitalizedName + 'ViewController.swift', 'wb')
writeVC(vc, capitalizedName)
protocol = open(capitalizedName + 'Protocol.swift', 'wb')
writeProtocol(protocol, capitalizedName)
presenter = open(capitalizedName + 'Presenter.swift', 'wb')
writePresenter(presenter, capitalizedName)
def writeVC(file, name):
print 'Start writing view controller'
# Headers
file.write('//\n// ' + name + 'ViewController.swift\n//\n// Template created by Edouard Libion on 30/12/16.\n// Copyright © 2016 Edouard Libion. All rights reserved.\n// Check my github for more cool stuff about IOS: https://github.com/edouardlib\n//')
# Class declaration
file.write('\n\nclass ' + name +'ViewController: BaseViewController, '+ name +'Protocol\n{')
# Properties & bindings
file.write('\n //\n // Properties\n //\n\n private let mPresenter = ' + name + 'Presenter()\n\n //\n // Binding views\n //\n\n')
# Life cycle
file.write(' //\n // Life cycle\n //\n \n override func loadView() {\n super.loadView()\n self.view.addSubview(Bundle.main.loadNibNamed("' + name + 'View", owner: self, options: nil)?[0] as! UIView)\n } \n\n override func viewDidLoad() {\n super.viewDidLoad()\n mPresenter.attachView(view: self)\n }\n')
# Acttions & methods implementation limiters
file.write(' //\n // Actions\n //\n\n //\n // View methods implementation\n //')
# end file
file.write('\n}')
file.close()
def writeProtocol(file, name):
print 'Start writing protocol'
# Headers
file.write('//\n// ' + name + 'ViewController.swift\n//\n// Template created by Edouard Libion on 30/12/16.\n// Copyright © 2016 Edouard Libion. All rights reserved.\n// Check my github for more cool stuff about IOS: https://github.com/edouardlib\n//')
# Class declaration
file.write('protocol '+ name +'Protocol: NSObjectProtocol {\n')
# end file
file.write('\n}')
file.close()
def writePresenter(file, name):
print 'Start writing presenter'
# Headers
file.write('//\n// ' + name + 'ViewController.swift\n//\n// Template created by Edouard Libion on 30/12/16.\n// Copyright © 2016 Edouard Libion. All rights reserved.\n// Check my github for more cool stuff about IOS: https://github.com/edouardlib\n//')
# Class declaration
file.write('class ' + name + 'Presenter {\n\n')
# Methods
file.write(' var disposeBag = DisposeBag()\n\n\n func attachView(view:'+ name + 'Protocol){\n viewController = view\n }\n \n func detachView() {\n viewController = nil\ı\ı }')
# end file
file.write('\n}')
file.close()
if __name__ == '__main__':
build()