Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb3de4f7

Browse files
author
Jim Puls
committed
Add options instead of hardcoding them
1 parent5fbcb06 commitb3de4f7

File tree

3 files changed

+79
-17
lines changed

3 files changed

+79
-17
lines changed

‎README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ For an asset catalog named "Foo" containing image sets "Bar" and "Baz", you'll g
1414

1515
##Command-line options
1616

17-
There are none. The class prefix is hardcoded as`WQ` and the output directory is hardcoded as the current one. We should fix this.
18-
19-
##Future plans
20-
21-
Maybe swizzle`+[UIImage imageNamed:]`?
17+
Usage:
18+
*`objc-assetgen [-o <path>] [-f <path>] [-p <prefix>] [<paths>]`
19+
*`objc-assetgen -h`
20+
21+
Options:
22+
<dl>
23+
<dt><code>-o&lt;path></code></dt><dd>Output files at <code>&lt;path></code></dd>
24+
<dt><code>-f&lt;path></code></dt><dd>Search for *.xcassets folders starting from <code>&lt;path></code></dd>
25+
<dt><code>-p&lt;prefix></code></dt><dd>Use <code>&lt;prefix></code> as the class prefix in the generated code</dd>
26+
<dt><code>-h</code></dt><dd>Print this help and exit</dd>
27+
<dt><code>&lt;paths></code></dt><dd>Input files; this and/or -f are required.</dd>
28+
</dl>

‎assetgen/AGCatalogParser.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,13 @@ - (void)outputCode;
218218
return [obj1compare:obj2];
219219
}];
220220

221-
NSString *interface = [NSStringstringWithFormat:@"//\n// This file is generated by objc-assetgen. Please do not edit.\n//\n\n#import <UIKit/UIKit.h>\n\n@interface%@ : NSObject\n\n%@\n@end\n", className, [self.interfaceContentscomponentsJoinedByString:@""]];
221+
NSString *interface = [NSStringstringWithFormat:@"//\n// This file is generatedfrom%@.xcassetsby objc-assetgen.\n// Please do not edit.\n//\n\n#import <UIKit/UIKit.h>\n\n@interface%@ : NSObject\n\n%@\n@end\n",self.catalogName, className, [self.interfaceContentscomponentsJoinedByString:@""]];
222222

223223
if (![interfaceisEqualToString:[NSStringstringWithContentsOfURL:interfaceURLencoding:NSUTF8StringEncodingerror:NULL]]) {
224224
[interfacewriteToURL:interfaceURLatomically:YESencoding:NSUTF8StringEncodingerror:NULL];
225225
}
226226

227-
NSString *implementation = [NSStringstringWithFormat:@"//\n// This file is generated by objc-assetgen. Please do not edit.\n//\n\n#import\"%@\"\n\n@implementation%@\n\n%@\n%@\n\n@end\n", classNameH, className,self.cacheMethodContents, [self.implementationContentscomponentsJoinedByString:@"\n"]];
227+
NSString *implementation = [NSStringstringWithFormat:@"//\n// This file is generatedfrom%@.xcassetsby objc-assetgen.\n// Please do not edit.\n//\n\n#import\"%@\"\n\n@implementation%@\n\n%@\n%@\n\n@end\n",self.catalogName, classNameH, className,self.cacheMethodContents, [self.implementationContentscomponentsJoinedByString:@"\n"]];
228228

229229
if (![implementationisEqualToString:[NSStringstringWithContentsOfURL:implementationURLencoding:NSUTF8StringEncodingerror:NULL]]) {
230230
[implementationwriteToURL:implementationURLatomically:YESencoding:NSUTF8StringEncodingerror:NULL];

‎assetgen/main.m

Lines changed: 65 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,82 @@
77
//
88

99
#import<Foundation/Foundation.h>
10+
#import<libgen.h>
11+
1012
#import"AGCatalogParser.h"
1113

1214
intmain(int argc,constchar * argv[])
1315
{
1416
@autoreleasepool {
15-
dispatch_group_t group =dispatch_group_create();
16-
17-
NSInteger index =0;
18-
for (NSString *argument in [[NSProcessInfoprocessInfo]arguments]) {
19-
if (index++ ==0) {
20-
continue;
17+
char opt = -1;
18+
NSURL *searchURL =nil;
19+
NSString *classPrefix =@"";
20+
NSMutableArray *inputURLs = [NSMutableArrayarray];
21+
22+
while ((opt =getopt(argc, (char *const*)argv,"o:f:p:h")) != -1) {
23+
switch (opt) {
24+
case'h': {
25+
printf("Usage:%s [-o <path>] [-f <path>] [-p <prefix>] [<paths>]\n",basename((char *)argv[0]));
26+
printf("%s -h\n\n",basename((char *)argv[0]));
27+
printf("Options:\n");
28+
printf(" -o <path> Output files at <path>\n");
29+
printf(" -f <path> Search for *.xcassets folders starting from <path>\n");
30+
printf(" -p <prefix> Use <prefix> as the class prefix in the generated code\n");
31+
printf(" -h Print this help and exit\n");
32+
printf(" <paths> Input files; this and/or -f are required.\n");
33+
return0;
34+
}
35+
36+
case'o': {
37+
NSString *outputPath = [[NSStringalloc]initWithUTF8String:optarg];
38+
outputPath = [outputPathstringByExpandingTildeInPath];
39+
[[NSFileManagerdefaultManager]changeCurrentDirectoryPath:outputPath];
40+
break;
41+
}
42+
43+
case'f': {
44+
NSString *searchPath = [[NSStringalloc]initWithUTF8String:optarg];
45+
searchPath = [searchPathstringByExpandingTildeInPath];
46+
searchURL = [NSURLfileURLWithPath:searchPath];
47+
break;
48+
}
49+
50+
case'p': {
51+
classPrefix = [[NSStringalloc]initWithUTF8String:optarg];
52+
break;
53+
}
54+
55+
default:
56+
break;
2157
}
22-
58+
}
59+
60+
for (int index = optind; index < argc; index++) {
61+
NSString *inputPath = [[NSStringalloc]initWithUTF8String:argv[index]];
62+
inputPath = [inputPathstringByExpandingTildeInPath];
63+
[inputURLsaddObject:[NSURLfileURLWithPath:inputPath]];
64+
}
65+
66+
if (searchURL) {
67+
NSDirectoryEnumerator *enumerator = [[NSFileManagerdefaultManager]enumeratorAtURL:searchURLincludingPropertiesForKeys:@[NSURLNameKey]options:0errorHandler:NULL];
68+
for (NSURL *url in enumerator) {
69+
if ([url.pathExtensionisEqualToString:@"xcassets"]) {
70+
[inputURLsaddObject:url];
71+
}
72+
}
73+
}
74+
75+
dispatch_group_t group =dispatch_group_create();
76+
77+
for (NSURL *url in inputURLs) {
2378
dispatch_group_enter(group);
24-
AGCatalogParser *parser = [AGCatalogParserassetCatalogAtURL:[NSURLfileURLWithPath:argument]];
25-
parser.classPrefix =@"WQ";
79+
AGCatalogParser *parser = [AGCatalogParserassetCatalogAtURL:url];
80+
parser.classPrefix =classPrefix;
2681
[parserstartWithCompletionHandler:^{
2782
dispatch_group_leave(group);
2883
}];
2984
}
30-
85+
3186
dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
3287
}
3388
return0;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp