mt_tool 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.idea/mt_tool.iml +77 -27
  3. data/.idea/sonarlint/issuestore/4/7/4745e92ab1b53af3e65026337909045741e13bea +0 -0
  4. data/.idea/sonarlint/issuestore/5/2/5283f86f6adbda087dceb47c69b64e141dfb1e93 +0 -0
  5. data/.idea/sonarlint/issuestore/7/0/70213f721c971c9a12d0f46060f7ee2a087b4a96 +0 -0
  6. data/.idea/sonarlint/issuestore/b/5/b53eec12e0ab8df9876dbc7fe65915bb985c4f72 +0 -0
  7. data/.idea/sonarlint/issuestore/e/8/e84cc700d4480c1d3ca7dcc158063e40a25cee12 +0 -0
  8. data/.idea/sonarlint/issuestore/f/8/f80e2edcdaf9ddf9362d26f7fa5d19df422f29c7 +0 -0
  9. data/.idea/sonarlint/issuestore/index.pb +13 -0
  10. data/Gemfile.lock +7 -3
  11. data/README.md +18 -7
  12. data/img/69786f8e2a527b8c26f2c1311e230e5f.webp.png +0 -0
  13. data/img/SCR-20240619-msnz.png +0 -0
  14. data/lib/mt_tool/commands.rb +23 -216
  15. data/lib/mt_tool/module/module.rb +275 -0
  16. data/lib/mt_tool/module/template/swift/Entity.swift +15 -0
  17. data/lib/mt_tool/module/template/swift/Interactor.swift +16 -0
  18. data/lib/mt_tool/module/template/swift/Presenter.swift +28 -0
  19. data/lib/mt_tool/module/template/swift/Router.swift +50 -0
  20. data/lib/mt_tool/module/template/swift/ViewController.swift +97 -0
  21. data/lib/mt_tool/oc_model/main.rb +112 -0
  22. data/lib/mt_tool/oc_model/oc_model.rb +235 -0
  23. data/lib/mt_tool/oc_model/sample.json +11 -0
  24. data/lib/mt_tool/short_hand/objc_generate_from_shorthand.rb +182 -0
  25. data/lib/mt_tool/short_hand/objc_header.mustache +41 -0
  26. data/lib/mt_tool/short_hand/objc_implementation.mustache +99 -0
  27. data/lib/mt_tool/short_hand/objc_shorthand.rb +64 -0
  28. data/lib/mt_tool/version.rb +1 -1
  29. data/mt_tool.gemspec +3 -1
  30. metadata +84 -21
  31. data/lib/mt_tool/analyze.rb +0 -126
  32. /data/lib/mt_tool/{template → module/template}/objc/Bundle.h +0 -0
  33. /data/lib/mt_tool/{template → module/template}/objc/Bundle.m +0 -0
  34. /data/lib/mt_tool/{template → module/template}/objc/CategoryHeader.h +0 -0
  35. /data/lib/mt_tool/{template → module/template}/objc/PrefixHeader.pch +0 -0
  36. /data/lib/mt_tool/{template → module/template}/objc/RouterDefine.h +0 -0
  37. /data/lib/mt_tool/{template → module/template}/objc/RouterRegister.h +0 -0
  38. /data/lib/mt_tool/{template → module/template}/objc/RouterRegister.m +0 -0
  39. /data/lib/mt_tool/{template → module/template}/objc/ServiceProtocol.h +0 -0
  40. /data/lib/mt_tool/{template → module/template}/objc/ServiceRegister.h +0 -0
  41. /data/lib/mt_tool/{template → module/template}/objc/ServiceRegister.m +0 -0
  42. /data/lib/mt_tool/{template → module/template}/objc/ToolsHeader.h +0 -0
  43. /data/lib/mt_tool/{template → module/template}/objc/VendorHeader.h +0 -0
  44. /data/lib/mt_tool/{template → module/template}/objc/demo/DemoViewController.h +0 -0
  45. /data/lib/mt_tool/{template → module/template}/objc/demo/DemoViewController.m +0 -0
  46. /data/lib/mt_tool/{template → module/template}/objc/demo/DemoViewModel.h +0 -0
  47. /data/lib/mt_tool/{template → module/template}/objc/demo/DemoViewModel.m +0 -0
  48. /data/lib/mt_tool/{template → module/template}/swift/RouterDefine.swift +0 -0
@@ -0,0 +1,275 @@
1
+
2
+ require 'colored'
3
+ require 'fileutils'
4
+ require 'psych'
5
+ require 'yaml'
6
+ require 'thor/actions'
7
+ require 'colored2'
8
+ require 'fileutils'
9
+ require 'psych'
10
+
11
+
12
+ module MtTool
13
+
14
+ CONFIG_FILE = '.MTModuleFilesConfig.yml'.freeze
15
+
16
+ class Module < Thor
17
+ include Thor::Actions
18
+ no_commands do
19
+
20
+ def initialize(args = [], options = {}, config = {})
21
+ super
22
+
23
+ end
24
+
25
+ def generate(path = nil, name, lang, class_prefix, author)
26
+
27
+ @name = name
28
+ @module = @name
29
+ @lang = lang
30
+ @class_prefix = class_prefix
31
+ @final_path = "#{path}/#{@name}"
32
+ @author = author
33
+ @prefixed_module = @class_prefix + @module
34
+
35
+ say "generating file in path:#{@final_path}", :green
36
+
37
+ if File.exist?(@final_path.to_s)
38
+ say "#{@final_path} 已存在:", :red
39
+ else
40
+ prepare_folder
41
+ if File.exist?("#{@final_path}/configure")
42
+ system("#{@final_path}/configure", @name, @lang, @class_prefix, *@additional_args)
43
+ else
44
+ say 'Template does not have a configure file', :red
45
+ end
46
+ yk_module_folders
47
+ yk_template_files
48
+ end
49
+ end
50
+
51
+ def create(path = nil)
52
+
53
+ path = Dir.pwd if path.nil?
54
+ say '模块名:', :green
55
+ config_file_path = "#{path}/#{CONFIG_FILE}"
56
+ config = File.exist?(config_file_path) ? YAML.load_file(config_file_path) : {}
57
+ input_name = ask("Project name [#{config[:project]}] ?")
58
+
59
+ if input_name != ''
60
+ @name = input_name
61
+ config[:project] = input_name if input_name != config[:project]
62
+ else
63
+ @name = config[:project]
64
+ end
65
+
66
+ File.open(config_file_path, 'w') do |f|
67
+ f.write config.to_yaml
68
+ end
69
+
70
+ @final_path = "#{path}/#{@name}"
71
+
72
+ if File.exist?(@final_path.to_s)
73
+ say "#{@final_path} 已存在:", :red
74
+ else
75
+ prepare_folder
76
+ read_config(path)
77
+
78
+ if File.exist?("#{@final_path}/configure")
79
+ system("#{@final_path}/configure", @name, @lang, @class_prefix, *@additional_args)
80
+ else
81
+ say 'Template does not have a configure file', :red
82
+ end
83
+
84
+ yk_module_folders
85
+ yk_template_files
86
+
87
+ end
88
+ end
89
+
90
+
91
+ def read_config(path)
92
+ config_file_path = "#{path}/#{CONFIG_FILE}"
93
+ config = File.exist?(config_file_path) ? YAML.load_file(config_file_path) : {}
94
+
95
+ project = @name
96
+ say '语言:', :green
97
+ language = ask("Project language [#{config[:language]}] ?", limited_to: ['objc', 'swift', ''])
98
+ say '类名前缀:', :green
99
+ class_prefix = ask("Class prefix [#{config[:class_prefix]}] ?")
100
+ say '文件作者:', :green
101
+ author = ask("Author [#{config[:author]}] ?")
102
+
103
+ config[:project] = project.empty? ? config[:project] || '' : project
104
+ config[:language] = language.empty? ? config[:language] || 'objc' : language
105
+ config[:class_prefix] = class_prefix.empty? ? config[:class_prefix] || '' : class_prefix
106
+ config[:author] = author.empty? ? config[:author] || '' : author
107
+
108
+ File.open(config_file_path, 'w') do |f|
109
+ f.write config.to_yaml
110
+ # f.write YAML.to_yaml(config)
111
+ end
112
+
113
+ @module = @name
114
+ @class_prefix = config[:class_prefix]
115
+ @prefixed_module = config[:class_prefix] + @module
116
+ @project = config[:project]
117
+ @author = config[:author]
118
+ @date = Time.now.strftime('%d/%m/%y')
119
+ @lang = config[:language]
120
+ end
121
+ def prepare_folder
122
+ host_a = 'yeah'
123
+ host_b = 'ka'
124
+ template_repo_url = "http://gitlab.#{host_a}#{host_b}.com/App/iOS/YKComponents/YKProjectTemplate.git"
125
+ system("git clone #{template_repo_url} #{@final_path}")
126
+
127
+ # FileUtils.remove_dir(@final_path, true)
128
+ # FileUtils.cp_r('/Users/imacn24/Documents/dev/YKProjectTemplate', @final_path)
129
+ # FileUtils.remove_dir("#{@final_path}/.git", true)
130
+ end
131
+
132
+ def create_viper_module(path = nil, name, lang, class_prefix, author)
133
+ @name = name
134
+ @module = @name
135
+ @lang = lang
136
+ @class_prefix = class_prefix
137
+ @final_path = "#{path}/#{@name}"
138
+ @author = author
139
+ @prefixed_module = @class_prefix + @module
140
+
141
+ say "generating file in path:#{@final_path}", :green
142
+
143
+ if File.exist?(@final_path.to_s)
144
+ say "#{@final_path} 已存在:", :red
145
+ else
146
+ mt_viper_module
147
+ end
148
+ end
149
+
150
+
151
+ def mt_viper_module
152
+ class_folder_path = "#{@final_path}"
153
+ class_folder_files= {
154
+ 'Entity.swift' => 'Entity',
155
+ 'Interactor.swift' => 'Entity',
156
+ 'Presenter.swift' => 'Entity',
157
+ 'Router.swift' => 'Entity',
158
+ 'ViewController.swift' => 'Entity',
159
+ }
160
+
161
+ class_folder_files.each do |file_name, _folder|
162
+ final_file = "#{class_folder_path}/#{@prefixed_module}#{file_name}"
163
+ template "#{__dir__}/template/swift/#{file_name}", final_file
164
+ end
165
+
166
+ end
167
+
168
+
169
+ def yk_module_folders
170
+ class_folder_path = "#{@final_path}/#{@name}/Classes"
171
+
172
+ first_level_folders = %w[Public Private]
173
+
174
+ # public_level_folders = ['Register']
175
+ # public_level_folders.each do |folder|
176
+ # path = "#{class_folder_path}/Public/#{folder}"
177
+ # empty_directory path
178
+ # end
179
+
180
+ private_level_folders = %w[Business Category Vendor Tools]
181
+
182
+ first_level_folders.each do |folder|
183
+ path = "#{class_folder_path}/#{folder}"
184
+ empty_directory path
185
+ end
186
+
187
+ private_level_folders.each do |folder|
188
+ path = "#{class_folder_path}/Private/#{folder}"
189
+ empty_directory path
190
+ end
191
+ end
192
+
193
+
194
+ MtTool::Module.source_root(File.dirname(__FILE__))
195
+ def yk_template_files
196
+
197
+ register_path = "#{@final_path}/#{@name}/Classes/Private/Register"
198
+ registger = {
199
+ 'RouterRegister.h' => 'RouterRegister',
200
+ 'RouterRegister.m' => 'RouterRegister',
201
+ 'ServiceRegister.h' => 'ServiceRegister',
202
+ 'ServiceRegister.m' => 'ServiceRegister'
203
+ }
204
+
205
+ registger.each do |file_name, _folder|
206
+ final_file = "#{register_path}/#{@prefixed_module}#{file_name}"
207
+ template "#{__dir__}/template/objc/#{file_name}", final_file
208
+ end
209
+
210
+ public_folder_path = "#{@final_path}/#{@name}/Classes/Public"
211
+
212
+ template_code_filename = ['ServiceProtocol.h', 'RouterDefine.h']
213
+ template_code_filename.each do |file_name|
214
+ final_file = "#{public_folder_path}/#{@prefixed_module}#{file_name}"
215
+ source = "#{__dir__}/template/objc/#{file_name}"
216
+ template source, final_file
217
+ end
218
+
219
+ swift_template_code_filename = ['RouterDefine.swift']
220
+ swift_template_code_filename.each do |file_name|
221
+ final_file = "#{public_folder_path}/#{@prefixed_module}_Swift_#{file_name}"
222
+ source = "#{__dir__}/template/swift/#{file_name}"
223
+ template source, final_file
224
+ end
225
+
226
+ private_folder_path = "#{@final_path}/#{@name}/Classes/Private"
227
+ #pch file
228
+ # pch_file_name = "PrefixHeader.pch"
229
+ # final_file = "#{private_folder_path}/#{@prefixed_module}#{pch_file_name}"
230
+ # source = "#{__dir__}/template/objc/#{pch_file_name}"
231
+ # template source, final_file
232
+
233
+ private_level_folder_files = {
234
+ 'PrefixHeader.pch' => 'Business',
235
+ 'CategoryHeader.h' => 'Category',
236
+ 'ToolsHeader.h' => 'Tools',
237
+ 'vendorHeader.h' => 'Vendor'
238
+ }
239
+
240
+ private_level_folder_files.each do |file_name, folder|
241
+ final_prefix = @prefixed_module
242
+ if file_name == 'PrefixHeader.pch'
243
+ final_prefix = @module
244
+ end
245
+
246
+ final_file = "#{private_folder_path}/#{folder}/#{final_prefix}#{file_name}"
247
+ source = "#{__dir__}/template/objc/#{file_name}"
248
+ template source, final_file
249
+ end
250
+
251
+ tools_files_path = "#{@final_path}/#{@name}/Classes/Private/Tools"
252
+
253
+ tool_files = ['Bundle.h','Bundle.m']
254
+ tool_files.each do |file_name|
255
+ final_file = "#{tools_files_path}/#{@prefixed_module}#{file_name}"
256
+ source = "#{__dir__}/template/objc/#{file_name}"
257
+ template source, final_file
258
+ end
259
+
260
+ business_demo_path = "#{@final_path}/#{@name}/Classes/Private/Business"
261
+ demo_replace_file = ['DemoViewController.h', 'DemoViewController.m', 'DemoViewModel.h', 'DemoViewModel.m']
262
+ demo_replace_file.each do |file_name|
263
+ final_file = "#{business_demo_path}/Demo/#{@prefixed_module}#{file_name}"
264
+ source = "#{__dir__}/template/objc/demo/#{file_name}"
265
+ template source, final_file
266
+ end
267
+
268
+ Dir.chdir("#{@final_path}/Example") do
269
+ system 'pod install'
270
+ system "open './#{@name}.xcworkspace'"
271
+ end
272
+ end
273
+ end
274
+ end
275
+ end
@@ -0,0 +1,15 @@
1
+ //
2
+ // <%= @prefixed_module %>Entity.swift
3
+ // <%= @project %>
4
+ //
5
+ // Created by <%= @author %> on <%= @date %>.
6
+ //
7
+ //
8
+
9
+
10
+
11
+ import Foundation
12
+
13
+ struct <%= @prefixed_module %>Entity {
14
+
15
+ }
@@ -0,0 +1,16 @@
1
+ //
2
+ // <%= @prefixed_module %>Interactor.swift
3
+ // <%= @project %>
4
+ //
5
+ // Created by <%= @author %> on <%= @date %>.
6
+ //
7
+ //
8
+
9
+ import Foundation
10
+
11
+ protocol <%= @prefixed_module %>InteractorProtocol {
12
+ }
13
+
14
+ class <%= @prefixed_module %>Interactor: <%= @prefixed_module %>InteractorProtocol {
15
+ weak var presenter: <%= @prefixed_module %>PresenterProtocol?
16
+ }
@@ -0,0 +1,28 @@
1
+ //
2
+ // <%= @prefixed_module %>Presenter.swift
3
+ // <%= @project %>
4
+ //
5
+ // Created by <%= @author %> on <%= @date %>.
6
+ //
7
+ //
8
+
9
+ import Foundation
10
+
11
+ protocol <%= @prefixed_module %>PresenterProtocol: AnyObject {
12
+ func notifySignInTapped()
13
+ func notifySignUpTapped()
14
+ }
15
+
16
+ class <%= @prefixed_module %>Presenter: <%= @prefixed_module %>PresenterProtocol {
17
+ weak var view: <%= @prefixed_module %>ViewProtocol?
18
+ var router: <%= @prefixed_module %>RouterProtocol?
19
+ var interactor: <%= @prefixed_module %>InteractorProtocol?
20
+
21
+ func notifySignInTapped() {
22
+ router?.routeToSignIn(view as! <%= @prefixed_module %>ViewController)
23
+ }
24
+
25
+ func notifySignUpTapped() {
26
+ router?.routeToSignUp(view as! <%= @prefixed_module %>ViewController)
27
+ }
28
+ }
@@ -0,0 +1,50 @@
1
+ //
2
+ // <%= @prefixed_module %>Router.swift
3
+ // <%= @project %>
4
+ //
5
+ // Created by <%= @author %> on <%= @date %>.
6
+ //
7
+ //
8
+
9
+ import UIKit
10
+
11
+ typealias <%= @prefixed_module %>Entry = <%= @prefixed_module %>ViewProtocol & UIViewController
12
+
13
+ protocol <%= @prefixed_module %>RouterProtocol {
14
+ var entry: <%= @prefixed_module %>Entry? { get set }
15
+ func routeToSignIn(_ view: <%= @prefixed_module %>ViewProtocol)
16
+ func routeToSignUp(_ view: <%= @prefixed_module %>ViewProtocol)
17
+ }
18
+
19
+ class <%= @prefixed_module %>Router: <%= @prefixed_module %>RouterProtocol {
20
+
21
+ var entry: <%= @prefixed_module %>Entry?
22
+
23
+ static func createModule() -> <%= @prefixed_module %>RouterProtocol {
24
+ let view = <%= @prefixed_module %>ViewController()
25
+ let interactor = <%= @prefixed_module %>Interactor()
26
+ let presenter = <%= @prefixed_module %>Presenter()
27
+ let router = <%= @prefixed_module %>Router()
28
+
29
+ view.presenter = presenter
30
+ interactor.presenter = presenter
31
+ presenter.view = view
32
+ presenter.router = router
33
+ presenter.interactor = interactor
34
+ router.entry = view
35
+
36
+ return router
37
+ }
38
+
39
+ func routeToSignIn(_ view: <%= @prefixed_module %>ViewProtocol) {
40
+ let signInVC = SignInRouter.createModule()
41
+ guard let view = view as? UIViewController else { return }
42
+ view.navigationController?.pushViewController(signInVC, animated: true)
43
+ }
44
+
45
+ func routeToSignUp(_ view: <%= @prefixed_module %>ViewProtocol) {
46
+ let signUpVC = SignUpRouter.createModule()
47
+ guard let view = view as? UIViewController else { return }
48
+ view.navigationController?.pushViewController(signUpVC, animated: true)
49
+ }
50
+ }
@@ -0,0 +1,97 @@
1
+ //
2
+ // <%= @prefixed_module %>ViewController.swift
3
+ // <%= @project %>
4
+ //
5
+ // Created by <%= @author %> on <%= @date %>.
6
+ //
7
+ //
8
+
9
+ import UIKit
10
+ protocol <%= @prefixed_module %>ViewProtocol: AnyObject {
11
+
12
+ }
13
+
14
+ class <%= @prefixed_module %>ViewController: UIViewController, <%= @prefixed_module %>ViewProtocol {
15
+
16
+ var presenter: <%= @prefixed_module %>PresenterProtocol?
17
+
18
+ lazy var button1: UIButton = {
19
+ let button = UIButton(type: .system)
20
+ button.setTitle("button 1", for: .normal)
21
+ button.addTarget(self, action: #selector(sampleButton1Tapped), for: .touchUpInside)
22
+ return button
23
+ }()
24
+
25
+ lazy var button2: UIButton = {
26
+ let button = UIButton(type: .system)
27
+ button.setTitle("button 2", for: .normal)
28
+ button.addTarget(self, action: #selector(sampleButton2Tapped), for: .touchUpInside)
29
+ return button
30
+ }()
31
+
32
+ //MARK: - View LifeCycle
33
+ override func viewDidLoad() {
34
+ super.viewDidLoad()
35
+ configureUI()
36
+ navigationItem.title = "Sample ViewController"
37
+ }
38
+
39
+ override func viewWillAppear(_ animated: Bool) {
40
+ super.viewWillAppear(animated)
41
+
42
+ }
43
+
44
+ override func viewWillDisappear(_ animated: Bool) {
45
+ super.viewWillDisappear(animated)
46
+
47
+ }
48
+
49
+ override func viewDidLayoutSubviews() {
50
+ super.viewDidLayoutSubviews()
51
+
52
+ }
53
+
54
+ //MARK: - View Configurations
55
+ private func configureUI() {
56
+ view.backgroundColor = .white
57
+ embedViewController(containerView: view, controller: PeaceCometsViewController(), previous: nil)
58
+
59
+ view.addSubview(button1)
60
+ view.addSubview(button2)
61
+
62
+ button1.backgroundColor = UIColor.purple.withAlphaComponent(0.5)
63
+ button2.backgroundColor = UIColor.red.withAlphaComponent(0.5)
64
+
65
+ setupConstraints()
66
+ }
67
+
68
+
69
+ func setupConstraints() {
70
+ button1.snp.makeConstraints { make in
71
+ make.centerX.equalToSuperview()
72
+ make.top.equalTo(view.safeAreaLayoutGuide.snp.top).offset(100)
73
+ make.width.equalTo(200)
74
+ make.height.equalTo(50)
75
+ }
76
+
77
+ button2.snp.makeConstraints { make in
78
+ make.centerX.equalToSuperview()
79
+ make.top.equalTo(button1.snp.bottom).offset(20)
80
+ make.width.equalTo(200)
81
+ make.height.equalTo(50)
82
+ }
83
+ }
84
+
85
+
86
+ @objc func sampleButton1Tapped() {
87
+ print("sample button 1 tapped")
88
+
89
+ }
90
+
91
+
92
+ @objc func sampleButton2Tapped() {
93
+ print("sample button 2 tapped")
94
+
95
+ }
96
+ }
97
+
@@ -0,0 +1,112 @@
1
+ require 'json'
2
+
3
+ $class_full_name = ARGV[0]
4
+ input_file_path = ARGV[1]
5
+
6
+ input_file = File.read(input_file_path)
7
+ input_json = JSON.parse(input_file)
8
+
9
+ input_dir = File.dirname(input_file_path)
10
+
11
+ # constants
12
+ OBJC_TYPE_STRING = "NSString *"
13
+ OBJC_TYPE_NUMBER = "NSNumber *"
14
+ OBJC_TYPE_NSDIC = "NSDictionary *"
15
+ OBJC_TYPE_ID = "id"
16
+ OBJC_TYPE_ARRAY = "NSArray *"
17
+ OBJC_TYPE_BOOL = "BOOL"
18
+ OBJC_TYPE_NULL = "NSNull *"
19
+
20
+ # attributes
21
+ ATTRIBUTE_NONATOMIC = "nonatomic"
22
+ ATTRIBUTE_COPY = "copy"
23
+ $class_full_name
24
+
25
+ $type_map = {
26
+ "String" => OBJC_TYPE_STRING,
27
+ "Integer" => OBJC_TYPE_NUMBER,
28
+ "Float" => OBJC_TYPE_NUMBER,
29
+ "Hash" => OBJC_TYPE_NSDIC,
30
+ #"Hash" => OBJC_TYPE_ID,
31
+ "Array" => OBJC_TYPE_ARRAY,
32
+ "TrueClass" => OBJC_TYPE_BOOL,
33
+ "FalseClass" => OBJC_TYPE_BOOL,
34
+ "NilClass" => OBJC_TYPE_NULL,
35
+ }
36
+
37
+ $attr_map = {
38
+ OBJC_TYPE_STRING => [ATTRIBUTE_NONATOMIC, ATTRIBUTE_COPY],
39
+ OBJC_TYPE_NUMBER => [ATTRIBUTE_NONATOMIC],
40
+ OBJC_TYPE_ID => [ATTRIBUTE_NONATOMIC],
41
+ OBJC_TYPE_NSDIC => [ATTRIBUTE_NONATOMIC],
42
+ OBJC_TYPE_ARRAY => [ATTRIBUTE_NONATOMIC, ATTRIBUTE_COPY],
43
+ OBJC_TYPE_BOOL => [ATTRIBUTE_NONATOMIC],
44
+ OBJC_TYPE_NULL => [ATTRIBUTE_NONATOMIC]
45
+ }
46
+
47
+ # generate info
48
+ $prop_declare = "@property"
49
+
50
+ def attr_name_for_attr_array(attr_array)
51
+ attr_name = ""
52
+
53
+ attr_array.each_with_index do |attribute, index|
54
+ if index != 0
55
+ attr_name << ", #{attribute}"
56
+ else
57
+ attr_name << "#{attribute}"
58
+ end
59
+
60
+ end
61
+
62
+ return attr_name
63
+ end
64
+
65
+ def prop_for_key_value(key, value)
66
+ type = $type_map["#{value.class}"]
67
+ attribute = attr_name_for_attr_array($attr_map[type])
68
+ var_name = key
69
+ prop_ret = "#{$prop_declare} (#{attribute}) #{type}#{var_name};"
70
+
71
+ return prop_ret
72
+ end
73
+
74
+ # puts type_map
75
+ header_comment = <<comment
76
+ // #{$class_full_name}.h
77
+ //
78
+ // Created by #{ENV['USER']} on #{Time.now.strftime("%Y/%m/%d")}
79
+ // Model file Generated using objc_export https://github.com/gogozs/objc_export
80
+ comment
81
+
82
+ header_result = ""
83
+ header_result << header_comment
84
+ header_result << "\n#import <Foundation/Foundation.h>\n\n"
85
+ header_result << "@interface #{$class_full_name} : NSObject\n\n"
86
+ header_file_name = "#{$class_full_name}.h"
87
+
88
+ imp_result = ""
89
+ imp_result << "#import \"#{header_file_name}\"\n\n"
90
+ imp_result << "@interface #{$class_full_name} ()\n@end\n\n"
91
+
92
+ imp_result << "@implementation #{$class_full_name}\n"
93
+ imp_result << "@end"
94
+
95
+ imp_file_name = "#{$class_full_name}.m"
96
+
97
+ input_json.each do |key, value|
98
+ header_result << "#{prop_for_key_value(key, value)}\n"
99
+ end
100
+ header_result << "\n@end"
101
+
102
+ header_file_path = "#{input_dir}/#{header_file_name}"
103
+ imp_file_path = "#{input_dir}/#{imp_file_name}"
104
+
105
+ File.open(header_file_path, 'w') do |io|
106
+ io << header_result
107
+ end
108
+
109
+ File.open(imp_file_path, 'w') do |io|
110
+ io << imp_result
111
+ end
112
+