Skip to content

Commit

Permalink
Links
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Gordon committed Mar 12, 2010
1 parent 5862b97 commit 148d59f
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 75 deletions.
44 changes: 5 additions & 39 deletions IGKDocRecordManagedObject.m
Expand Up @@ -24,11 +24,8 @@ @implementation IGKDocRecordManagedObject

+ (IGKDocRecordManagedObject *)resolveURL:(NSURL *)url inContext:(NSManagedObjectContext *)ctx tableOfContentsMask:(IGKHTMLDisplayTypeMask *)tocMaskPointer
{
NSLog(@"Resolve URL = %@, %@", url, ctx);
NSArray *components = [url pathComponents];

NSLog(@"components = %@", components);


/*
ingr-doc:// <docset-family> / <docset-version> / <table-of-contents> / <item-name> . <item-type>
ingr-doc:// <docset-family> / <docset-version> / <table-of-contents> / <container-name> . <container-type> / <item-name> . <item-type>
Expand All @@ -41,13 +38,9 @@ + (IGKDocRecordManagedObject *)resolveURL:(NSURL *)url inContext:(NSManagedObjec
//Remove an initial "/" component
if ([[components objectAtIndex:0] isEqual:@"/"])
components = [components subarrayWithRange:NSMakeRange(1, [components count] - 1)];

NSLog(@"components2 = %@", components);

components = [[NSArray arrayWithObject:[url host]] arrayByAddingObjectsFromArray:components];

NSLog(@"components3 = %@", components);

// <docset-family>
NSString *docsetFamily = [components objectAtIndex:0];
if ([docsetFamily isEqual:@"mac"])
Expand All @@ -61,22 +54,17 @@ + (IGKDocRecordManagedObject *)resolveURL:(NSURL *)url inContext:(NSManagedObjec
NSFetchRequest *docsetFetch = [[NSFetchRequest alloc] init];
[docsetFetch setEntity:[NSEntityDescription entityForName:@"Docset" inManagedObjectContext:ctx]];
[docsetFetch setPredicate:[NSPredicate predicateWithFormat:@"platformFamily == %@ && platformVersion == %@", docsetFamily, docsetVersion]];

NSLog(@"docsetFamily = '%@', docsetVersion = '%@'", docsetFamily, docsetVersion);


NSError *err = nil;
NSArray *docsets = [ctx executeFetchRequest:docsetFetch error:&err];

NSLog(@"Err = %@, docsets = %@", err, docsets);


if (err || ![docsets count])
return nil;

IGKDocSetManagedObject *docset = [docsets objectAtIndex:0];


// <table-of-contents>
NSLog(@"tocMaskPointer = %d", tocMaskPointer);
if (tocMaskPointer)
{
NSString *tableOfContents = [components objectAtIndex:2];
Expand Down Expand Up @@ -105,9 +93,6 @@ + (IGKDocRecordManagedObject *)resolveURL:(NSURL *)url inContext:(NSManagedObjec
tocMask |= IGKHTMLDisplayType_BindingListings;
}

NSLog(@"tocMask = %d", tocMask);
NSLog(@"tableOfContentsItems = %@", tableOfContentsItems);

*tocMaskPointer = tocMask;
}

Expand Down Expand Up @@ -142,24 +127,19 @@ + (IGKDocRecordManagedObject *)resolveURL:(NSURL *)url inContext:(NSManagedObjec
}


NSLog(@"a");
// <item-name> . <item-type>
NSString *itemComponent = [components lastObject];

NSString *itemName = [itemComponent stringByDeletingPathExtension];
NSString *itemExtension = [itemComponent pathExtension];
if (![itemName length] || ![itemExtension length])
return nil;

NSLog(@"b");



NSString *itemEntity = [self entityNameFromURLComponentExtension:itemExtension];
if (![itemEntity length])
return nil;

NSLog(@"c");



NSFetchRequest *itemFetchRequest = [[NSFetchRequest alloc] init];
[itemFetchRequest setEntity:[NSEntityDescription entityForName:itemEntity inManagedObjectContext:ctx]];
Expand All @@ -169,21 +149,7 @@ + (IGKDocRecordManagedObject *)resolveURL:(NSURL *)url inContext:(NSManagedObjec
else
[itemFetchRequest setPredicate:[NSPredicate predicateWithFormat:@"name == %@ && docset == %@", itemName, docset]];

NSLog(@"itemEntity = %@", itemEntity);
NSLog(@"itemName = %@", itemName);
NSLog(@"container = %@", container);
NSLog(@"docset = %@", docset);

NSLog(@"itemFetchRequest = %@", itemFetchRequest);

NSLog(@"\n\n START FETCH");
NSArray *items = [ctx executeFetchRequest:itemFetchRequest error:&err];
NSLog(@"\n\n STOP FETCH");

NSLog(@"d = %d, %d", err, [items count]);


NSLog(@"e = %d", [items objectAtIndex:0]);

if (err || ![items count])
return nil;
Expand Down
4 changes: 4 additions & 0 deletions IGKDocSetManagedObject.m
Expand Up @@ -10,6 +10,10 @@

@implementation IGKDocSetManagedObject

- (NSString *)docsetURLHost
{
return [NSString stringWithFormat:@"%@.%@", [self shortPlatformName], [self shortVersionName]];
}
- (NSString *)shortPlatformName
{
NSString *platformFamily = [self valueForKey:@"platformFamily"];
Expand Down
103 changes: 85 additions & 18 deletions IGKHTMLGenerator.m
Expand Up @@ -158,11 +158,11 @@ - (NSString *)html
}
else if ([[transientObject entity] isKindOfEntity:ObjCMethod])
{
[outputString appendString:@"<div class='methods' class='single'>"];
[outputString appendString:@"<div class='methods' class='single'>\n"];

[self html_method:transientObject hasParameters:YES];

[outputString appendString:@"</div>"];
[outputString appendString:@"</div>\n"];
}
else
{
Expand All @@ -184,7 +184,8 @@ - (void)html_all
}
- (void)html_overview
{
[outputString appendString:@"<div class='methods overview'>"];
[outputString appendString:@"<a name='overview'></a>\n"];
[outputString appendString:@"<div class='methods overview'>\n"];

[outputString appendFormat:@"<h1>%@</h1>", [self escape:[transientObject valueForKey:@"name"]]];

Expand All @@ -193,47 +194,106 @@ - (void)html_overview

[self html_metadataTable:transientObject];

[outputString appendString:@"</div>"];
[outputString appendString:@"</div>\n"];

[self html_tasks];
}
- (void)html_tasks
{
[outputString appendString:@"<div class='methods tasks'>"];
[outputString appendString:@"<a name='tasks'></a>\n"];
[outputString appendString:@"<div class='methods tasks'>\n"];

NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:@"positionIndex" ascending:YES];
NSArray *taskgroups = [[[transientObject valueForKey:@"taskgroups"] allObjects] sortedArrayUsingDescriptors:[NSArray arrayWithObject:descriptor]];
for (NSManagedObject *taskgroup in taskgroups)
{
[outputString appendFormat:@"<h2>%@</h2>", [taskgroup valueForKey:@"name"]];
[outputString appendString:@"<ul>"];
[outputString appendFormat:@"<h2>%@</h2>\n", [taskgroup valueForKey:@"name"]];
[outputString appendString:@"<ul>\n"];

NSArray *taskgroupItems = [[[taskgroup valueForKey:@"items"] allObjects] sortedArrayUsingDescriptors:[NSArray arrayWithObject:descriptor]];
for (NSManagedObject *taskgroupItem in taskgroupItems)
{
[outputString appendFormat:@"<li><code><a href='%@' class='stealth'>%@</a></code></li>", [taskgroupItem valueForKey:@"href"], [taskgroupItem valueForKey:@"name"]];
NSString *hrefAndNameAndType = [self hrefToActualFragment:taskgroupItem];

[outputString appendFormat:@"<li><code><a href='%@' class='stealth'>%@</a></code></li>\n", hrefAndNameAndType, [taskgroupItem valueForKey:@"name"]];
}

[outputString appendString:@"</ul>"];
[outputString appendString:@"</ul>\n"];
}

[outputString appendString:@"</div>"];
[outputString appendString:@"</div>\n"];
}
- (NSArray *)hrefToActualFragment:(IGKDocRecordManagedObject *)mo
{
NSString *href = [mo valueForKey:@"href"];

// NSString.html#//apple_ref/occ/instm/NSString/stringByAppendingPathComponent:
// We need to grab
// the type (cl, instm, etc)
// the container (NSString)
// the item (stringByAppendingPathComponent:)

NSString *regex = @"//apple_ref/(occ|c)/([^/]+)/([^/]+)(/([^/]+))?";
NSArray *captures = [href captureComponentsMatchedByRegex:regex];
if ([captures count] < 4)
return nil;

NSString *applecode = [captures objectAtIndex:2];
NSString *n = [captures objectAtIndex:3];

NSString *containerName = nil;
NSString *itemName = nil;


if ([captures count] >= 6)
{
containerName = n;
itemName = [captures objectAtIndex:5];
}
else
{
itemName = n;
}

NSString *ingrcode = nil;
if ([applecode isEqual:@"instm"] || [applecode isEqual:@"intfm"])
ingrcode = @"instance-method";
else if ([applecode isEqual:@"clm"] || [applecode isEqual:@"intfcm"])
ingrcode = @"class-method";
else if ([applecode isEqual:@"intfp"] || [applecode isEqual:@"instp"])
ingrcode = @"property";
else if ([applecode isEqual:@"func"])
ingrcode = @"function";
else if ([applecode isEqual:@"tdef"])
ingrcode = @"type";

if ([containerName isEqual:[transientObject valueForKey:@"name"]])
{
return [NSString stringWithFormat:@"#%@.%@", itemName, ingrcode];
}

if (containerName)
return [NSString stringWithFormat:@"ingr-doc://%@/all/%@.unknown/%@.%@", [[transientObject valueForKey:@"Docset"] docsetURLHost], containerName, itemName, ingrcode];

return [NSString stringWithFormat:@"ingr-doc://%@/all/%@.%@", [[transientObject valueForKey:@"Docset"] docsetURLHost], itemName, ingrcode];
}
- (void)html_properties
{
[outputString appendString:@"<div class='methods' class='properties'>"];
[outputString appendString:@"<a name='properties'></a>\n"];
[outputString appendString:@"<div class='methods' class='properties'>\n"];

[self html_methodLikeDeclarationsWithEntity:@"ObjCProperty" hasParameters:NO];

[outputString appendString:@"</div>"];
}
- (void)html_methods
{
[outputString appendString:@"<div class='methods'>"];
[outputString appendString:@"<a name='methods'></a>\n"];
[outputString appendString:@"<div class='methods'>\n"];

[self html_methodLikeDeclarationsWithEntity:@"ObjCMethod" hasParameters:YES];

[outputString appendString:@"</div>"];
[outputString appendString:@"</div>\n"];
}
- (void)html_methodLikeDeclarationsWithEntity:(NSString *)entityName hasParameters:(BOOL)hasParameters
{
Expand All @@ -252,11 +312,12 @@ - (void)html_methodLikeDeclarationsWithEntity:(NSString *)entityName hasParamete

- (void)html_notifications
{
[outputString appendString:@"<div class='methods' class='notifications'>"];
[outputString appendString:@"<a name='notifications'></a>\n"];
[outputString appendString:@"<div class='methods' class='notifications'>\n"];

[self html_methodLikeDeclarationsWithEntity:@"ObjCNotification" hasParameters:NO];

[outputString appendString:@"</div>"];
[outputString appendString:@"</div>\n"];
}
- (void)html_delegate
{
Expand All @@ -265,6 +326,7 @@ - (void)html_delegate

- (void)html_method:(IGKDocRecordManagedObject *)object hasParameters:(BOOL)hasParameters
{
[outputString appendFormat:@"<a name='%@.%@'></a>\n", [object valueForKey:@"name"], [object URLComponentExtension]];
[outputString appendFormat:@"\t<div class='method'>\n"];

if ([object valueForKey:@"name"])
Expand All @@ -285,7 +347,7 @@ - (void)html_method:(IGKDocRecordManagedObject *)object hasParameters:(BOOL)hasP
[outputString appendFormat:@"\t\t<hr>\n\n\t\t<div class='discussion'>%@</div>\n\n\t\t<hr>\n\n", [object valueForKey:@"discussion"]];

[self html_metadataTable:object];

[outputString appendFormat:@"\t</div>\n\n"];
}
- (void)html_parametersForCallable:(IGKDocRecordManagedObject *)object
Expand Down Expand Up @@ -377,7 +439,8 @@ - (void)html_metadataTable:(IGKDocRecordManagedObject *)object

NSUInteger i = 0;

NSArray *seealsos = [[[[object valueForKey:@"seealsos"] allObjects] valueForKey:@"name"] sortedArrayUsingSelector:@selector(localizedCompare:)];
NSArray *seealsos = [[[object valueForKey:@"seealsos"] allObjects] sortedArrayUsingDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES]]];
//NSArray *seealsos = [[ valueForKey:@"name"] sortedArrayUsingSelector:@selector(localizedCompare:)];
NSArray *samplecodeprojects = [[[[object valueForKey:@"samplecodeprojects"] allObjects] valueForKey:@"name"] sortedArrayUsingSelector:@selector(localizedCompare:)];

for (i = 0; i < maxrowcount + 1; i++)
Expand Down Expand Up @@ -411,7 +474,10 @@ - (void)html_metadataTable:(IGKDocRecordManagedObject *)object
if (i == 0 && [seealsos count])
[outputString appendString:@"\t\t\t\t<th>See also</th>\n"];
else if (i > 0 && i - 1 < [seealsos count])
[outputString appendFormat:@"\t\t\t\t<td><code><a href='#' class='stealth'>%@</a></code></td>\n", [seealsos objectAtIndex:i - 1]];
{
NSManagedObject *mo = [seealsos objectAtIndex:i - 1];
[outputString appendFormat:@"\t\t\t\t<td><code><a href='%@' class='stealth'>%@</a></code></td>\n", [self hrefToActualFragment:mo], [mo valueForKey:@"name"]];
}
else if ([seealsos count])
[outputString appendString:@"\t\t\t\t<td></td>\n"];

Expand Down Expand Up @@ -497,6 +563,7 @@ - (void)html_metadataTable:(IGKDocRecordManagedObject *)object

- (void)html_generic
{
[outputString appendString:@"<div class='#overview'>"];
[outputString appendString:@"<div class='overview'>"];

[outputString appendFormat:@"<h1>%@</h1>", [self escape:[transientObject valueForKey:@"name"]]];
Expand Down

0 comments on commit 148d59f

Please sign in to comment.