iosgen 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +37 -0
- data/.hound.yml +6 -0
- data/.rubocop.yml +7 -0
- data/Gemfile +19 -0
- data/Gemfile.lock +110 -0
- data/Guardfile +16 -0
- data/LICENSE +22 -0
- data/README.md +158 -0
- data/Rakefile +28 -0
- data/bin/iosgen +6 -0
- data/iosgen.gemspec +29 -0
- data/lib/ios_gen/base/action.rb +15 -0
- data/lib/ios_gen/base/base_factory.rb +73 -0
- data/lib/ios_gen/base/interactor.rb +15 -0
- data/lib/ios_gen/base/property.rb +13 -0
- data/lib/ios_gen/base/view_controller.rb +15 -0
- data/lib/ios_gen/base/view_model.rb +16 -0
- data/lib/ios_gen/generator/base_generator.rb +61 -0
- data/lib/ios_gen/generator/objc/action_formatter.rb +35 -0
- data/lib/ios_gen/generator/objc/interactor_formatter.rb +68 -0
- data/lib/ios_gen/generator/objc/objc_formatter.rb +30 -0
- data/lib/ios_gen/generator/objc/view_controller_formatter.rb +37 -0
- data/lib/ios_gen/generator/objc/view_model_formatter.rb +88 -0
- data/lib/ios_gen/ios_gen_thor.rb +17 -0
- data/lib/iosgen.rb +5 -0
- data/spec/ios_gen/base/action_spec.rb +50 -0
- data/spec/ios_gen/base/base_factory_spec.rb +238 -0
- data/spec/ios_gen/base/interactor_spec.rb +60 -0
- data/spec/ios_gen/base/property_spec.rb +26 -0
- data/spec/ios_gen/base/view_controller_spec.rb +18 -0
- data/spec/ios_gen/base/view_model_spec.rb +70 -0
- data/spec/ios_gen/generator/base_generator_spec.rb +84 -0
- data/spec/ios_gen/generator/objc/action_formatter_spec.rb +88 -0
- data/spec/ios_gen/generator/objc/interactor_formatter_spec.rb +79 -0
- data/spec/ios_gen/generator/objc/objc_formatter_spec.rb +52 -0
- data/spec/ios_gen/generator/objc/view_controller_formatter_spec.rb +52 -0
- data/spec/ios_gen/generator/objc/view_model_formatter_spec.rb +125 -0
- data/spec/ios_gen/generator/spec.json +58 -0
- data/spec/spec_helper.rb +8 -0
- data/templates/objc/Interactor.h.erb +11 -0
- data/templates/objc/Interactor.m.erb +13 -0
- data/templates/objc/InteractorProtocol.h.erb +9 -0
- data/templates/objc/UIViewController.h.erb +8 -0
- data/templates/objc/UIViewController.m.erb +31 -0
- data/templates/objc/ViewModel.h.erb +9 -0
- data/templates/objc/ViewModel.m.erb +13 -0
- data/templates/objc/ViewModelProtocol.h.erb +16 -0
- metadata +178 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
# CLI for generator
|
2
|
+
class IOSGenThor < Thor
|
3
|
+
include Thor::Actions
|
4
|
+
|
5
|
+
def self.source_root
|
6
|
+
File.dirname(__FILE__)
|
7
|
+
end
|
8
|
+
|
9
|
+
desc 'generate', 'Generate new code with spec file'
|
10
|
+
# method_option :destination, aliases: '-d', desc: 'destination path'
|
11
|
+
# method_option :languague, aliases: '-l', desc: 'objc or swift'
|
12
|
+
def generate(file_path)
|
13
|
+
puts file_path
|
14
|
+
generator = IOSGen::Generator::BaseGenerator.new(file_spec: file_path)
|
15
|
+
generator.generate
|
16
|
+
end
|
17
|
+
end
|
data/lib/iosgen.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include IOSGen::Base
|
4
|
+
|
5
|
+
describe IOSGen::Base::Action do
|
6
|
+
|
7
|
+
description = 'Dismiss the ViewController when the button is tapped'
|
8
|
+
return_type = 'void'
|
9
|
+
name = 'didTapOnCloseButton:'
|
10
|
+
arguments = [Property.new(type: 'UIButton',
|
11
|
+
name: 'closeButton')]
|
12
|
+
|
13
|
+
describe '#Properties' do
|
14
|
+
action = described_class.new(description: description,
|
15
|
+
return_type: return_type, name: name,
|
16
|
+
arguments: arguments)
|
17
|
+
|
18
|
+
it 'has description' do
|
19
|
+
expect(action.description).to eq(description)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'has return_type' do
|
23
|
+
expect(action.return_type).to eq(return_type)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'has name' do
|
27
|
+
expect(action.name).to eq(name)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'has arguments' do
|
31
|
+
expect(action.arguments.empty?).to be false
|
32
|
+
property = action.arguments[0]
|
33
|
+
expect(property).to be_kind_of Property
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'Optional Properties' do
|
39
|
+
|
40
|
+
action = described_class.new(description: description,
|
41
|
+
return_type: return_type,
|
42
|
+
name: name)
|
43
|
+
|
44
|
+
it 'has not arguments' do
|
45
|
+
expect(action.arguments.nil?).to be true
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,238 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe IOSGen::Base::BaseFactory do
|
4
|
+
|
5
|
+
describe '#Property' do
|
6
|
+
|
7
|
+
json = '{
|
8
|
+
"type": "UIButton",
|
9
|
+
"name": "button"
|
10
|
+
}'
|
11
|
+
|
12
|
+
it 'expect to parse JSON' do
|
13
|
+
factory = described_class.new
|
14
|
+
hash = JSON.parse(json)
|
15
|
+
property = factory.parse_property(hash)
|
16
|
+
expect(property).to be_a Property
|
17
|
+
expect(property.type).to eq('UIButton')
|
18
|
+
expect(property.name).to eq('button')
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#Action' do
|
24
|
+
|
25
|
+
description = 'Dismiss the ViewController when the button is tapped'
|
26
|
+
name = 'didTapOnCloseButton:'
|
27
|
+
return_type = 'void'
|
28
|
+
json = '{
|
29
|
+
"description": "Dismiss the ViewController when the button is tapped",
|
30
|
+
"return_type": "void",
|
31
|
+
"name": "didTapOnCloseButton:",
|
32
|
+
"arguments": [{
|
33
|
+
"type" : "UIButton",
|
34
|
+
"name" : "closeButton"
|
35
|
+
}]
|
36
|
+
}'
|
37
|
+
|
38
|
+
it 'expect to parse JSON' do
|
39
|
+
factory = described_class.new
|
40
|
+
hash = JSON.parse(json)
|
41
|
+
action = factory.parse_action(hash)
|
42
|
+
expect(action.description).to eq(description)
|
43
|
+
expect(action.return_type).to eq(return_type)
|
44
|
+
expect(action.name).to eq(name)
|
45
|
+
expect(action.arguments.nil?).to be false
|
46
|
+
property = action.arguments[0]
|
47
|
+
expect(property).to be_a Property
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#Interactor' do
|
53
|
+
|
54
|
+
description = 'Api Interactions required by Notification ViewModel'
|
55
|
+
name = 'FJBNotificationsApiInteractor'
|
56
|
+
|
57
|
+
json = '{
|
58
|
+
"description" : "Api Interactions required by Notification ViewModel",
|
59
|
+
"name": "FJBNotificationsApiInteractor",
|
60
|
+
"properties": [
|
61
|
+
{
|
62
|
+
"type": "UIButton",
|
63
|
+
"name": "button"
|
64
|
+
},
|
65
|
+
{
|
66
|
+
"type": "UIButton",
|
67
|
+
"name": "button2"
|
68
|
+
}
|
69
|
+
],
|
70
|
+
"actions": [
|
71
|
+
{
|
72
|
+
"description": "Perform API request to mark a notification as read",
|
73
|
+
"return_type": "void",
|
74
|
+
"name": "markNotificationAsRead:onCompletionBlock:",
|
75
|
+
"arguments": [
|
76
|
+
{
|
77
|
+
"type": "NSString",
|
78
|
+
"name": "notificationId"
|
79
|
+
},
|
80
|
+
{
|
81
|
+
"type": "^()",
|
82
|
+
"name": "completionBlock"
|
83
|
+
}
|
84
|
+
]
|
85
|
+
}
|
86
|
+
]
|
87
|
+
}'
|
88
|
+
|
89
|
+
factory = described_class.new
|
90
|
+
hash = JSON.parse(json)
|
91
|
+
interactor = factory.parse_interactor(hash)
|
92
|
+
|
93
|
+
it 'expect to parse JSON' do
|
94
|
+
expect(interactor).to be_a Interactor
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'has to match description' do
|
98
|
+
expect(interactor.description).to eq(description)
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'has to match name' do
|
102
|
+
expect(interactor.name).to eq(name)
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'has to containt properties' do
|
106
|
+
expect(interactor.properties).to be_a Array
|
107
|
+
expect(interactor.properties.length).to eq(2)
|
108
|
+
property0 = interactor.properties[0]
|
109
|
+
property1 = interactor.properties[1]
|
110
|
+
expect(property0).to be_a Property
|
111
|
+
expect(property1).to be_a Property
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'has to containt actions' do
|
115
|
+
expect(interactor.actions).to be_a Array
|
116
|
+
expect(interactor.actions.length).to eq(1)
|
117
|
+
action = interactor.actions[0]
|
118
|
+
expect(action).to be_a Action
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe '#ViewModels' do
|
123
|
+
|
124
|
+
description = 'State of NotificationViewController and perform bussiness logic'
|
125
|
+
name = 'FJBNotificationsViewModel'
|
126
|
+
|
127
|
+
json = '{
|
128
|
+
"description" : "State of NotificationViewController and perform bussiness logic",
|
129
|
+
"name": "FJBNotificationsViewModel",
|
130
|
+
"properties": [
|
131
|
+
{
|
132
|
+
"type": "NSIndexPath",
|
133
|
+
"name": "selectedIndexPath"
|
134
|
+
}
|
135
|
+
],
|
136
|
+
"actions": [
|
137
|
+
{
|
138
|
+
"description": "Dismiss the ViewController when the button is tapped",
|
139
|
+
"retun_type": "void",
|
140
|
+
"name": "didTapOnCloseButton"
|
141
|
+
},
|
142
|
+
{
|
143
|
+
"description": "Mark notification as read when the notification is selected",
|
144
|
+
"retun_type": "void",
|
145
|
+
"name": "didTapAtIndexPath:",
|
146
|
+
"arguments": [
|
147
|
+
{
|
148
|
+
"type": "NSIndexPath",
|
149
|
+
"name": "indexPath"
|
150
|
+
}
|
151
|
+
]
|
152
|
+
}
|
153
|
+
],
|
154
|
+
"interactors": [
|
155
|
+
{
|
156
|
+
"description" : "Api Interactions required by Notification ViewModel",
|
157
|
+
"name": "FJBNotificationsApiInteractor",
|
158
|
+
"properties": [],
|
159
|
+
"actions": [
|
160
|
+
{
|
161
|
+
"description": "Perform API request to mark a notification as read",
|
162
|
+
"return_type": "void",
|
163
|
+
"name": "markNotificationAsRead:onCompletionBlock:",
|
164
|
+
"arguments": [
|
165
|
+
{
|
166
|
+
"type": "NSString",
|
167
|
+
"name": "notificationId"
|
168
|
+
},
|
169
|
+
{
|
170
|
+
"type": "^()",
|
171
|
+
"name": "completionBlock"
|
172
|
+
}
|
173
|
+
]
|
174
|
+
}
|
175
|
+
]
|
176
|
+
}
|
177
|
+
]
|
178
|
+
}'
|
179
|
+
|
180
|
+
factory = described_class.new
|
181
|
+
hash = JSON.parse(json)
|
182
|
+
view_model = factory.parse_view_model(hash)
|
183
|
+
|
184
|
+
it 'has a description' do
|
185
|
+
expect(view_model.description).to eq(description)
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'has a name' do
|
189
|
+
expect(view_model.name).to eq(name)
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'has properties' do
|
193
|
+
expect(view_model.properties).to be_a Array
|
194
|
+
expect(view_model.properties.length).to eq(1)
|
195
|
+
property = view_model.properties[0]
|
196
|
+
expect(property).to be_a Property
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'has actions' do
|
200
|
+
expect(view_model.actions).to be_a Array
|
201
|
+
expect(view_model.actions.length).to eq(2)
|
202
|
+
action0 = view_model.actions[0]
|
203
|
+
action1 = view_model.actions[1]
|
204
|
+
expect(action0).to be_a Action
|
205
|
+
expect(action1).to be_a Action
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'has interactors' do
|
209
|
+
expect(view_model.interactors).to be_a Array
|
210
|
+
expect(view_model.interactors.length).to eq(1)
|
211
|
+
interactor = view_model.interactors[0]
|
212
|
+
expect(interactor).to be_a Interactor
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
describe '#ViewController' do
|
217
|
+
json = '{
|
218
|
+
"description": "ViewController to show the list of notifications",
|
219
|
+
"name": "FJBNotificationViewController",
|
220
|
+
"view_model": "FJBNotificationsViewModel"
|
221
|
+
}'
|
222
|
+
|
223
|
+
factory = described_class.new
|
224
|
+
hash = JSON.parse(json)
|
225
|
+
view_controller = factory.parse_view_controller(hash)
|
226
|
+
|
227
|
+
it 'expect to parse JSON' do
|
228
|
+
expect(view_controller).to be_a ViewController
|
229
|
+
end
|
230
|
+
|
231
|
+
it 'has name' do
|
232
|
+
expect(view_controller.name).to eq('FJBNotificationViewController')
|
233
|
+
end
|
234
|
+
it 'has description' do
|
235
|
+
expect(view_controller.description).to eq('ViewController to show the list of notifications')
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
include IOSGen::Base
|
3
|
+
|
4
|
+
describe IOSGen::Base::Interactor do
|
5
|
+
|
6
|
+
description = 'Api Interactions required by Notification ViewModel'
|
7
|
+
|
8
|
+
name = 'FJBNotificationsApiInteractor'
|
9
|
+
|
10
|
+
properties = [Property.new(type: 'TestType', name: 'TestName'),
|
11
|
+
Property.new(type: 'TestType2', name: 'TestName2')]
|
12
|
+
|
13
|
+
action = Action.new(description: 'Perform API request to mark a notification as read',
|
14
|
+
return_type: 'void',
|
15
|
+
name: 'markNotificationAsRead:onCompletionBlock:',
|
16
|
+
arguments: [Property.new(type: 'NSString', name: 'notificationId'),
|
17
|
+
Property.new(type: '^()', name: 'completionBlock')])
|
18
|
+
actions = [action]
|
19
|
+
|
20
|
+
describe '#Properties' do
|
21
|
+
interactor = described_class.new(description: description,
|
22
|
+
name: name,
|
23
|
+
properties: properties,
|
24
|
+
actions: actions)
|
25
|
+
|
26
|
+
it 'has a description' do
|
27
|
+
expect(interactor.description).to eq(description)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'has a name' do
|
31
|
+
expect(interactor.name).to eq(name)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'has properties' do
|
35
|
+
expect(interactor.properties).to be_a Array
|
36
|
+
expect(interactor.properties.length).to eq(2)
|
37
|
+
property1 = interactor.properties[0]
|
38
|
+
property2 = interactor.properties[1]
|
39
|
+
expect(property1).to be_a Property
|
40
|
+
expect(property2).to be_a Property
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'has actions' do
|
44
|
+
expect(interactor.actions).to be_a Array
|
45
|
+
expect(interactor.actions.length).to eq(1)
|
46
|
+
action = interactor.actions[0]
|
47
|
+
expect(action).to be_a Action
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'Optional properties' do
|
53
|
+
interactor = described_class.new(description: description,
|
54
|
+
name: name,
|
55
|
+
actions: actions)
|
56
|
+
it 'has not properties' do
|
57
|
+
expect(interactor.properties.nil?).to be true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
describe IOSGen::Base::Property do
|
5
|
+
|
6
|
+
describe '#Properties' do
|
7
|
+
|
8
|
+
type = 'NSIndexPath'
|
9
|
+
name = 'selectedIndexPath'
|
10
|
+
property = described_class.new(name: name, type: type)
|
11
|
+
|
12
|
+
it 'has to be a property' do
|
13
|
+
expect(property).to be_a described_class
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'has Type' do
|
17
|
+
expect(property.type).to eq(type)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'has Name' do
|
21
|
+
expect(property.name).to eq(name)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe IOSGen::Base::ViewController do
|
4
|
+
|
5
|
+
name = 'FJBNotificationViewController'
|
6
|
+
description = 'ViewController to display notifications'
|
7
|
+
view_controller = described_class.new(name: name,
|
8
|
+
description: description)
|
9
|
+
describe '#Properties' do
|
10
|
+
it 'has a description' do
|
11
|
+
expect(view_controller.description).to eq(description)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'has a name' do
|
15
|
+
expect(view_controller.name).to eq(name)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include IOSGen::Base
|
4
|
+
|
5
|
+
describe IOSGen::Base::ViewModel do
|
6
|
+
|
7
|
+
description = 'State of NotificationViewController and perform bussiness logic'
|
8
|
+
|
9
|
+
name = 'FJBNotificationsViewModel'
|
10
|
+
|
11
|
+
properties = [Property.new(type: 'NSIndexPath', name: 'selectedIndexPath')]
|
12
|
+
|
13
|
+
actions = [Action.new(description: 'Dismiss the ViewController when the button is tapped',
|
14
|
+
return_type: 'void',
|
15
|
+
name: 'didTapOnCloseButton'),
|
16
|
+
Action.new(description: 'Mark notification as read when the notification is selected',
|
17
|
+
return_type: 'void',
|
18
|
+
name: 'didTapAtIndexPath',
|
19
|
+
arguments: [Property.new(type: 'NSIndexPath',
|
20
|
+
name: 'indexPath')])]
|
21
|
+
|
22
|
+
interactors = [Interactor.new(description: 'Api Interactions required by Notification ViewModel',
|
23
|
+
name: 'FJBNotificationsApiInteractor',
|
24
|
+
actions: [Action.new(description: 'Perform API request to mark a notification as read',
|
25
|
+
return_type: 'void',
|
26
|
+
name: 'markNotificationAsRead:onCompletionBlock:',
|
27
|
+
arguments: [Property.new(type: 'NSString',
|
28
|
+
name: 'notificationId'),
|
29
|
+
Property.new(type: '^()',
|
30
|
+
name: 'completionBlock')
|
31
|
+
])])]
|
32
|
+
describe '#Properties' do
|
33
|
+
|
34
|
+
view_model = described_class.new(description: description,
|
35
|
+
name: name,
|
36
|
+
properties: properties,
|
37
|
+
actions: actions,
|
38
|
+
interactors: interactors)
|
39
|
+
it 'has a description' do
|
40
|
+
expect(view_model.description).to eq(description)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'has a name' do
|
44
|
+
expect(view_model.name).to eq(name)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'has properties' do
|
48
|
+
properties = view_model.properties
|
49
|
+
expect(properties.length).to eq(1)
|
50
|
+
property = properties[0]
|
51
|
+
expect(property).to be_a Property
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'has actions' do
|
55
|
+
actions = view_model.actions
|
56
|
+
expect(actions.length).to eq(2)
|
57
|
+
action0 = actions[0]
|
58
|
+
action1 = actions[1]
|
59
|
+
expect(action0).to be_a Action
|
60
|
+
expect(action1).to be_a Action
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'has interactors' do
|
64
|
+
interactors = view_model.interactors
|
65
|
+
expect(interactors.length).to eq(1)
|
66
|
+
interactor = interactors[0]
|
67
|
+
expect(interactor).to be_a Interactor
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|