-
Notifications
You must be signed in to change notification settings - Fork 0
/
templates.py
73 lines (54 loc) · 1.57 KB
/
templates.py
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
69
70
71
72
HEADER_TEMPLATE = '''
@interface {name}: {parent_name}
{{
@private
{fields}
}}
{property_decls}
{method_decls}
@end
'''
FIELD_DECL_TEMPLATE = " {objc_type} {name}_;"
PROPERTY_DECL_TEMPLATE = "@property({mem_policy}) {objc_type} {name};"
PROPERTY_SYNTH_TEMPLATE = "@synthesize {name} = {name}_;"
IMPLEMENTATION_TEMPLATE = '''
#import "{name}.h"
@implementation {name}
{property_synthesis}
{methods}
@end
'''
SETTER_DECLARATION = '- (void)setContent:(NSDictionary*)content;'
SETTER_BODY_TEMPLATE = '''- (void)setContent:(NSDictionary*)content
{{
{parse_lines}
}}
'''
FIELD_PARSE_LINE_TEMPLATE = '''
self.{name} = [content objectForKey:@"{name}"];
self.{name} = [[NSNull null] isEqual:self.{name}]?nil:self.{name};'''
INT_FIELD_PARSE_LINE_TEMPLATE = '''
id boxed_{name} = [content objectForKey:@"{name}"];
if (boxed_{name} && ![[NSNull null] isEqual:boxed_{name}])
self.{name} = [boxed_{name} intValue];
else
self.{name} = 0;'''
DOUBLE_FIELD_PARSE_LINE_TEMPLATE = '''
id boxed_{name} = [content objectForKey:@"{name}"];
if (boxed_{name} && ![[NSNull null] isEqual:boxed_{name}])
self.{name} = [boxed_{name} doubleValue];
else
self.{name} = 0.f;'''
BOOL_FIELD_PARSE_LINE_TEMPLATE = '''
id boxed_{name} = [content objectForKey:@"{name}"];
if (boxed_{name} && ![[NSNull null] isEqual:boxed_{name}])
self.{name} = [boxed_{name} boolValue];
else
self.{name} = NO;'''
DEALLOC_BODY_TEMPLATE = '''- (void)dealloc
{{
{release_lines}
[super dealloc];
}}
'''
RELEASE_FIELD_LINE = ' [{name}_ release];'