-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathIDXIBDumper.m
More file actions
54 lines (41 loc) · 2.16 KB
/
IDXIBDumper.m
File metadata and controls
54 lines (41 loc) · 2.16 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
//
// IDXIBDumper.m
// codegenutils
//
// Created by Tony Arnold on 27/04/2014.
// Licensed to Square, Inc. under one or more contributor license agreements.
// See the LICENSE file distributed with this work for the terms under
// which Square, Inc. licenses this file to you.
#import "IDXIBDumper.h"
#import "NSString+ISDAdditions.h"
@implementation IDXIBDumper
+ (NSString *)inputFileExtension;
{
return @"xib";
}
- (void)startWithCompletionHandler:(dispatch_block_t)completionBlock;
{
self.skipClassDeclaration = YES;
NSString *storyboardFilename = [[self.inputURL lastPathComponent] stringByDeletingPathExtension];
NSString *storyboardName = [storyboardFilename stringByReplacingOccurrencesOfString:@" " withString:@""];
self.className = [NSString stringWithFormat:@"%@%@XIBIdentifiers", self.classPrefix, storyboardName];
NSError *error = nil;
NSXMLDocument *document = [[NSXMLDocument alloc] initWithContentsOfURL:self.inputURL options:0 error:&error];
NSArray *objectIdentifiers = [[document nodesForXPath:@"/document/objects//@identifier" error:&error] valueForKey:NSStringFromSelector(@selector(stringValue))];
NSMutableArray *identifiers = [NSMutableArray arrayWithArray:objectIdentifiers];
self.interfaceContents = [NSMutableArray array];
self.implementationContents = [NSMutableArray array];
NSMutableDictionary *uniqueKeys = [NSMutableDictionary dictionary];
uniqueKeys[[NSString stringWithFormat:@"%@%@XIBName", self.classPrefix, storyboardName]] = storyboardFilename;
for (NSString *identifier in identifiers) {
NSString *key = [NSString stringWithFormat:@"%@%@XIB%@Identifier", self.classPrefix, storyboardName, [identifier IDS_titlecaseString]];
uniqueKeys[key] = identifier;
}
for (NSString *key in [uniqueKeys keysSortedByValueUsingSelector:@selector(caseInsensitiveCompare:)]) {
[self.interfaceContents addObject:[NSString stringWithFormat:@"extern NSString *const %@;\n", key]];
[self.implementationContents addObject:[NSString stringWithFormat:@"NSString *const %@ = @\"%@\";\n", key, uniqueKeys[key]]];
}
[self writeOutputFiles];
completionBlock();
}
@end