Skip to content

Commit

Permalink
Swap around HTML anchor format argument to be more flexble.
Browse files Browse the repository at this point in the history
  • Loading branch information
beelsebob committed Dec 28, 2012
1 parent bfcadb2 commit 63ec2a2
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 26 deletions.
13 changes: 7 additions & 6 deletions Application/GBAppledocApplication.m
Expand Up @@ -39,7 +39,7 @@
static NSString *kGBArgCreateDocSet = @"create-docset"; static NSString *kGBArgCreateDocSet = @"create-docset";
static NSString *kGBArgInstallDocSet = @"install-docset"; static NSString *kGBArgInstallDocSet = @"install-docset";
static NSString *kGBArgPublishDocSet = @"publish-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 *kGBArgKeepIntermediateFiles = @"keep-intermediate-files";
static NSString *kGBArgExitCodeThreshold = @"exit-threshold"; static NSString *kGBArgExitCodeThreshold = @"exit-threshold";


Expand Down Expand Up @@ -267,7 +267,7 @@ - (void)application:(DDCliApplication *)app willParseOptions:(DDGetoptLongParser
{ kGBArgCreateDocSet, 'd', DDGetoptNoArgument }, { kGBArgCreateDocSet, 'd', DDGetoptNoArgument },
{ kGBArgInstallDocSet, 'n', DDGetoptNoArgument }, { kGBArgInstallDocSet, 'n', DDGetoptNoArgument },
{ kGBArgPublishDocSet, 'u', DDGetoptNoArgument }, { kGBArgPublishDocSet, 'u', DDGetoptNoArgument },
{ kGBArgUseAppleAnchors, 0, DDGetoptNoArgument }, { kGBArgHTMLAnchorFormat, 0, DDGetoptRequiredArgument },
{ GBNoArg(kGBArgCreateHTML), 0, DDGetoptNoArgument }, { GBNoArg(kGBArgCreateHTML), 0, DDGetoptNoArgument },
{ GBNoArg(kGBArgCreateDocSet), 0, DDGetoptNoArgument }, { GBNoArg(kGBArgCreateDocSet), 0, DDGetoptNoArgument },
{ GBNoArg(kGBArgInstallDocSet), 0, DDGetoptNoArgument }, { GBNoArg(kGBArgInstallDocSet), 0, DDGetoptNoArgument },
Expand Down Expand Up @@ -767,13 +767,14 @@ - (void)setPublishDocset:(BOOL)value {
// self.settings.installDocSet = YES; // 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)setNoCleanOutput:(BOOL)value { self.settings.cleanupOutputPathBeforeRunning = !value; }
- (void)setNoCreateHtml:(BOOL)value { [self setCreateHtml:!value]; } - (void)setNoCreateHtml:(BOOL)value { [self setCreateHtml:!value]; }
- (void)setNoCreateDocset:(BOOL)value { [self setCreateDocset:!value]; } - (void)setNoCreateDocset:(BOOL)value { [self setCreateDocset:!value]; }
- (void)setNoInstallDocset:(BOOL)value { [self setInstallDocset:!value]; } - (void)setNoInstallDocset:(BOOL)value { [self setInstallDocset:!value]; }
- (void)setNoPublishDocset:(BOOL)value { [self setPublishDocset:!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)setCrossrefFormat:(NSString *)value { self.settings.commentComponents.crossReferenceMarkersTemplate = value; }
- (void)setExplicitCrossref:(BOOL)value { self.settings.commentComponents.crossReferenceMarkersTemplate = value ? @"<%@>" : @"<?%@>?"; } - (void)setExplicitCrossref:(BOOL)value { self.settings.commentComponents.crossReferenceMarkersTemplate = value ? @"<%@>" : @"<?%@>?"; }
Expand Down Expand Up @@ -909,7 +910,7 @@ - (void)printSettingsAndArguments:(NSArray *)arguments {
ddprintf(@"--%@ = %@\n", kGBArgCreateDocSet, PRINT_BOOL(self.settings.createDocSet)); ddprintf(@"--%@ = %@\n", kGBArgCreateDocSet, PRINT_BOOL(self.settings.createDocSet));
ddprintf(@"--%@ = %@\n", kGBArgInstallDocSet, PRINT_BOOL(self.settings.installDocSet)); ddprintf(@"--%@ = %@\n", kGBArgInstallDocSet, PRINT_BOOL(self.settings.installDocSet));
ddprintf(@"--%@ = %@\n", kGBArgPublishDocSet, PRINT_BOOL(self.settings.publishDocSet)); 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", kGBArgKeepIntermediateFiles, PRINT_BOOL(self.settings.keepIntermediateFiles));
ddprintf(@"--%@ = %@\n", kGBArgKeepUndocumentedObjects, PRINT_BOOL(self.settings.keepUndocumentedObjects)); ddprintf(@"--%@ = %@\n", kGBArgKeepUndocumentedObjects, PRINT_BOOL(self.settings.keepUndocumentedObjects));
ddprintf(@"--%@ = %@\n", kGBArgKeepUndocumentedMembers, PRINT_BOOL(self.settings.keepUndocumentedMembers)); ddprintf(@"--%@ = %@\n", kGBArgKeepUndocumentedMembers, PRINT_BOOL(self.settings.keepUndocumentedMembers));
Expand Down Expand Up @@ -974,7 +975,7 @@ - (void)printHelp {
PRINT_USAGE(@"-d,", kGBArgCreateDocSet, @"", @"[b] Create documentation set"); PRINT_USAGE(@"-d,", kGBArgCreateDocSet, @"", @"[b] Create documentation set");
PRINT_USAGE(@"-n,", kGBArgInstallDocSet, @"", @"[b] Install documentation set to Xcode"); PRINT_USAGE(@"-n,", kGBArgInstallDocSet, @"", @"[b] Install documentation set to Xcode");
PRINT_USAGE(@"-u,", kGBArgPublishDocSet, @"", @"[b] Prepare DocSet for publishing"); PRINT_USAGE(@"-u,", kGBArgPublishDocSet, @"", @"[b] Prepare DocSet for publishing");
PRINT_USAGE(@" ", kGBArgUseAppleAnchors, @"", @"[b] Use apple style anchors in docsets"); PRINT_USAGE(@" ", kGBArgHTMLAnchorFormat, @"<string>", @"[*] The html anchor format to use in DocSet HTML.");
PRINT_USAGE(@" ", kGBArgCleanOutput, @"", @"[b] Remove contents of output path before starting !!CAUTION!!"); PRINT_USAGE(@" ", kGBArgCleanOutput, @"", @"[b] Remove contents of output path before starting !!CAUTION!!");
ddprintf(@"\n"); ddprintf(@"\n");
ddprintf(@"OPTIONS\n"); ddprintf(@"OPTIONS\n");
Expand Down
18 changes: 15 additions & 3 deletions Application/GBApplicationSettingsProvider.h
Expand Up @@ -13,6 +13,15 @@


extern id kGBCustomDocumentIndexDescKey; extern id kGBCustomDocumentIndexDescKey;


typedef enum
{
GBHTMLAnchorFormatAppleDoc = 0,
GBHTMLAnchorFormatApple
} GBHTMLAnchorFormat;

GBHTMLAnchorFormat GBHTMLAnchorFormatFromNSString(NSString *formatString);
NSString *NSStringFromGBHTMLAnchorFormat(GBHTMLAnchorFormat format);

#pragma mark - #pragma mark -


/** Main application settings provider. /** Main application settings provider.
Expand Down Expand Up @@ -213,12 +222,15 @@ extern id kGBCustomDocumentIndexDescKey;
*/ */
@property (assign) BOOL publishDocSet; @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 @see createDocSet
*/ */
@property (assign) BOOL useAppleAnchors; @property (assign) GBHTMLAnchorFormat htmlAnchorFormat;


/** Specifies whether intermediate files should be kept in `outputPath` or not. /** Specifies whether intermediate files should be kept in `outputPath` or not.
Expand Down
31 changes: 26 additions & 5 deletions Application/GBApplicationSettingsProvider.m
Expand Up @@ -28,6 +28,24 @@


NSString *kGBCustomDocumentIndexDescKey = @"index-description"; 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 - #pragma mark -


@interface GBApplicationSettingsProvider () @interface GBApplicationSettingsProvider ()
Expand Down Expand Up @@ -83,7 +101,7 @@ - (id)init {
self.createDocSet = YES; self.createDocSet = YES;
self.installDocSet = YES; self.installDocSet = YES;
self.publishDocSet = NO; self.publishDocSet = NO;
self.useAppleAnchors = NO; self.htmlAnchorFormat = GBHTMLAnchorFormatAppleDoc;
self.repeatFirstParagraphForMemberDescription = YES; self.repeatFirstParagraphForMemberDescription = YES;
self.preprocessHeaderDoc = NO; self.preprocessHeaderDoc = NO;
self.printInformationBlockTitles = YES; self.printInformationBlockTitles = YES;
Expand Down Expand Up @@ -374,9 +392,12 @@ - (NSString *)htmlReferenceForMember:(GBModelBase *)member prefixedWith:(NSStrin
NSParameterAssert(prefix != nil); NSParameterAssert(prefix != nil);
if ([member isKindOfClass:[GBMethodData class]]) { if ([member isKindOfClass:[GBMethodData class]]) {
GBMethodData *method = (GBMethodData *)member; GBMethodData *method = (GBMethodData *)member;
return (useAppleAnchors ? switch (htmlAnchorFormat) {
[NSString stringWithFormat:@"%@//apple_ref/occ/%@/%@/%@", prefix, [method methodTypeString], [method parentObject], method.methodSelector] : case GBHTMLAnchorFormatApple:
[NSString stringWithFormat:@"%@//api/name/%@", prefix, method.methodSelector]); return [NSString stringWithFormat:@"%@//apple_ref/occ/%@/%@/%@", prefix, [method methodTypeString], [method parentObject], method.methodSelector];
case GBHTMLAnchorFormatAppleDoc:
return [NSString stringWithFormat:@"%@//api/name/%@", prefix, method.methodSelector];
}
} }
return @""; return @"";
} }
Expand Down Expand Up @@ -626,7 +647,7 @@ - (NSString *)versionIdentifier {
@synthesize createDocSet; @synthesize createDocSet;
@synthesize installDocSet; @synthesize installDocSet;
@synthesize publishDocSet; @synthesize publishDocSet;
@synthesize useAppleAnchors; @synthesize htmlAnchorFormat;
@synthesize keepIntermediateFiles; @synthesize keepIntermediateFiles;
@synthesize cleanupOutputPathBeforeRunning; @synthesize cleanupOutputPathBeforeRunning;
@synthesize treatDocSetIndexingErrorsAsFatals; @synthesize treatDocSetIndexingErrorsAsFatals;
Expand Down
2 changes: 1 addition & 1 deletion Model/GBMethodData.m
Expand Up @@ -11,7 +11,7 @@
#import "GBMethodSectionData.h" #import "GBMethodSectionData.h"
#import "GBMethodData.h" #import "GBMethodData.h"
#import "GBClassData.h" #import "GBClassData.h"
#import "GBProtocolData.h" #import "GBCategoryData.h"
#import "RegexKitLite.h" #import "RegexKitLite.h"


@interface GBMethodData () @interface GBMethodData ()
Expand Down
14 changes: 7 additions & 7 deletions Testing/GBApplicationSettingsProviderTesting.m
Expand Up @@ -171,7 +171,7 @@ - (void)testHtmlReferenceNameForObject_shouldReturnProperValueForMethods {
GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider]; GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
settings1.outputPath = @"anything :)"; settings1.outputPath = @"anything :)";
settings2.outputPath = @"anything :)"; settings2.outputPath = @"anything :)";
settings2.useAppleAnchors = YES; settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple;
GBMethodArgument *argument = [GBMethodArgument methodArgumentWithName:@"method"]; GBMethodArgument *argument = [GBMethodArgument methodArgumentWithName:@"method"];
GBMethodData *method1 = [GBTestObjectsRegistry instanceMethodWithArguments:argument, nil]; GBMethodData *method1 = [GBTestObjectsRegistry instanceMethodWithArguments:argument, nil];
GBMethodData *method2 = [GBTestObjectsRegistry instanceMethodWithNames:@"doSomething", @"withVars", nil]; GBMethodData *method2 = [GBTestObjectsRegistry instanceMethodWithNames:@"doSomething", @"withVars", nil];
Expand All @@ -197,7 +197,7 @@ - (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForClassFrom
GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider]; GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
settings1.outputPath = @"anything :)"; settings1.outputPath = @"anything :)";
settings2.outputPath = @"anything :)"; settings2.outputPath = @"anything :)";
settings2.useAppleAnchors = YES; settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple;
GBClassData *class = [GBClassData classDataWithName:@"Class"]; GBClassData *class = [GBClassData classDataWithName:@"Class"];
GBMethodData *method = [GBTestObjectsRegistry instanceMethodWithNames:@"method", nil]; GBMethodData *method = [GBTestObjectsRegistry instanceMethodWithNames:@"method", nil];
[class.methods registerMethod:method]; [class.methods registerMethod:method];
Expand All @@ -214,7 +214,7 @@ - (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForCategoryF
GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider]; GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
settings1.outputPath = @"anything :)"; settings1.outputPath = @"anything :)";
settings2.outputPath = @"anything :)"; settings2.outputPath = @"anything :)";
settings2.useAppleAnchors = YES; settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple;
GBCategoryData *category = [GBCategoryData categoryDataWithName:@"Category" className:@"Class"]; GBCategoryData *category = [GBCategoryData categoryDataWithName:@"Category" className:@"Class"];
GBMethodData *method = [GBTestObjectsRegistry instanceMethodWithNames:@"method", nil]; GBMethodData *method = [GBTestObjectsRegistry instanceMethodWithNames:@"method", nil];
[category.methods registerMethod:method]; [category.methods registerMethod:method];
Expand All @@ -231,7 +231,7 @@ - (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForProtocolF
GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider]; GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
settings1.outputPath = @"anything :)"; settings1.outputPath = @"anything :)";
settings2.outputPath = @"anything :)"; settings2.outputPath = @"anything :)";
settings2.useAppleAnchors = YES; settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple;
GBProtocolData *protocol = [GBProtocolData protocolDataWithName:@"Protocol"]; GBProtocolData *protocol = [GBProtocolData protocolDataWithName:@"Protocol"];
GBMethodData *method = [GBTestObjectsRegistry instanceMethodWithNames:@"method", nil]; GBMethodData *method = [GBTestObjectsRegistry instanceMethodWithNames:@"method", nil];
[protocol.methods registerMethod:method]; [protocol.methods registerMethod:method];
Expand Down Expand Up @@ -371,7 +371,7 @@ - (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForTopLevelO
GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider]; GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
settings1.outputPath = @"anything :)"; settings1.outputPath = @"anything :)";
settings2.outputPath = @"anything :)"; settings2.outputPath = @"anything :)";
settings2.useAppleAnchors = YES; settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple;
GBClassData *class = [GBClassData classDataWithName:@"Class"]; GBClassData *class = [GBClassData classDataWithName:@"Class"];
GBMethodData *method = [GBTestObjectsRegistry propertyMethodWithArgument:@"value"]; GBMethodData *method = [GBTestObjectsRegistry propertyMethodWithArgument:@"value"];
[class.methods registerMethod:method]; [class.methods registerMethod:method];
Expand All @@ -388,7 +388,7 @@ - (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForTopLevelO
GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider]; GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
settings1.outputPath = @"anything :)"; settings1.outputPath = @"anything :)";
settings2.outputPath = @"anything :)"; settings2.outputPath = @"anything :)";
settings2.useAppleAnchors = YES; settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple;
GBClassData *class1 = [GBClassData classDataWithName:@"Class1"]; GBClassData *class1 = [GBClassData classDataWithName:@"Class1"];
GBClassData *class2 = [GBClassData classDataWithName:@"Class2"]; GBClassData *class2 = [GBClassData classDataWithName:@"Class2"];
GBMethodData *method = [GBTestObjectsRegistry propertyMethodWithArgument:@"value"]; GBMethodData *method = [GBTestObjectsRegistry propertyMethodWithArgument:@"value"];
Expand All @@ -410,7 +410,7 @@ - (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForTopLevelO
GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider]; GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
settings1.outputPath = @"anything :)"; settings1.outputPath = @"anything :)";
settings2.outputPath = @"anything :)"; settings2.outputPath = @"anything :)";
settings2.useAppleAnchors = YES; settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple;
GBClassData *class = [GBClassData classDataWithName:@"Class"]; GBClassData *class = [GBClassData classDataWithName:@"Class"];
GBCategoryData *protocol = [GBProtocolData protocolDataWithName:@"Protocol"]; GBCategoryData *protocol = [GBProtocolData protocolDataWithName:@"Protocol"];
GBMethodData *method1 = [GBTestObjectsRegistry propertyMethodWithArgument:@"value1"]; GBMethodData *method1 = [GBTestObjectsRegistry propertyMethodWithArgument:@"value1"];
Expand Down
10 changes: 6 additions & 4 deletions Testing/GBApplicationTesting.m
Expand Up @@ -214,11 +214,13 @@ - (void)testPublishDocSet_shouldAssignValueToSettings {


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


- (void)testKeepIntermediateFiles_shouldAssignValueToSettings { - (void)testKeepIntermediateFiles_shouldAssignValueToSettings {
Expand Down

0 comments on commit 63ec2a2

Please sign in to comment.