mt_tool 0.1.2 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.idea/mt_tool.iml +81 -49
- data/.idea/sonarlint/issuestore/4/7/4745e92ab1b53af3e65026337909045741e13bea +0 -0
- data/.idea/sonarlint/issuestore/5/2/5283f86f6adbda087dceb47c69b64e141dfb1e93 +0 -0
- data/.idea/sonarlint/issuestore/7/0/70213f721c971c9a12d0f46060f7ee2a087b4a96 +0 -0
- data/.idea/sonarlint/issuestore/b/5/b53eec12e0ab8df9876dbc7fe65915bb985c4f72 +0 -0
- data/.idea/sonarlint/issuestore/e/8/e84cc700d4480c1d3ca7dcc158063e40a25cee12 +0 -0
- data/.idea/sonarlint/issuestore/f/8/f80e2edcdaf9ddf9362d26f7fa5d19df422f29c7 +0 -0
- data/.idea/sonarlint/issuestore/index.pb +13 -0
- data/Gemfile.lock +7 -3
- data/README.md +18 -7
- data/img/69786f8e2a527b8c26f2c1311e230e5f.webp.png +0 -0
- data/img/SCR-20240619-msnz.png +0 -0
- data/lib/mt_tool/commands.rb +27 -214
- data/lib/mt_tool/module/module.rb +275 -0
- data/lib/mt_tool/module/template/objc/Bundle.h +21 -0
- data/lib/mt_tool/module/template/objc/Bundle.m +28 -0
- data/lib/mt_tool/{template → module/template}/objc/CategoryHeader.h +1 -0
- data/lib/mt_tool/{template → module/template}/objc/PrefixHeader.pch +6 -0
- data/lib/mt_tool/{template → module/template}/objc/ToolsHeader.h +1 -1
- data/lib/mt_tool/module/template/swift/Entity.swift +15 -0
- data/lib/mt_tool/module/template/swift/Interactor.swift +16 -0
- data/lib/mt_tool/module/template/swift/Presenter.swift +28 -0
- data/lib/mt_tool/module/template/swift/Router.swift +50 -0
- data/lib/mt_tool/module/template/swift/ViewController.swift +97 -0
- data/lib/mt_tool/oc_model/main.rb +112 -0
- data/lib/mt_tool/oc_model/oc_model.rb +235 -0
- data/lib/mt_tool/oc_model/sample.json +11 -0
- data/lib/mt_tool/short_hand/objc_generate_from_shorthand.rb +182 -0
- data/lib/mt_tool/short_hand/objc_header.mustache +41 -0
- data/lib/mt_tool/short_hand/objc_implementation.mustache +99 -0
- data/lib/mt_tool/short_hand/objc_shorthand.rb +64 -0
- data/lib/mt_tool/version.rb +1 -1
- data/mt_tool.gemspec +3 -1
- metadata +84 -19
- data/lib/mt_tool/analyze.rb +0 -126
- /data/lib/mt_tool/{template → module/template}/objc/RouterDefine.h +0 -0
- /data/lib/mt_tool/{template → module/template}/objc/RouterRegister.h +0 -0
- /data/lib/mt_tool/{template → module/template}/objc/RouterRegister.m +0 -0
- /data/lib/mt_tool/{template → module/template}/objc/ServiceProtocol.h +0 -0
- /data/lib/mt_tool/{template → module/template}/objc/ServiceRegister.h +0 -0
- /data/lib/mt_tool/{template → module/template}/objc/ServiceRegister.m +0 -0
- /data/lib/mt_tool/{template → module/template}/objc/VendorHeader.h +0 -0
- /data/lib/mt_tool/{template → module/template}/objc/demo/DemoViewController.h +0 -0
- /data/lib/mt_tool/{template → module/template}/objc/demo/DemoViewController.m +0 -0
- /data/lib/mt_tool/{template → module/template}/objc/demo/DemoViewModel.h +0 -0
- /data/lib/mt_tool/{template → module/template}/objc/demo/DemoViewModel.m +0 -0
- /data/lib/mt_tool/{template → module/template}/swift/RouterDefine.swift +0 -0
@@ -0,0 +1,235 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'thor'
|
3
|
+
require 'active_support/all'
|
4
|
+
|
5
|
+
module MtTool
|
6
|
+
|
7
|
+
class OcModel < Thor
|
8
|
+
|
9
|
+
# constants
|
10
|
+
OBJC_TYPE_STRING = "NSString *"
|
11
|
+
OBJC_TYPE_NUMBER = "NSNumber *"
|
12
|
+
OBJC_TYPE_ID = "id"
|
13
|
+
OBJC_TYPE_NSDIC = "NSDictionary *"
|
14
|
+
|
15
|
+
OBJC_TYPE_ARRAY = "NSArray *"
|
16
|
+
OBJC_TYPE_BOOL = "BOOL"
|
17
|
+
OBJC_TYPE_NULL = "NSNull *"
|
18
|
+
|
19
|
+
# attributes
|
20
|
+
ATTRIBUTE_NONATOMIC = "nonatomic"
|
21
|
+
ATTRIBUTE_COPY = "copy"
|
22
|
+
ATTRIBUTE_STRONG= "strong"
|
23
|
+
ATTRIBUTE_ASSIGN= "assign"
|
24
|
+
|
25
|
+
$type_map = {
|
26
|
+
"String" => OBJC_TYPE_STRING,
|
27
|
+
"Integer" => OBJC_TYPE_NUMBER,
|
28
|
+
"Float" => OBJC_TYPE_NUMBER,
|
29
|
+
# "Hash" => OBJC_TYPE_ID,
|
30
|
+
"Hash" => OBJC_TYPE_NSDIC,
|
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,ATTRIBUTE_COPY],
|
40
|
+
OBJC_TYPE_ID => [ATTRIBUTE_NONATOMIC,ATTRIBUTE_COPY],
|
41
|
+
OBJC_TYPE_NSDIC => [ATTRIBUTE_NONATOMIC,ATTRIBUTE_COPY],
|
42
|
+
OBJC_TYPE_ARRAY => [ATTRIBUTE_NONATOMIC, ATTRIBUTE_COPY],
|
43
|
+
OBJC_TYPE_BOOL => [ATTRIBUTE_NONATOMIC,ATTRIBUTE_ASSIGN],
|
44
|
+
OBJC_TYPE_NULL => [ATTRIBUTE_NONATOMIC,ATTRIBUTE_ASSIGN]
|
45
|
+
}
|
46
|
+
|
47
|
+
# generate info
|
48
|
+
$prop_declare = "@property"
|
49
|
+
|
50
|
+
include Thor::Actions
|
51
|
+
|
52
|
+
def initialize(args = [], options = {}, config = {})
|
53
|
+
super
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
no_commands do
|
58
|
+
|
59
|
+
def qt_create(prefix,name, path = nil ,output_path = nil)
|
60
|
+
|
61
|
+
@json_path = path
|
62
|
+
@class_full_name = name
|
63
|
+
@file_name = name+'Model'
|
64
|
+
@output_path = output_path
|
65
|
+
system "quicktype --src #{path} --src-lang json --class-prefix #{prefix} --lang objc --top-level #{name} -o #{output_path}/#{prefix+name} --just-types "
|
66
|
+
end
|
67
|
+
|
68
|
+
def create(prefix,name, path = nil ,output_path = nil)
|
69
|
+
|
70
|
+
@json_path = path
|
71
|
+
@prefix = prefix
|
72
|
+
@class_full_name = name
|
73
|
+
@file_name = prefix+name+'Model'
|
74
|
+
@output_path = output_path
|
75
|
+
operate
|
76
|
+
end
|
77
|
+
|
78
|
+
def operate
|
79
|
+
|
80
|
+
input_file = File.read(@json_path)
|
81
|
+
input_json = JSON.parse(input_file)
|
82
|
+
|
83
|
+
|
84
|
+
header_result = ""
|
85
|
+
result = add_header_with_kv input_json
|
86
|
+
header_result << result
|
87
|
+
|
88
|
+
|
89
|
+
imp_result = add_imp_with_kv input_json
|
90
|
+
|
91
|
+
|
92
|
+
header_file_name = "#{@file_name}.h"
|
93
|
+
header_file_path = "#{@output_path}/#{header_file_name}"
|
94
|
+
imp_file_name = "#{@file_name}.m"
|
95
|
+
imp_file_path = "#{@output_path}/#{imp_file_name}"
|
96
|
+
|
97
|
+
File.open(header_file_path, 'w') do |io|
|
98
|
+
io << header_result
|
99
|
+
end
|
100
|
+
|
101
|
+
File.open(imp_file_path, 'w') do |io|
|
102
|
+
io << imp_result
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
def add_header_with_kv(json)
|
110
|
+
|
111
|
+
header_comment = <<comment
|
112
|
+
// #{@class_full_name}.h
|
113
|
+
//
|
114
|
+
// Created by #{ENV['USER']} on #{Time.now.strftime("%Y/%m/%d")}
|
115
|
+
comment
|
116
|
+
|
117
|
+
header_result = ''
|
118
|
+
header_result << header_comment
|
119
|
+
header_result << "\n\n\n"
|
120
|
+
header_result << "#import <Foundation/Foundation.h>\n\n"
|
121
|
+
header_result << "@interface #{@file_name} : NSObject\n\n"
|
122
|
+
|
123
|
+
sub_model_types = []
|
124
|
+
sub_model_kvs = {}
|
125
|
+
|
126
|
+
json.each do |key, value|
|
127
|
+
if value.class == Hash
|
128
|
+
attribute = attr_name_for_attr_array [ATTRIBUTE_NONATOMIC,ATTRIBUTE_STRONG]
|
129
|
+
type = @prefix+@class_full_name + key.camelize(:upper) + "Model"
|
130
|
+
var_name = key
|
131
|
+
header_result << "#{$prop_declare} (#{attribute}) #{type +" *"}#{var_name};\n"
|
132
|
+
sub_model_types.push type
|
133
|
+
sub_model_kvs[type] = value
|
134
|
+
elsif value.class == Array
|
135
|
+
|
136
|
+
attribute = attr_name_for_attr_array [ATTRIBUTE_NONATOMIC,ATTRIBUTE_STRONG]
|
137
|
+
type = @prefix+@class_full_name + key.camelize(:upper) + "Model"
|
138
|
+
var_name = key
|
139
|
+
header_result << "#{$prop_declare} (#{attribute}) NSArray <#{type+" *"}>*#{var_name};\n"
|
140
|
+
sub_model_types.push type
|
141
|
+
sub_model_kvs[type] = value
|
142
|
+
else
|
143
|
+
header_result << "#{prop_for_key_value(key, value)}\n"
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
header_result << "\n@end"
|
150
|
+
|
151
|
+
|
152
|
+
sub_model_types.each do |type|
|
153
|
+
header_result << "\n\n@interface #{type} : NSObject\n\n"
|
154
|
+
|
155
|
+
header_result << "\n@end\n"
|
156
|
+
end
|
157
|
+
header_result
|
158
|
+
end
|
159
|
+
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
def add_imp_with_kv(json)
|
165
|
+
imp_comment = <<comment
|
166
|
+
// #{@class_full_name}.h
|
167
|
+
//
|
168
|
+
// Created by #{ENV['USER']} on #{Time.now.strftime("%Y/%m/%d")}
|
169
|
+
comment
|
170
|
+
|
171
|
+
imp_result = ""
|
172
|
+
imp_result << imp_comment
|
173
|
+
imp_result << "\n\n\n"
|
174
|
+
imp_result << "#import \"#{@prefix+@class_full_name}\"\n\n"
|
175
|
+
imp_result << "@interface #{@prefix+@class_full_name} ()\n\n\n@end\n\n"
|
176
|
+
|
177
|
+
imp_result << "@implementation #{@prefix+@class_full_name}\n"
|
178
|
+
imp_result << "\n\n@end"
|
179
|
+
imp_result << "\n\n------------\n"
|
180
|
+
sub_model_types = []
|
181
|
+
|
182
|
+
|
183
|
+
json.each do |key, value|
|
184
|
+
if value.class == Hash
|
185
|
+
type = @prefix+@class_full_name + key.camelize(:upper) + "Model"
|
186
|
+
sub_model_types.push type
|
187
|
+
elsif value.class == Array
|
188
|
+
type = @prefix+@class_full_name + key.camelize(:upper) + "Model"
|
189
|
+
sub_model_types.push type
|
190
|
+
else
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|
195
|
+
sub_model_types.each do |type|
|
196
|
+
imp_result << "\n\n@implementation #{type} "
|
197
|
+
|
198
|
+
imp_result << "\n@end\n"
|
199
|
+
end
|
200
|
+
imp_result
|
201
|
+
|
202
|
+
end
|
203
|
+
|
204
|
+
def attr_name_for_attr_array(attr_array)
|
205
|
+
attr_name = ""
|
206
|
+
|
207
|
+
attr_array.each_with_index do |attribute, index|
|
208
|
+
if index != 0
|
209
|
+
attr_name << ", #{attribute}"
|
210
|
+
else
|
211
|
+
attr_name << "#{attribute}"
|
212
|
+
end
|
213
|
+
|
214
|
+
end
|
215
|
+
|
216
|
+
return attr_name
|
217
|
+
end
|
218
|
+
|
219
|
+
def prop_for_key_value(key, value)
|
220
|
+
type = $type_map["#{value.class}"]
|
221
|
+
attribute = attr_name_for_attr_array($attr_map[type])
|
222
|
+
var_name = key.camelize(:lower)
|
223
|
+
if key =='id'
|
224
|
+
var_name = 'ID'
|
225
|
+
end
|
226
|
+
prop_ret = "#{$prop_declare} (#{attribute}) #{type}#{var_name};"
|
227
|
+
|
228
|
+
return prop_ret
|
229
|
+
end
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'mustache'
|
5
|
+
require 'objc_shorthand'
|
6
|
+
|
7
|
+
# -------------
|
8
|
+
|
9
|
+
class ObjCClassTemplate < Mustache
|
10
|
+
attr_accessor :cls, :shorthand_file
|
11
|
+
|
12
|
+
def initialize cls, shorthand_file
|
13
|
+
@cls = cls
|
14
|
+
@shorthand_file = shorthand_file
|
15
|
+
end
|
16
|
+
|
17
|
+
def ivars
|
18
|
+
@cls.objc_ivars.map { |name, x| ObjCIvarTemplate.new(x) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def ivars_with_properties; ivars; end
|
22
|
+
def ivars_without_properties; []; end
|
23
|
+
|
24
|
+
def ivars_with_properties_without_ro
|
25
|
+
ivars_with_properties.select { |x| not x.ivar.options.include? :ro }
|
26
|
+
end
|
27
|
+
|
28
|
+
def ivars_without_properties_or_with_ro
|
29
|
+
ivars_with_properties.select { |x| x.ivar.options.include? :ro }
|
30
|
+
end
|
31
|
+
|
32
|
+
def frameworks
|
33
|
+
@cls.objc_frameworks
|
34
|
+
end
|
35
|
+
|
36
|
+
def imports
|
37
|
+
@cls.objc_imports
|
38
|
+
end
|
39
|
+
|
40
|
+
def class_name
|
41
|
+
@cls.objc_name
|
42
|
+
end
|
43
|
+
|
44
|
+
def superclass_name
|
45
|
+
@cls.objc_superclass_name
|
46
|
+
end
|
47
|
+
|
48
|
+
def needs_legacy
|
49
|
+
true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class ObjCIvarTemplate
|
54
|
+
def initialize ivar
|
55
|
+
@ivar = ivar
|
56
|
+
end
|
57
|
+
|
58
|
+
attr_reader :ivar
|
59
|
+
|
60
|
+
def ivar_type
|
61
|
+
t = ivar.objc_type
|
62
|
+
t = "NSString*" if t == :str
|
63
|
+
t = "NSInteger" if t == :int
|
64
|
+
t = "NSUInteger" if t == :uint
|
65
|
+
t = "BOOL" if t == :bool
|
66
|
+
t = "#{t}*" if t.kind_of? Symbol and t != :id and t != :Class
|
67
|
+
t
|
68
|
+
end
|
69
|
+
|
70
|
+
def is_object_type
|
71
|
+
t = ivar.objc_type
|
72
|
+
return true if ivar.options.include?(:object)
|
73
|
+
return false if (t == :int or t == :uint or t == :bool)
|
74
|
+
return true if t.kind_of?(Symbol)
|
75
|
+
|
76
|
+
(t =~ /^\s*id\s*(<|$)/) != nil
|
77
|
+
end
|
78
|
+
|
79
|
+
def ivar_name
|
80
|
+
"#{ivar.name}_"
|
81
|
+
end
|
82
|
+
|
83
|
+
def outlet_marker
|
84
|
+
'IBOutlet' if ivar.options.include? :outlet
|
85
|
+
end
|
86
|
+
|
87
|
+
def memory_management_marker
|
88
|
+
if is_object_type
|
89
|
+
if ivar.options.include? :retain
|
90
|
+
'retain'
|
91
|
+
elsif ivar.options.include? :copy
|
92
|
+
'copy'
|
93
|
+
elsif ivar.options.include? :assign
|
94
|
+
'assign'
|
95
|
+
elsif ivar.name.to_s == 'delegate' or ivar.name.to_s =~ /Delegate$/ and not ivar.options.include? :ro
|
96
|
+
'assign'
|
97
|
+
elsif not ivar.options.include? :ro
|
98
|
+
'retain'
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def property_modifiers
|
104
|
+
s = []
|
105
|
+
|
106
|
+
marker = memory_management_marker
|
107
|
+
s << marker if marker
|
108
|
+
|
109
|
+
s << 'nonatomic' unless ivar.options.include? :atomic
|
110
|
+
|
111
|
+
if ivar.options.include? :ro
|
112
|
+
s << 'readonly'
|
113
|
+
end
|
114
|
+
|
115
|
+
getter_name = ivar.options.select { |x| x.kind_of? ObjCIvarGetterNameOption }[0]
|
116
|
+
if getter_name
|
117
|
+
s << "getter = #{getter_name.name}"
|
118
|
+
end
|
119
|
+
|
120
|
+
return "(#{s.join ','})"
|
121
|
+
end
|
122
|
+
|
123
|
+
def property_name
|
124
|
+
ivar.name
|
125
|
+
end
|
126
|
+
|
127
|
+
def capitalized_property_name
|
128
|
+
p = property_name.to_s.dup
|
129
|
+
p[0,1] = p[0,1].upcase
|
130
|
+
p
|
131
|
+
end
|
132
|
+
|
133
|
+
def will_set
|
134
|
+
ivar.options.include? :will_set
|
135
|
+
end
|
136
|
+
|
137
|
+
def did_set
|
138
|
+
ivar.options.include? :did_set
|
139
|
+
end
|
140
|
+
|
141
|
+
def will_get
|
142
|
+
ivar.options.include? :will_get
|
143
|
+
end
|
144
|
+
|
145
|
+
def needs_explicit_setter
|
146
|
+
will_set || did_set
|
147
|
+
end
|
148
|
+
|
149
|
+
def needs_explicit_getter
|
150
|
+
will_get
|
151
|
+
end
|
152
|
+
|
153
|
+
def is_assign
|
154
|
+
marker = memory_management_marker
|
155
|
+
marker != 'retain' and marker != 'copy'
|
156
|
+
end
|
157
|
+
|
158
|
+
def memory_management_call
|
159
|
+
memory_management_marker
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
# -------------
|
165
|
+
|
166
|
+
load ARGV[0]
|
167
|
+
|
168
|
+
OBJC_CLASSES.each do |name, cls|
|
169
|
+
File.open("#{name}.h", 'w') do |io|
|
170
|
+
t = ObjCClassTemplate.new(cls, File.expand_path(ARGV[0]))
|
171
|
+
t.template_file = File.join(File.dirname(__FILE__), 'objc_header.mustache')
|
172
|
+
|
173
|
+
io << t.render
|
174
|
+
end
|
175
|
+
|
176
|
+
File.open("#{name}.m", 'w') do |io|
|
177
|
+
t = ObjCClassTemplate.new(cls, File.expand_path(ARGV[0]))
|
178
|
+
t.template_file = File.join(File.dirname(__FILE__), 'objc_implementation.mustache')
|
179
|
+
|
180
|
+
io << t.render
|
181
|
+
end
|
182
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
// ----------------------------
|
3
|
+
// AUTOGENERATED FROM:
|
4
|
+
// {{{shorthand_file}}}
|
5
|
+
// ----------------------------
|
6
|
+
|
7
|
+
{{#frameworks}}
|
8
|
+
#import <{{{.}}}/{{{.}}}.h>
|
9
|
+
{{/frameworks}}
|
10
|
+
{{^frameworks}}
|
11
|
+
#import <Foundation/Foundation.h>
|
12
|
+
{{/frameworks}}
|
13
|
+
|
14
|
+
{{#imports}}
|
15
|
+
#import "{{{.}}}"
|
16
|
+
{{/imports}}
|
17
|
+
|
18
|
+
@interface {{{class_name}}} : {{{superclass_name}}}
|
19
|
+
{{#needs_legacy}}
|
20
|
+
{
|
21
|
+
@protected
|
22
|
+
{{#ivars}}
|
23
|
+
{{{ivar_type}}} {{{ivar_name}}};
|
24
|
+
{{/ivars}}
|
25
|
+
}
|
26
|
+
{{/needs_legacy}}
|
27
|
+
|
28
|
+
{{#ivars_with_properties}}
|
29
|
+
@property{{{property_modifiers}}} {{{outlet_marker}}} {{{ivar_type}}} {{{property_name}}};
|
30
|
+
{{#will_get}}
|
31
|
+
- (void) willReturnValueFor{{{capitalized_property_name}}};
|
32
|
+
{{/will_get}}
|
33
|
+
{{#will_set}}
|
34
|
+
- ({{{ivar_type}}}) {{{property_name}}}WillChangeToValue:({{{ivar_type}}}) aNewValue fromValue:({{{ivar_type}}}) anOldValue;
|
35
|
+
{{/will_set}}
|
36
|
+
{{#did_set}}
|
37
|
+
- (void) {{{property_name}}}DidChangeToValue:({{{ivar_type}}}) aNewValue fromValue:({{{ivar_type}}}) anOldValue;
|
38
|
+
{{/did_set}}
|
39
|
+
{{/ivars_with_properties}}
|
40
|
+
|
41
|
+
@end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
|
2
|
+
// ----------------------------
|
3
|
+
// AUTOGENERATED FROM:
|
4
|
+
// {{{shorthand_file}}}
|
5
|
+
// ----------------------------
|
6
|
+
|
7
|
+
#import "{{{class_name}}}.h"
|
8
|
+
|
9
|
+
@implementation {{{class_name}}}
|
10
|
+
|
11
|
+
{{#ivars_with_properties}}
|
12
|
+
@synthesize {{{property_name}}} = {{{ivar_name}}};
|
13
|
+
{{/ivars_with_properties}}
|
14
|
+
|
15
|
+
- (void) dealloc;
|
16
|
+
{
|
17
|
+
{{#ivars_with_properties_without_ro}}
|
18
|
+
{{^is_assign}}
|
19
|
+
self.{{{property_name}}} = nil;
|
20
|
+
{{/is_assign}}
|
21
|
+
{{/ivars_with_properties_without_ro}}
|
22
|
+
|
23
|
+
{{#ivars_without_properties_or_with_ro}}
|
24
|
+
{{^is_assign}}
|
25
|
+
[{{{ivar_name}}} release];
|
26
|
+
{{/is_assign}}
|
27
|
+
{{#is_assign}}
|
28
|
+
// {{{ivar_name}}} is assigned
|
29
|
+
{{/is_assign}}
|
30
|
+
{{/ivars_without_properties_or_with_ro}}
|
31
|
+
|
32
|
+
[super dealloc];
|
33
|
+
}
|
34
|
+
|
35
|
+
{{#ivars_with_properties}}
|
36
|
+
{{#needs_explicit_getter}}
|
37
|
+
- ({{{ivar_type}}}) {{{property_name}}};
|
38
|
+
{
|
39
|
+
{{#will_get}}
|
40
|
+
[self willReturnValueFor{{{capitalized_property_name}}}];
|
41
|
+
{{/will_get}}
|
42
|
+
|
43
|
+
return {{{ivar_name}}};
|
44
|
+
}
|
45
|
+
{{#will_get}}
|
46
|
+
- (void) willReturnValueFor{{{capitalized_property_name}}};
|
47
|
+
{}
|
48
|
+
{{/will_get}}
|
49
|
+
|
50
|
+
{{/needs_explicit_getter}}
|
51
|
+
|
52
|
+
{{#needs_explicit_setter}}
|
53
|
+
- (void) set{{{capitalized_property_name}}}:({{{ivar_type}}}) aNewValue;
|
54
|
+
{
|
55
|
+
if (aNewValue != {{{ivar_name}}}) {
|
56
|
+
|
57
|
+
{{#will_set}}
|
58
|
+
aNewValue = [self {{{property_name}}}WillChangeToValue:aNewValue fromValue:{{{ivar_name}}}];
|
59
|
+
if (aNewValue == {{{ivar_name}}})
|
60
|
+
return;
|
61
|
+
{{/will_set}}
|
62
|
+
{{#did_set}}
|
63
|
+
{{{ivar_type}}} anOldValue = {{{ivar_name}}};
|
64
|
+
{{/did_set}}
|
65
|
+
{{^is_assign}}
|
66
|
+
{{#did_set}}
|
67
|
+
[[anOldValue retain] autorelease];
|
68
|
+
{{/did_set}}
|
69
|
+
{{/is_assign}}
|
70
|
+
|
71
|
+
{{#is_assign}}
|
72
|
+
{{{ivar_name}}} = aNewValue;
|
73
|
+
{{/is_assign}}
|
74
|
+
{{^is_assign}}
|
75
|
+
[{{{ivar_name}}} release];
|
76
|
+
{{{ivar_name}}} = [aNewValue {{{memory_management_call}}}];
|
77
|
+
{{/is_assign}}
|
78
|
+
|
79
|
+
{{#did_set}}
|
80
|
+
[self {{{property_name}}}DidChangeToValue:aNewValue fromValue:anOldValue];
|
81
|
+
{{/did_set}}
|
82
|
+
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
{{#will_set}}
|
87
|
+
- ({{{ivar_type}}}) {{{property_name}}}WillChangeToValue:({{{ivar_type}}}) aNewValue fromValue:({{{ivar_type}}}) anOldValue;
|
88
|
+
{
|
89
|
+
return aNewValue;
|
90
|
+
}
|
91
|
+
{{/will_set}}
|
92
|
+
{{#did_set}}
|
93
|
+
- (void) {{{property_name}}}DidChangeToValue:({{{ivar_type}}}) aNewValue fromValue:({{{ivar_type}}}) anOldValue;
|
94
|
+
{}
|
95
|
+
{{/did_set}}
|
96
|
+
{{/needs_explicit_setter}}
|
97
|
+
{{/ivars_with_properties}}
|
98
|
+
|
99
|
+
@end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
class ObjCClass
|
4
|
+
def initialize name
|
5
|
+
@objc_name = name
|
6
|
+
@objc_superclass_name = :NSObject
|
7
|
+
@objc_ivars = {}
|
8
|
+
@objc_frameworks = []
|
9
|
+
@objc_imports = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def subclass_of x
|
13
|
+
@objc_superclass_name = x
|
14
|
+
end
|
15
|
+
|
16
|
+
def ivar name, type = nil, *options
|
17
|
+
@objc_ivars[name] = ObjCIvar.new name, type || :id, options
|
18
|
+
end
|
19
|
+
|
20
|
+
def framework x
|
21
|
+
@objc_frameworks << x unless @objc_frameworks.include? x
|
22
|
+
end
|
23
|
+
|
24
|
+
def import x
|
25
|
+
@objc_imports << x unless @objc_imports.include? x
|
26
|
+
end
|
27
|
+
|
28
|
+
def method_missing name, type = nil, *options
|
29
|
+
ivar name, type, *options
|
30
|
+
end
|
31
|
+
|
32
|
+
def getter(name)
|
33
|
+
return ObjCIvarGetterNameOption.new(name)
|
34
|
+
end
|
35
|
+
|
36
|
+
attr_reader :objc_name, :objc_ivars, :objc_frameworks, :objc_imports, :objc_superclass_name
|
37
|
+
end
|
38
|
+
|
39
|
+
class ObjCIvarGetterNameOption
|
40
|
+
def initialize name
|
41
|
+
@name = name
|
42
|
+
end
|
43
|
+
|
44
|
+
attr_reader :name
|
45
|
+
end
|
46
|
+
|
47
|
+
class ObjCIvar
|
48
|
+
def initialize name, type, options
|
49
|
+
@name = name
|
50
|
+
@objc_type = type
|
51
|
+
@options = options
|
52
|
+
end
|
53
|
+
|
54
|
+
attr_reader :name, :objc_type, :options
|
55
|
+
end
|
56
|
+
|
57
|
+
OBJC_CLASSES = {} unless
|
58
|
+
|
59
|
+
def objc_class name, &block
|
60
|
+
x = ObjCClass.new(name)
|
61
|
+
OBJC_CLASSES[name] = x
|
62
|
+
x.instance_eval(&block)
|
63
|
+
x
|
64
|
+
end
|
data/lib/mt_tool/version.rb
CHANGED
data/mt_tool.gemspec
CHANGED
@@ -42,8 +42,10 @@ Gem::Specification.new do |spec|
|
|
42
42
|
spec.add_dependency 'thor'
|
43
43
|
spec.add_dependency 'xcodeproj'
|
44
44
|
spec.add_dependency 'colored'
|
45
|
+
spec.add_dependency 'colored2'
|
45
46
|
spec.add_dependency 'pathname'
|
46
|
-
|
47
|
+
spec.add_dependency 'mustache'
|
48
|
+
spec.add_dependency 'activesupport'
|
47
49
|
# For more information and examples about making a new gem, check out our
|
48
50
|
# guide at: https://bundler.io/guides/creating_gem.html
|
49
51
|
end
|