Permalink
Browse files

Add an option to turn apple-style anchors on or off.

  • Loading branch information...
1 parent e700063 commit bfcadb21057b3f617e6a49c50e5610ad9ef45422 @beelsebob beelsebob committed Dec 26, 2012
@@ -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";
@@ -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 },
@@ -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 ? @"<%@>" : @"<?%@>?"; }
@@ -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));
@@ -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");
@@ -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!
@@ -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;
@@ -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 @"";
}
@@ -623,6 +626,7 @@ - (NSString *)versionIdentifier {
@synthesize createDocSet;
@synthesize installDocSet;
@synthesize publishDocSet;
+@synthesize useAppleAnchors;
@synthesize keepIntermediateFiles;
@synthesize cleanupOutputPathBeforeRunning;
@synthesize treatDocSetIndexingErrorsAsFatals;
@@ -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:
@@ -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];
@@ -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 {
@@ -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
@@ -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];
Oops, something went wrong. Retry.

0 comments on commit bfcadb2

Please sign in to comment.