Skip to content

Commit

Permalink
added support for relative template dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
tonklon committed Feb 13, 2011
1 parent 462a485 commit fff9f12
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions mogenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
@end

@interface MOGeneratorApp : NSObject <DDCliApplicationDelegate> {
NSString *origModelBasePath;
NSString *tempMOMPath;
NSManagedObjectModel *model;
NSString *baseClass;
Expand Down
26 changes: 25 additions & 1 deletion mogenerator.m
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ - (void) printUsage;
" -m, --model MODEL Path to model\n"
" --base-class CLASS Custom base class\n"
" --includem FILE Generate aggregate include file\n"
" --template-path PATH Path to templates\n"
" --template-path PATH Path to templates (absolute or relative to model path)\n"
" --template-group NAME Name of template group\n"
" -O, --output-dir DIR Output directory\n"
" -M, --machine-dir DIR Output directory for machine files\n"
Expand Down Expand Up @@ -396,6 +396,8 @@ - (void)setModel:(NSString*)path;
{
assert(!model); // Currently we only can load one model.

origModelBasePath = [path stringByDeletingLastPathComponent];

if( ![[NSFileManager defaultManager] fileExistsAtPath:path]){
NSString * reason = [NSString stringWithFormat: @"error loading file at %@: no such file exists", path];
DDCliParseException * e = [DDCliParseException parseExceptionWithReason: reason
Expand Down Expand Up @@ -485,6 +487,28 @@ - (int) application: (DDCliApplication *) app

return EXIT_SUCCESS;
}

if (templatePath) {

NSString* absoluteTemplatePath = nil;

if (![templatePath isAbsolutePath]) {
absoluteTemplatePath = [[origModelBasePath stringByAppendingPathComponent:templatePath] stringByStandardizingPath];

// Be kind and try a relative Path of the parent xcdatamodeld folder of the model, if it exists
if ((![fm fileExistsAtPath:absoluteTemplatePath]) && ([[origModelBasePath pathExtension] isEqualToString:@"xcdatamodeld"])) {
absoluteTemplatePath = [[[origModelBasePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:templatePath] stringByStandardizingPath];
}
} else {
absoluteTemplatePath = templatePath;
}


// the the computed absoluteTemplatePath exists, use it.
if ([fm fileExistsAtPath:absoluteTemplatePath]) {
templatePath = absoluteTemplatePath;
}
}

int machineFilesGenerated = 0;
int humanFilesGenerated = 0;
Expand Down

0 comments on commit fff9f12

Please sign in to comment.