Permalink
Browse files

added support for relative template dirs

  • Loading branch information...
1 parent 462a485 commit fff9f12a15186877e780cb01cc8a925cc59768cf @tonklon tonklon committed Feb 13, 2011
Showing with 26 additions and 1 deletion.
  1. +1 −0 mogenerator.h
  2. +25 −1 mogenerator.m
View
@@ -41,6 +41,7 @@
@end
@interface MOGeneratorApp : NSObject <DDCliApplicationDelegate> {
+ NSString *origModelBasePath;
NSString *tempMOMPath;
NSManagedObjectModel *model;
NSString *baseClass;
View
@@ -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"
@@ -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
@@ -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;

0 comments on commit fff9f12

Please sign in to comment.