Skip to content

Commit

Permalink
Add an option to turn apple-style anchors on or off.
Browse files Browse the repository at this point in the history
  • Loading branch information
beelsebob committed Dec 26, 2012
1 parent e700063 commit bfcadb2
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 90 deletions.
6 changes: 6 additions & 0 deletions Application/GBAppledocApplication.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
static NSString *kGBArgCreateDocSet = @"create-docset";
static NSString *kGBArgInstallDocSet = @"install-docset";
static NSString *kGBArgPublishDocSet = @"publish-docset";
static NSString *kGBArgUseAppleAnchors = @"use-apple-anchors";
static NSString *kGBArgKeepIntermediateFiles = @"keep-intermediate-files";
static NSString *kGBArgExitCodeThreshold = @"exit-threshold";

Expand Down Expand Up @@ -266,6 +267,7 @@ - (void)application:(DDCliApplication *)app willParseOptions:(DDGetoptLongParser
{ kGBArgCreateDocSet, 'd', DDGetoptNoArgument },
{ kGBArgInstallDocSet, 'n', DDGetoptNoArgument },
{ kGBArgPublishDocSet, 'u', DDGetoptNoArgument },
{ kGBArgUseAppleAnchors, 0, DDGetoptNoArgument },
{ GBNoArg(kGBArgCreateHTML), 0, DDGetoptNoArgument },
{ GBNoArg(kGBArgCreateDocSet), 0, DDGetoptNoArgument },
{ GBNoArg(kGBArgInstallDocSet), 0, DDGetoptNoArgument },
Expand Down Expand Up @@ -765,11 +767,13 @@ - (void)setPublishDocset:(BOOL)value {
// self.settings.installDocSet = YES;
}
}
- (void)setUseAppleAnchors:(BOOL)value { self.settings.useAppleAnchors = value; }
- (void)setNoCleanOutput:(BOOL)value { self.settings.cleanupOutputPathBeforeRunning = !value; }
- (void)setNoCreateHtml:(BOOL)value { [self setCreateHtml:!value]; }
- (void)setNoCreateDocset:(BOOL)value { [self setCreateDocset:!value]; }
- (void)setNoInstallDocset:(BOOL)value { [self setInstallDocset:!value]; }
- (void)setNoPublishDocset:(BOOL)value { [self setPublishDocset:!value]; }
- (void)setNoUseAppleAnchors:(BOOL)value { [self setUseAppleAnchors:!value]; }

- (void)setCrossrefFormat:(NSString *)value { self.settings.commentComponents.crossReferenceMarkersTemplate = value; }
- (void)setExplicitCrossref:(BOOL)value { self.settings.commentComponents.crossReferenceMarkersTemplate = value ? @"<%@>" : @"<?%@>?"; }
Expand Down Expand Up @@ -905,6 +909,7 @@ - (void)printSettingsAndArguments:(NSArray *)arguments {
ddprintf(@"--%@ = %@\n", kGBArgCreateDocSet, PRINT_BOOL(self.settings.createDocSet));
ddprintf(@"--%@ = %@\n", kGBArgInstallDocSet, PRINT_BOOL(self.settings.installDocSet));
ddprintf(@"--%@ = %@\n", kGBArgPublishDocSet, PRINT_BOOL(self.settings.publishDocSet));
ddprintf(@"--%@ = %@\n", kGBArgUseAppleAnchors, PRINT_BOOL(self.settings.useAppleAnchors));
ddprintf(@"--%@ = %@\n", kGBArgKeepIntermediateFiles, PRINT_BOOL(self.settings.keepIntermediateFiles));
ddprintf(@"--%@ = %@\n", kGBArgKeepUndocumentedObjects, PRINT_BOOL(self.settings.keepUndocumentedObjects));
ddprintf(@"--%@ = %@\n", kGBArgKeepUndocumentedMembers, PRINT_BOOL(self.settings.keepUndocumentedMembers));
Expand Down Expand Up @@ -969,6 +974,7 @@ - (void)printHelp {
PRINT_USAGE(@"-d,", kGBArgCreateDocSet, @"", @"[b] Create documentation set");
PRINT_USAGE(@"-n,", kGBArgInstallDocSet, @"", @"[b] Install documentation set to Xcode");
PRINT_USAGE(@"-u,", kGBArgPublishDocSet, @"", @"[b] Prepare DocSet for publishing");
PRINT_USAGE(@" ", kGBArgUseAppleAnchors, @"", @"[b] Use apple style anchors in docsets");
PRINT_USAGE(@" ", kGBArgCleanOutput, @"", @"[b] Remove contents of output path before starting !!CAUTION!!");
ddprintf(@"\n");
ddprintf(@"OPTIONS\n");
Expand Down
7 changes: 7 additions & 0 deletions Application/GBApplicationSettingsProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ extern id kGBCustomDocumentIndexDescKey;
*/
@property (assign) BOOL publishDocSet;

/** Specifies whether docSets should use the Apple or appledoc anchor format.
If `YES`, docset HTML files will use the format `//apple_ref/occ/symbol_type/parent_symbol/symbol_name/` for anchor names. Otherwise the format `//api/name/symbol_name` will be used.
@see createDocSet
*/
@property (assign) BOOL useAppleAnchors;

/** Specifies whether intermediate files should be kept in `outputPath` or not.
If `YES`, all intermediate files (i.e. HTML files and documentation set files) are kept in output path. If `NO`, only final results are kept. This setting not only affects how the files are being handled, it also affects performance. If intermediate files are not kept, appledoc moves files between various generation phases, otherwise it copies them. So it's prefferable to leave this option to `NO`. This option only affects output files, input source files are always left intact!
Expand Down
6 changes: 5 additions & 1 deletion Application/GBApplicationSettingsProvider.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ - (id)init {
self.createDocSet = YES;
self.installDocSet = YES;
self.publishDocSet = NO;
self.useAppleAnchors = NO;
self.repeatFirstParagraphForMemberDescription = YES;
self.preprocessHeaderDoc = NO;
self.printInformationBlockTitles = YES;
Expand Down Expand Up @@ -373,7 +374,9 @@ - (NSString *)htmlReferenceForMember:(GBModelBase *)member prefixedWith:(NSStrin
NSParameterAssert(prefix != nil);
if ([member isKindOfClass:[GBMethodData class]]) {
GBMethodData *method = (GBMethodData *)member;
return [NSString stringWithFormat:@"%@//apple_ref/occ/%@/%@/%@", prefix, [method methodTypeString], [method parentObject], method.methodSelector];
return (useAppleAnchors ?
[NSString stringWithFormat:@"%@//apple_ref/occ/%@/%@/%@", prefix, [method methodTypeString], [method parentObject], method.methodSelector] :
[NSString stringWithFormat:@"%@//api/name/%@", prefix, method.methodSelector]);
}
return @"";
}
Expand Down Expand Up @@ -623,6 +626,7 @@ - (NSString *)versionIdentifier {
@synthesize createDocSet;
@synthesize installDocSet;
@synthesize publishDocSet;
@synthesize useAppleAnchors;
@synthesize keepIntermediateFiles;
@synthesize cleanupOutputPathBeforeRunning;
@synthesize treatDocSetIndexingErrorsAsFatals;
Expand Down
2 changes: 1 addition & 1 deletion Model/GBMethodData.m
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ - (NSString *)description {

- (NSString *)methodTypeString {
BOOL isInterfaceParent = (![self.parentObject isKindOfClass:[GBClassData class]] &&
![self.parentObject isKindOfClass:[GBProtocolData class]]);
![self.parentObject isKindOfClass:[GBCategoryData class]]);
switch (self.methodType)
{
case GBMethodTypeClass:
Expand Down
100 changes: 69 additions & 31 deletions Testing/GBApplicationSettingsProviderTesting.m
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,11 @@ - (void)testHtmlReferenceNameForObject_shouldReturnProperValueForDocuments {

- (void)testHtmlReferenceNameForObject_shouldReturnProperValueForMethods {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
settings.outputPath = @"anything :)";
GBApplicationSettingsProvider *settings1 = [GBApplicationSettingsProvider provider];
GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
settings1.outputPath = @"anything :)";
settings2.outputPath = @"anything :)";
settings2.useAppleAnchors = YES;
GBMethodArgument *argument = [GBMethodArgument methodArgumentWithName:@"method"];
GBMethodData *method1 = [GBTestObjectsRegistry instanceMethodWithArguments:argument, nil];
GBMethodData *method2 = [GBTestObjectsRegistry instanceMethodWithNames:@"doSomething", @"withVars", nil];
Expand All @@ -178,47 +181,65 @@ - (void)testHtmlReferenceNameForObject_shouldReturnProperValueForMethods {
[class.methods registerMethod:method2];
[class.methods registerMethod:property];
// execute & verify
assertThat([settings htmlReferenceNameForObject:method1], is(@"//apple_ref/occ/instm/Class/method"));
assertThat([settings htmlReferenceNameForObject:method2], is(@"//apple_ref/occ/instm/Class/doSomething:withVars:"));
assertThat([settings htmlReferenceNameForObject:property], is(@"//apple_ref/occ/instp/Class/value"));
assertThat([settings1 htmlReferenceNameForObject:method1], is(@"//api/name/method"));
assertThat([settings1 htmlReferenceNameForObject:method2], is(@"//api/name/doSomething:withVars:"));
assertThat([settings1 htmlReferenceNameForObject:property], is(@"//api/name/value"));
assertThat([settings2 htmlReferenceNameForObject:method1], is(@"//apple_ref/occ/instm/Class/method"));
assertThat([settings2 htmlReferenceNameForObject:method2], is(@"//apple_ref/occ/instm/Class/doSomething:withVars:"));
assertThat([settings2 htmlReferenceNameForObject:property], is(@"//apple_ref/occ/instp/Class/value"));
}

#pragma mark HTML href references handling - index

- (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForClassFromIndex {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
settings.outputPath = @"anything :)";
GBApplicationSettingsProvider *settings1 = [GBApplicationSettingsProvider provider];
GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
settings1.outputPath = @"anything :)";
settings2.outputPath = @"anything :)";
settings2.useAppleAnchors = YES;
GBClassData *class = [GBClassData classDataWithName:@"Class"];
GBMethodData *method = [GBTestObjectsRegistry instanceMethodWithNames:@"method", nil];
[class.methods registerMethod:method];
// execute & verify
assertThat([settings htmlReferenceForObject:class fromSource:nil], is(@"Classes/Class.html"));
assertThat([settings htmlReferenceForObject:method fromSource:nil], is(@"Classes/Class.html#//apple_ref/occ/instm/Class/method:"));
assertThat([settings1 htmlReferenceForObject:class fromSource:nil], is(@"Classes/Class.html"));
assertThat([settings1 htmlReferenceForObject:method fromSource:nil], is(@"Classes/Class.html#//api/name/method:"));
assertThat([settings2 htmlReferenceForObject:class fromSource:nil], is(@"Classes/Class.html"));
assertThat([settings2 htmlReferenceForObject:method fromSource:nil], is(@"Classes/Class.html#//apple_ref/occ/instm/Class/method:"));
}

- (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForCategoryFromIndex {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
settings.outputPath = @"anything :)";
GBApplicationSettingsProvider *settings1 = [GBApplicationSettingsProvider provider];
GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
settings1.outputPath = @"anything :)";
settings2.outputPath = @"anything :)";
settings2.useAppleAnchors = YES;
GBCategoryData *category = [GBCategoryData categoryDataWithName:@"Category" className:@"Class"];
GBMethodData *method = [GBTestObjectsRegistry instanceMethodWithNames:@"method", nil];
[category.methods registerMethod:method];
// execute & verify
assertThat([settings htmlReferenceForObject:category fromSource:nil], is(@"Categories/Class+Category.html"));
assertThat([settings htmlReferenceForObject:method fromSource:nil], is(@"Categories/Class+Category.html#//apple_ref/occ/intfm/Class(Category)/method:"));
assertThat([settings1 htmlReferenceForObject:category fromSource:nil], is(@"Categories/Class+Category.html"));
assertThat([settings1 htmlReferenceForObject:method fromSource:nil], is(@"Categories/Class+Category.html#//api/name/method:"));
assertThat([settings2 htmlReferenceForObject:category fromSource:nil], is(@"Categories/Class+Category.html"));
assertThat([settings2 htmlReferenceForObject:method fromSource:nil], is(@"Categories/Class+Category.html#//apple_ref/occ/instm/Class(Category)/method:"));
}

- (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForProtocolFromIndex {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
settings.outputPath = @"anything :)";
GBApplicationSettingsProvider *settings1 = [GBApplicationSettingsProvider provider];
GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
settings1.outputPath = @"anything :)";
settings2.outputPath = @"anything :)";
settings2.useAppleAnchors = YES;
GBProtocolData *protocol = [GBProtocolData protocolDataWithName:@"Protocol"];
GBMethodData *method = [GBTestObjectsRegistry instanceMethodWithNames:@"method", nil];
[protocol.methods registerMethod:method];
// execute & verify
assertThat([settings htmlReferenceForObject:protocol fromSource:nil], is(@"Protocols/Protocol.html"));
assertThat([settings htmlReferenceForObject:method fromSource:nil], is(@"Protocols/Protocol.html#//apple_ref/occ/instm/Protocol/method:"));
assertThat([settings1 htmlReferenceForObject:protocol fromSource:nil], is(@"Protocols/Protocol.html"));
assertThat([settings1 htmlReferenceForObject:method fromSource:nil], is(@"Protocols/Protocol.html#//api/name/method:"));
assertThat([settings2 htmlReferenceForObject:protocol fromSource:nil], is(@"Protocols/Protocol.html"));
assertThat([settings2 htmlReferenceForObject:method fromSource:nil], is(@"Protocols/Protocol.html#//apple_ref/occ/intfm/Protocol/method:"));
}

- (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForDocumentFromIndex {
Expand Down Expand Up @@ -346,44 +367,61 @@ - (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForCustomDoc

- (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForTopLevelObjectToItsMemberReference {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
settings.outputPath = @"anything :)";
GBApplicationSettingsProvider *settings1 = [GBApplicationSettingsProvider provider];
GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
settings1.outputPath = @"anything :)";
settings2.outputPath = @"anything :)";
settings2.useAppleAnchors = YES;
GBClassData *class = [GBClassData classDataWithName:@"Class"];
GBMethodData *method = [GBTestObjectsRegistry propertyMethodWithArgument:@"value"];
[class.methods registerMethod:method];
// execute & verify
assertThat([settings htmlReferenceForObject:method fromSource:class], is(@"#//apple_ref/occ/instp/Class/value"));
assertThat([settings htmlReferenceForObject:class fromSource:method], is(@"Class.html"));
assertThat([settings1 htmlReferenceForObject:method fromSource:class], is(@"#//api/name/value"));
assertThat([settings1 htmlReferenceForObject:class fromSource:method], is(@"Class.html"));
assertThat([settings2 htmlReferenceForObject:method fromSource:class], is(@"#//apple_ref/occ/instp/Class/value"));
assertThat([settings2 htmlReferenceForObject:class fromSource:method], is(@"Class.html"));
}

- (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForTopLevelObjectToSameTypeRemoteMemberReference {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
settings.outputPath = @"anything :)";
GBApplicationSettingsProvider *settings1 = [GBApplicationSettingsProvider provider];
GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
settings1.outputPath = @"anything :)";
settings2.outputPath = @"anything :)";
settings2.useAppleAnchors = YES;
GBClassData *class1 = [GBClassData classDataWithName:@"Class1"];
GBClassData *class2 = [GBClassData classDataWithName:@"Class2"];
GBMethodData *method = [GBTestObjectsRegistry propertyMethodWithArgument:@"value"];
[class1.methods registerMethod:method];
// execute & verify
assertThat([settings htmlReferenceForObject:method fromSource:class2], is(@"../Classes/Class1.html#//apple_ref/occ/instp/Class1/value"));
assertThat([settings htmlReferenceForObject:method fromSource:class1], is(@"#//apple_ref/occ/instp/Class1/value"));
assertThat([settings htmlReferenceForObject:class1 fromSource:method], is(@"Class1.html"));
assertThat([settings htmlReferenceForObject:class2 fromSource:method], is(@"../Classes/Class2.html"));
assertThat([settings1 htmlReferenceForObject:method fromSource:class2], is(@"../Classes/Class1.html#//api/name/value"));
assertThat([settings1 htmlReferenceForObject:method fromSource:class1], is(@"#//api/name/value"));
assertThat([settings1 htmlReferenceForObject:class1 fromSource:method], is(@"Class1.html"));
assertThat([settings1 htmlReferenceForObject:class2 fromSource:method], is(@"../Classes/Class2.html"));
assertThat([settings2 htmlReferenceForObject:method fromSource:class2], is(@"../Classes/Class1.html#//apple_ref/occ/instp/Class1/value"));
assertThat([settings2 htmlReferenceForObject:method fromSource:class1], is(@"#//apple_ref/occ/instp/Class1/value"));
assertThat([settings2 htmlReferenceForObject:class1 fromSource:method], is(@"Class1.html"));
assertThat([settings2 htmlReferenceForObject:class2 fromSource:method], is(@"../Classes/Class2.html"));
}

- (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForTopLevelObjectToDifferentTypeRemoteMemberReference {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
settings.outputPath = @"anything :)";
GBApplicationSettingsProvider *settings1 = [GBApplicationSettingsProvider provider];
GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
settings1.outputPath = @"anything :)";
settings2.outputPath = @"anything :)";
settings2.useAppleAnchors = YES;
GBClassData *class = [GBClassData classDataWithName:@"Class"];
GBCategoryData *protocol = [GBProtocolData protocolDataWithName:@"Protocol"];
GBMethodData *method1 = [GBTestObjectsRegistry propertyMethodWithArgument:@"value1"];
GBMethodData *method2 = [GBTestObjectsRegistry propertyMethodWithArgument:@"value2"];
[class.methods registerMethod:method1];
[protocol.methods registerMethod:method2];
// execute & verify
assertThat([settings htmlReferenceForObject:method1 fromSource:protocol], is(@"../Classes/Class.html#//apple_ref/occ/instp/Class/value1"));
assertThat([settings htmlReferenceForObject:method2 fromSource:class], is(@"../Protocols/Protocol.html#//apple_ref/occ/instp/Protocol/value2"));
assertThat([settings1 htmlReferenceForObject:method1 fromSource:protocol], is(@"../Classes/Class.html#//api/name/value1"));
assertThat([settings1 htmlReferenceForObject:method2 fromSource:class], is(@"../Protocols/Protocol.html#//api/name/value2"));
assertThat([settings2 htmlReferenceForObject:method1 fromSource:protocol], is(@"../Classes/Class.html#//apple_ref/occ/instp/Class/value1"));
assertThat([settings2 htmlReferenceForObject:method2 fromSource:class], is(@"../Protocols/Protocol.html#//apple_ref/occ/intfp/Protocol/value2"));
}

#pragma mark Template files handling
Expand Down
9 changes: 9 additions & 0 deletions Testing/GBApplicationTesting.m
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,15 @@ - (void)testPublishDocSet_shouldAssignValueToSettings {
assertThatBool(settings2.publishDocSet, equalToBool(NO));
}

- (void)testUseAppleAnchors_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings1 = [self settingsByRunningWithArgs:@"--use-apple-anchors", nil];
GBApplicationSettingsProvider *settings2 = [self settingsByRunningWithArgs:@"--no-use-apple-anchors", nil];
// verify
assertThatBool(settings1.useAppleAnchors, equalToBool(YES));
assertThatBool(settings2.useAppleAnchors, equalToBool(NO));
}

- (void)testKeepIntermediateFiles_shouldAssignValueToSettings {
// setup & execute
GBApplicationSettingsProvider *settings1 = [self settingsByRunningWithArgs:@"--keep-intermediate-files", nil];
Expand Down
Loading

0 comments on commit bfcadb2

Please sign in to comment.