diff --git a/Application/GBAppledocApplication.m b/Application/GBAppledocApplication.m index 7412cd22..b625ff99 100644 --- a/Application/GBAppledocApplication.m +++ b/Application/GBAppledocApplication.m @@ -39,7 +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 *kGBArgHTMLAnchorFormat = @"html-anchors"; static NSString *kGBArgKeepIntermediateFiles = @"keep-intermediate-files"; static NSString *kGBArgExitCodeThreshold = @"exit-threshold"; @@ -267,7 +267,7 @@ - (void)application:(DDCliApplication *)app willParseOptions:(DDGetoptLongParser { kGBArgCreateDocSet, 'd', DDGetoptNoArgument }, { kGBArgInstallDocSet, 'n', DDGetoptNoArgument }, { kGBArgPublishDocSet, 'u', DDGetoptNoArgument }, - { kGBArgUseAppleAnchors, 0, DDGetoptNoArgument }, + { kGBArgHTMLAnchorFormat, 0, DDGetoptRequiredArgument }, { GBNoArg(kGBArgCreateHTML), 0, DDGetoptNoArgument }, { GBNoArg(kGBArgCreateDocSet), 0, DDGetoptNoArgument }, { GBNoArg(kGBArgInstallDocSet), 0, DDGetoptNoArgument }, @@ -767,13 +767,14 @@ - (void)setPublishDocset:(BOOL)value { // self.settings.installDocSet = YES; } } -- (void)setUseAppleAnchors:(BOOL)value { self.settings.useAppleAnchors = value; } +- (void)setHtmlAnchors:(NSString *)value { + self.settings.htmlAnchorFormat = GBHTMLAnchorFormatFromNSString(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 ? @"<%@>" : @"?"; } @@ -909,7 +910,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", kGBArgHTMLAnchorFormat, NSStringFromGBHTMLAnchorFormat(self.settings.htmlAnchorFormat)); ddprintf(@"--%@ = %@\n", kGBArgKeepIntermediateFiles, PRINT_BOOL(self.settings.keepIntermediateFiles)); ddprintf(@"--%@ = %@\n", kGBArgKeepUndocumentedObjects, PRINT_BOOL(self.settings.keepUndocumentedObjects)); ddprintf(@"--%@ = %@\n", kGBArgKeepUndocumentedMembers, PRINT_BOOL(self.settings.keepUndocumentedMembers)); @@ -974,7 +975,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(@" ", kGBArgHTMLAnchorFormat, @"", @"[*] The html anchor format to use in DocSet HTML."); PRINT_USAGE(@" ", kGBArgCleanOutput, @"", @"[b] Remove contents of output path before starting !!CAUTION!!"); ddprintf(@"\n"); ddprintf(@"OPTIONS\n"); diff --git a/Application/GBApplicationSettingsProvider.h b/Application/GBApplicationSettingsProvider.h index 6261f9bf..c807a80c 100644 --- a/Application/GBApplicationSettingsProvider.h +++ b/Application/GBApplicationSettingsProvider.h @@ -13,6 +13,15 @@ extern id kGBCustomDocumentIndexDescKey; +typedef enum +{ + GBHTMLAnchorFormatAppleDoc = 0, + GBHTMLAnchorFormatApple +} GBHTMLAnchorFormat; + +GBHTMLAnchorFormat GBHTMLAnchorFormatFromNSString(NSString *formatString); +NSString *NSStringFromGBHTMLAnchorFormat(GBHTMLAnchorFormat format); + #pragma mark - /** Main application settings provider. @@ -213,12 +222,15 @@ extern id kGBCustomDocumentIndexDescKey; */ @property (assign) BOOL publishDocSet; -/** Specifies whether docSets should use the Apple or appledoc anchor format. +/** Specifies the format docsets should use for their html anchors. + + If `appledoc`, docset HTML files will use the format `//api/name/symbol_name` for anchor names. + + If `apple`, docset HTML files will use the format `//apple_ref/occ/symbol_type/parent_symbol/symbol_name/`. - 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; +@property (assign) GBHTMLAnchorFormat htmlAnchorFormat; /** Specifies whether intermediate files should be kept in `outputPath` or not. diff --git a/Application/GBApplicationSettingsProvider.m b/Application/GBApplicationSettingsProvider.m index 4df7615c..652df665 100644 --- a/Application/GBApplicationSettingsProvider.m +++ b/Application/GBApplicationSettingsProvider.m @@ -28,6 +28,24 @@ NSString *kGBCustomDocumentIndexDescKey = @"index-description"; +GBHTMLAnchorFormat GBHTMLAnchorFormatFromNSString(NSString *formatString) { + NSString *lowercaseFormatString = [formatString lowercaseString]; + if ([lowercaseFormatString isEqualToString:@"apple"]) { + return GBHTMLAnchorFormatApple; + } + // We default to appledoc format if the option is not recognised + return GBHTMLAnchorFormatAppleDoc; +} + +NSString *NSStringFromGBHTMLAnchorFormat(GBHTMLAnchorFormat format) { + switch (format) { + case GBHTMLAnchorFormatAppleDoc: + return @"appledoc"; + case GBHTMLAnchorFormatApple: + return @"apple"; + } +} + #pragma mark - @interface GBApplicationSettingsProvider () @@ -83,7 +101,7 @@ - (id)init { self.createDocSet = YES; self.installDocSet = YES; self.publishDocSet = NO; - self.useAppleAnchors = NO; + self.htmlAnchorFormat = GBHTMLAnchorFormatAppleDoc; self.repeatFirstParagraphForMemberDescription = YES; self.preprocessHeaderDoc = NO; self.printInformationBlockTitles = YES; @@ -374,9 +392,12 @@ - (NSString *)htmlReferenceForMember:(GBModelBase *)member prefixedWith:(NSStrin NSParameterAssert(prefix != nil); if ([member isKindOfClass:[GBMethodData class]]) { GBMethodData *method = (GBMethodData *)member; - return (useAppleAnchors ? - [NSString stringWithFormat:@"%@//apple_ref/occ/%@/%@/%@", prefix, [method methodTypeString], [method parentObject], method.methodSelector] : - [NSString stringWithFormat:@"%@//api/name/%@", prefix, method.methodSelector]); + switch (htmlAnchorFormat) { + case GBHTMLAnchorFormatApple: + return [NSString stringWithFormat:@"%@//apple_ref/occ/%@/%@/%@", prefix, [method methodTypeString], [method parentObject], method.methodSelector]; + case GBHTMLAnchorFormatAppleDoc: + return [NSString stringWithFormat:@"%@//api/name/%@", prefix, method.methodSelector]; + } } return @""; } @@ -626,7 +647,7 @@ - (NSString *)versionIdentifier { @synthesize createDocSet; @synthesize installDocSet; @synthesize publishDocSet; -@synthesize useAppleAnchors; +@synthesize htmlAnchorFormat; @synthesize keepIntermediateFiles; @synthesize cleanupOutputPathBeforeRunning; @synthesize treatDocSetIndexingErrorsAsFatals; diff --git a/Model/GBMethodData.m b/Model/GBMethodData.m index c64aea05..d763c465 100644 --- a/Model/GBMethodData.m +++ b/Model/GBMethodData.m @@ -11,7 +11,7 @@ #import "GBMethodSectionData.h" #import "GBMethodData.h" #import "GBClassData.h" -#import "GBProtocolData.h" +#import "GBCategoryData.h" #import "RegexKitLite.h" @interface GBMethodData () diff --git a/Testing/GBApplicationSettingsProviderTesting.m b/Testing/GBApplicationSettingsProviderTesting.m index c8d42966..2c0871ba 100644 --- a/Testing/GBApplicationSettingsProviderTesting.m +++ b/Testing/GBApplicationSettingsProviderTesting.m @@ -171,7 +171,7 @@ - (void)testHtmlReferenceNameForObject_shouldReturnProperValueForMethods { GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider]; settings1.outputPath = @"anything :)"; settings2.outputPath = @"anything :)"; - settings2.useAppleAnchors = YES; + settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple; GBMethodArgument *argument = [GBMethodArgument methodArgumentWithName:@"method"]; GBMethodData *method1 = [GBTestObjectsRegistry instanceMethodWithArguments:argument, nil]; GBMethodData *method2 = [GBTestObjectsRegistry instanceMethodWithNames:@"doSomething", @"withVars", nil]; @@ -197,7 +197,7 @@ - (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForClassFrom GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider]; settings1.outputPath = @"anything :)"; settings2.outputPath = @"anything :)"; - settings2.useAppleAnchors = YES; + settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple; GBClassData *class = [GBClassData classDataWithName:@"Class"]; GBMethodData *method = [GBTestObjectsRegistry instanceMethodWithNames:@"method", nil]; [class.methods registerMethod:method]; @@ -214,7 +214,7 @@ - (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForCategoryF GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider]; settings1.outputPath = @"anything :)"; settings2.outputPath = @"anything :)"; - settings2.useAppleAnchors = YES; + settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple; GBCategoryData *category = [GBCategoryData categoryDataWithName:@"Category" className:@"Class"]; GBMethodData *method = [GBTestObjectsRegistry instanceMethodWithNames:@"method", nil]; [category.methods registerMethod:method]; @@ -231,7 +231,7 @@ - (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForProtocolF GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider]; settings1.outputPath = @"anything :)"; settings2.outputPath = @"anything :)"; - settings2.useAppleAnchors = YES; + settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple; GBProtocolData *protocol = [GBProtocolData protocolDataWithName:@"Protocol"]; GBMethodData *method = [GBTestObjectsRegistry instanceMethodWithNames:@"method", nil]; [protocol.methods registerMethod:method]; @@ -371,7 +371,7 @@ - (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForTopLevelO GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider]; settings1.outputPath = @"anything :)"; settings2.outputPath = @"anything :)"; - settings2.useAppleAnchors = YES; + settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple; GBClassData *class = [GBClassData classDataWithName:@"Class"]; GBMethodData *method = [GBTestObjectsRegistry propertyMethodWithArgument:@"value"]; [class.methods registerMethod:method]; @@ -388,7 +388,7 @@ - (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForTopLevelO GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider]; settings1.outputPath = @"anything :)"; settings2.outputPath = @"anything :)"; - settings2.useAppleAnchors = YES; + settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple; GBClassData *class1 = [GBClassData classDataWithName:@"Class1"]; GBClassData *class2 = [GBClassData classDataWithName:@"Class2"]; GBMethodData *method = [GBTestObjectsRegistry propertyMethodWithArgument:@"value"]; @@ -410,7 +410,7 @@ - (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForTopLevelO GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider]; settings1.outputPath = @"anything :)"; settings2.outputPath = @"anything :)"; - settings2.useAppleAnchors = YES; + settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple; GBClassData *class = [GBClassData classDataWithName:@"Class"]; GBCategoryData *protocol = [GBProtocolData protocolDataWithName:@"Protocol"]; GBMethodData *method1 = [GBTestObjectsRegistry propertyMethodWithArgument:@"value1"]; diff --git a/Testing/GBApplicationTesting.m b/Testing/GBApplicationTesting.m index a70831fb..ac46c9a9 100644 --- a/Testing/GBApplicationTesting.m +++ b/Testing/GBApplicationTesting.m @@ -214,11 +214,13 @@ - (void)testPublishDocSet_shouldAssignValueToSettings { - (void)testUseAppleAnchors_shouldAssignValueToSettings { // setup & execute - GBApplicationSettingsProvider *settings1 = [self settingsByRunningWithArgs:@"--use-apple-anchors", nil]; - GBApplicationSettingsProvider *settings2 = [self settingsByRunningWithArgs:@"--no-use-apple-anchors", nil]; + GBApplicationSettingsProvider *settings1 = [self settingsByRunningWithArgs:@"--html-anchors", @"appledoc", nil]; + GBApplicationSettingsProvider *settings2 = [self settingsByRunningWithArgs:@"--html-anchors", @"apple", nil]; + GBApplicationSettingsProvider *settings3 = [self settingsByRunningWithArgs:nil]; // verify - assertThatBool(settings1.useAppleAnchors, equalToBool(YES)); - assertThatBool(settings2.useAppleAnchors, equalToBool(NO)); + assertThatBool(settings1.htmlAnchorFormat, equalToInt(GBHTMLAnchorFormatAppleDoc)); + assertThatBool(settings2.htmlAnchorFormat, equalToInt(GBHTMLAnchorFormatApple)); + assertThatBool(settings3.htmlAnchorFormat, equalToInt(GBHTMLAnchorFormatAppleDoc)); } - (void)testKeepIntermediateFiles_shouldAssignValueToSettings {