Skip to content
This repository
Browse code

Swap around HTML anchor format argument to be more flexble.

  • Loading branch information...
commit 63ec2a2c95f1513073102448975842ce7cc27271 1 parent bfcadb2
Tom Davie beelsebob authored
13 Application/GBAppledocApplication.m
@@ -39,7 +39,7 @@
39 39 static NSString *kGBArgCreateDocSet = @"create-docset";
40 40 static NSString *kGBArgInstallDocSet = @"install-docset";
41 41 static NSString *kGBArgPublishDocSet = @"publish-docset";
42   -static NSString *kGBArgUseAppleAnchors = @"use-apple-anchors";
  42 +static NSString *kGBArgHTMLAnchorFormat = @"html-anchors";
43 43 static NSString *kGBArgKeepIntermediateFiles = @"keep-intermediate-files";
44 44 static NSString *kGBArgExitCodeThreshold = @"exit-threshold";
45 45
@@ -267,7 +267,7 @@ - (void)application:(DDCliApplication *)app willParseOptions:(DDGetoptLongParser
267 267 { kGBArgCreateDocSet, 'd', DDGetoptNoArgument },
268 268 { kGBArgInstallDocSet, 'n', DDGetoptNoArgument },
269 269 { kGBArgPublishDocSet, 'u', DDGetoptNoArgument },
270   - { kGBArgUseAppleAnchors, 0, DDGetoptNoArgument },
  270 + { kGBArgHTMLAnchorFormat, 0, DDGetoptRequiredArgument },
271 271 { GBNoArg(kGBArgCreateHTML), 0, DDGetoptNoArgument },
272 272 { GBNoArg(kGBArgCreateDocSet), 0, DDGetoptNoArgument },
273 273 { GBNoArg(kGBArgInstallDocSet), 0, DDGetoptNoArgument },
@@ -767,13 +767,14 @@ - (void)setPublishDocset:(BOOL)value {
767 767 // self.settings.installDocSet = YES;
768 768 }
769 769 }
770   -- (void)setUseAppleAnchors:(BOOL)value { self.settings.useAppleAnchors = value; }
  770 +- (void)setHtmlAnchors:(NSString *)value {
  771 + self.settings.htmlAnchorFormat = GBHTMLAnchorFormatFromNSString(value);
  772 +}
771 773 - (void)setNoCleanOutput:(BOOL)value { self.settings.cleanupOutputPathBeforeRunning = !value; }
772 774 - (void)setNoCreateHtml:(BOOL)value { [self setCreateHtml:!value]; }
773 775 - (void)setNoCreateDocset:(BOOL)value { [self setCreateDocset:!value]; }
774 776 - (void)setNoInstallDocset:(BOOL)value { [self setInstallDocset:!value]; }
775 777 - (void)setNoPublishDocset:(BOOL)value { [self setPublishDocset:!value]; }
776   -- (void)setNoUseAppleAnchors:(BOOL)value { [self setUseAppleAnchors:!value]; }
777 778
778 779 - (void)setCrossrefFormat:(NSString *)value { self.settings.commentComponents.crossReferenceMarkersTemplate = value; }
779 780 - (void)setExplicitCrossref:(BOOL)value { self.settings.commentComponents.crossReferenceMarkersTemplate = value ? @"<%@>" : @"<?%@>?"; }
@@ -909,7 +910,7 @@ - (void)printSettingsAndArguments:(NSArray *)arguments {
909 910 ddprintf(@"--%@ = %@\n", kGBArgCreateDocSet, PRINT_BOOL(self.settings.createDocSet));
910 911 ddprintf(@"--%@ = %@\n", kGBArgInstallDocSet, PRINT_BOOL(self.settings.installDocSet));
911 912 ddprintf(@"--%@ = %@\n", kGBArgPublishDocSet, PRINT_BOOL(self.settings.publishDocSet));
912   - ddprintf(@"--%@ = %@\n", kGBArgUseAppleAnchors, PRINT_BOOL(self.settings.useAppleAnchors));
  913 + ddprintf(@"--%@ = %@\n", kGBArgHTMLAnchorFormat, NSStringFromGBHTMLAnchorFormat(self.settings.htmlAnchorFormat));
913 914 ddprintf(@"--%@ = %@\n", kGBArgKeepIntermediateFiles, PRINT_BOOL(self.settings.keepIntermediateFiles));
914 915 ddprintf(@"--%@ = %@\n", kGBArgKeepUndocumentedObjects, PRINT_BOOL(self.settings.keepUndocumentedObjects));
915 916 ddprintf(@"--%@ = %@\n", kGBArgKeepUndocumentedMembers, PRINT_BOOL(self.settings.keepUndocumentedMembers));
@@ -974,7 +975,7 @@ - (void)printHelp {
974 975 PRINT_USAGE(@"-d,", kGBArgCreateDocSet, @"", @"[b] Create documentation set");
975 976 PRINT_USAGE(@"-n,", kGBArgInstallDocSet, @"", @"[b] Install documentation set to Xcode");
976 977 PRINT_USAGE(@"-u,", kGBArgPublishDocSet, @"", @"[b] Prepare DocSet for publishing");
977   - PRINT_USAGE(@" ", kGBArgUseAppleAnchors, @"", @"[b] Use apple style anchors in docsets");
  978 + PRINT_USAGE(@" ", kGBArgHTMLAnchorFormat, @"<string>", @"[*] The html anchor format to use in DocSet HTML.");
978 979 PRINT_USAGE(@" ", kGBArgCleanOutput, @"", @"[b] Remove contents of output path before starting !!CAUTION!!");
979 980 ddprintf(@"\n");
980 981 ddprintf(@"OPTIONS\n");
18 Application/GBApplicationSettingsProvider.h
@@ -13,6 +13,15 @@
13 13
14 14 extern id kGBCustomDocumentIndexDescKey;
15 15
  16 +typedef enum
  17 +{
  18 + GBHTMLAnchorFormatAppleDoc = 0,
  19 + GBHTMLAnchorFormatApple
  20 +} GBHTMLAnchorFormat;
  21 +
  22 +GBHTMLAnchorFormat GBHTMLAnchorFormatFromNSString(NSString *formatString);
  23 +NSString *NSStringFromGBHTMLAnchorFormat(GBHTMLAnchorFormat format);
  24 +
16 25 #pragma mark -
17 26
18 27 /** Main application settings provider.
@@ -213,12 +222,15 @@ extern id kGBCustomDocumentIndexDescKey;
213 222 */
214 223 @property (assign) BOOL publishDocSet;
215 224
216   -/** Specifies whether docSets should use the Apple or appledoc anchor format.
  225 +/** Specifies the format docsets should use for their html anchors.
  226 +
  227 + If `appledoc`, docset HTML files will use the format `//api/name/symbol_name` for anchor names.
  228 +
  229 + If `apple`, docset HTML files will use the format `//apple_ref/occ/symbol_type/parent_symbol/symbol_name/`.
217 230
218   - 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.
219 231 @see createDocSet
220 232 */
221   -@property (assign) BOOL useAppleAnchors;
  233 +@property (assign) GBHTMLAnchorFormat htmlAnchorFormat;
222 234
223 235 /** Specifies whether intermediate files should be kept in `outputPath` or not.
224 236
31 Application/GBApplicationSettingsProvider.m
@@ -28,6 +28,24 @@
28 28
29 29 NSString *kGBCustomDocumentIndexDescKey = @"index-description";
30 30
  31 +GBHTMLAnchorFormat GBHTMLAnchorFormatFromNSString(NSString *formatString) {
  32 + NSString *lowercaseFormatString = [formatString lowercaseString];
  33 + if ([lowercaseFormatString isEqualToString:@"apple"]) {
  34 + return GBHTMLAnchorFormatApple;
  35 + }
  36 + // We default to appledoc format if the option is not recognised
  37 + return GBHTMLAnchorFormatAppleDoc;
  38 +}
  39 +
  40 +NSString *NSStringFromGBHTMLAnchorFormat(GBHTMLAnchorFormat format) {
  41 + switch (format) {
  42 + case GBHTMLAnchorFormatAppleDoc:
  43 + return @"appledoc";
  44 + case GBHTMLAnchorFormatApple:
  45 + return @"apple";
  46 + }
  47 +}
  48 +
31 49 #pragma mark -
32 50
33 51 @interface GBApplicationSettingsProvider ()
@@ -83,7 +101,7 @@ - (id)init {
83 101 self.createDocSet = YES;
84 102 self.installDocSet = YES;
85 103 self.publishDocSet = NO;
86   - self.useAppleAnchors = NO;
  104 + self.htmlAnchorFormat = GBHTMLAnchorFormatAppleDoc;
87 105 self.repeatFirstParagraphForMemberDescription = YES;
88 106 self.preprocessHeaderDoc = NO;
89 107 self.printInformationBlockTitles = YES;
@@ -374,9 +392,12 @@ - (NSString *)htmlReferenceForMember:(GBModelBase *)member prefixedWith:(NSStrin
374 392 NSParameterAssert(prefix != nil);
375 393 if ([member isKindOfClass:[GBMethodData class]]) {
376 394 GBMethodData *method = (GBMethodData *)member;
377   - return (useAppleAnchors ?
378   - [NSString stringWithFormat:@"%@//apple_ref/occ/%@/%@/%@", prefix, [method methodTypeString], [method parentObject], method.methodSelector] :
379   - [NSString stringWithFormat:@"%@//api/name/%@", prefix, method.methodSelector]);
  395 + switch (htmlAnchorFormat) {
  396 + case GBHTMLAnchorFormatApple:
  397 + return [NSString stringWithFormat:@"%@//apple_ref/occ/%@/%@/%@", prefix, [method methodTypeString], [method parentObject], method.methodSelector];
  398 + case GBHTMLAnchorFormatAppleDoc:
  399 + return [NSString stringWithFormat:@"%@//api/name/%@", prefix, method.methodSelector];
  400 + }
380 401 }
381 402 return @"";
382 403 }
@@ -626,7 +647,7 @@ - (NSString *)versionIdentifier {
626 647 @synthesize createDocSet;
627 648 @synthesize installDocSet;
628 649 @synthesize publishDocSet;
629   -@synthesize useAppleAnchors;
  650 +@synthesize htmlAnchorFormat;
630 651 @synthesize keepIntermediateFiles;
631 652 @synthesize cleanupOutputPathBeforeRunning;
632 653 @synthesize treatDocSetIndexingErrorsAsFatals;
2  Model/GBMethodData.m
@@ -11,7 +11,7 @@
11 11 #import "GBMethodSectionData.h"
12 12 #import "GBMethodData.h"
13 13 #import "GBClassData.h"
14   -#import "GBProtocolData.h"
  14 +#import "GBCategoryData.h"
15 15 #import "RegexKitLite.h"
16 16
17 17 @interface GBMethodData ()
14 Testing/GBApplicationSettingsProviderTesting.m
@@ -171,7 +171,7 @@ - (void)testHtmlReferenceNameForObject_shouldReturnProperValueForMethods {
171 171 GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
172 172 settings1.outputPath = @"anything :)";
173 173 settings2.outputPath = @"anything :)";
174   - settings2.useAppleAnchors = YES;
  174 + settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple;
175 175 GBMethodArgument *argument = [GBMethodArgument methodArgumentWithName:@"method"];
176 176 GBMethodData *method1 = [GBTestObjectsRegistry instanceMethodWithArguments:argument, nil];
177 177 GBMethodData *method2 = [GBTestObjectsRegistry instanceMethodWithNames:@"doSomething", @"withVars", nil];
@@ -197,7 +197,7 @@ - (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForClassFrom
197 197 GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
198 198 settings1.outputPath = @"anything :)";
199 199 settings2.outputPath = @"anything :)";
200   - settings2.useAppleAnchors = YES;
  200 + settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple;
201 201 GBClassData *class = [GBClassData classDataWithName:@"Class"];
202 202 GBMethodData *method = [GBTestObjectsRegistry instanceMethodWithNames:@"method", nil];
203 203 [class.methods registerMethod:method];
@@ -214,7 +214,7 @@ - (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForCategoryF
214 214 GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
215 215 settings1.outputPath = @"anything :)";
216 216 settings2.outputPath = @"anything :)";
217   - settings2.useAppleAnchors = YES;
  217 + settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple;
218 218 GBCategoryData *category = [GBCategoryData categoryDataWithName:@"Category" className:@"Class"];
219 219 GBMethodData *method = [GBTestObjectsRegistry instanceMethodWithNames:@"method", nil];
220 220 [category.methods registerMethod:method];
@@ -231,7 +231,7 @@ - (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForProtocolF
231 231 GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
232 232 settings1.outputPath = @"anything :)";
233 233 settings2.outputPath = @"anything :)";
234   - settings2.useAppleAnchors = YES;
  234 + settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple;
235 235 GBProtocolData *protocol = [GBProtocolData protocolDataWithName:@"Protocol"];
236 236 GBMethodData *method = [GBTestObjectsRegistry instanceMethodWithNames:@"method", nil];
237 237 [protocol.methods registerMethod:method];
@@ -371,7 +371,7 @@ - (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForTopLevelO
371 371 GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
372 372 settings1.outputPath = @"anything :)";
373 373 settings2.outputPath = @"anything :)";
374   - settings2.useAppleAnchors = YES;
  374 + settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple;
375 375 GBClassData *class = [GBClassData classDataWithName:@"Class"];
376 376 GBMethodData *method = [GBTestObjectsRegistry propertyMethodWithArgument:@"value"];
377 377 [class.methods registerMethod:method];
@@ -388,7 +388,7 @@ - (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForTopLevelO
388 388 GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
389 389 settings1.outputPath = @"anything :)";
390 390 settings2.outputPath = @"anything :)";
391   - settings2.useAppleAnchors = YES;
  391 + settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple;
392 392 GBClassData *class1 = [GBClassData classDataWithName:@"Class1"];
393 393 GBClassData *class2 = [GBClassData classDataWithName:@"Class2"];
394 394 GBMethodData *method = [GBTestObjectsRegistry propertyMethodWithArgument:@"value"];
@@ -410,7 +410,7 @@ - (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForTopLevelO
410 410 GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
411 411 settings1.outputPath = @"anything :)";
412 412 settings2.outputPath = @"anything :)";
413   - settings2.useAppleAnchors = YES;
  413 + settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple;
414 414 GBClassData *class = [GBClassData classDataWithName:@"Class"];
415 415 GBCategoryData *protocol = [GBProtocolData protocolDataWithName:@"Protocol"];
416 416 GBMethodData *method1 = [GBTestObjectsRegistry propertyMethodWithArgument:@"value1"];
10 Testing/GBApplicationTesting.m
@@ -214,11 +214,13 @@ - (void)testPublishDocSet_shouldAssignValueToSettings {
214 214
215 215 - (void)testUseAppleAnchors_shouldAssignValueToSettings {
216 216 // setup & execute
217   - GBApplicationSettingsProvider *settings1 = [self settingsByRunningWithArgs:@"--use-apple-anchors", nil];
218   - GBApplicationSettingsProvider *settings2 = [self settingsByRunningWithArgs:@"--no-use-apple-anchors", nil];
  217 + GBApplicationSettingsProvider *settings1 = [self settingsByRunningWithArgs:@"--html-anchors", @"appledoc", nil];
  218 + GBApplicationSettingsProvider *settings2 = [self settingsByRunningWithArgs:@"--html-anchors", @"apple", nil];
  219 + GBApplicationSettingsProvider *settings3 = [self settingsByRunningWithArgs:nil];
219 220 // verify
220   - assertThatBool(settings1.useAppleAnchors, equalToBool(YES));
221   - assertThatBool(settings2.useAppleAnchors, equalToBool(NO));
  221 + assertThatBool(settings1.htmlAnchorFormat, equalToInt(GBHTMLAnchorFormatAppleDoc));
  222 + assertThatBool(settings2.htmlAnchorFormat, equalToInt(GBHTMLAnchorFormatApple));
  223 + assertThatBool(settings3.htmlAnchorFormat, equalToInt(GBHTMLAnchorFormatAppleDoc));
222 224 }
223 225
224 226 - (void)testKeepIntermediateFiles_shouldAssignValueToSettings {

0 comments on commit 63ec2a2

Please sign in to comment.
Something went wrong with that request. Please try again.