Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixing custom titled links to remote members. #238

Merged
merged 4 commits into from

2 participants

@kenji21

Hi,

As said in issue #237, this pull request manages links to remote members with custom titles.

Added the test method testStringByConvertingCrossReferencesInString_shouldKeepManualObjectMethodLinksAndUpdateAddress.
Launched the the test app and all tests passes.

@tomaz tomaz merged commit 5a442eb into tomaz:master
@tomaz
Owner

thanks, just merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  Application/GBCommentComponentsProvider.m
@@ -99,7 +99,7 @@ - (NSString *)remoteMemberCrossReferenceRegex:(BOOL)templated {
if (templated) {
GBRETURN_ON_DEMAND([self crossReferenceRegexForRegex:[self remoteMemberCrossReferenceRegex:NO]]);
} else {
- GBRETURN_ON_DEMAND(@"([+-]?)\\[(\\S+)\\s+(\\S+)\\]");
+ GBRETURN_ON_DEMAND(@"\\[?([^\\]]*)\\]?\\(?[+-]?\\[([^]\\s]+)\\s+(\\S+)\\]\\)?");
}
}
View
18 Processing/GBCommentsProcessor.m
@@ -661,7 +661,7 @@ - (NSString *)stringByConvertingSimpleCrossReferencesInString:(NSString *)string
if (searchRange.length == 0) break;
continue;
}
-
+
// Handle all the links starting at the lowest one, adding proper Markdown syntax for each.
while ([links count] > 0) {
// Find the lowest index.
@@ -679,6 +679,7 @@ - (NSString *)stringByConvertingSimpleCrossReferencesInString:(NSString *)string
if (linkData->range.location > lastUsedLocation) {
NSRange skippedRange = NSMakeRange(lastUsedLocation, linkData->range.location - lastUsedLocation);
NSString *skippedText = [string substringWithRange:skippedRange];
+ //NSLog(@"adding skipped text to result : %@", skippedText);
[result appendString:skippedText];
}
@@ -697,13 +698,14 @@ - (NSString *)stringByConvertingSimpleCrossReferencesInString:(NSString *)string
// Exit if there's nothing more to process.
if (searchRange.location >= searchEndLocation) break;
}
-
+
// If there's some text remaining after all links, append it.
if (!isInsideMarkdown && lastUsedLocation < searchEndLocation) {
NSRange remainingRange = NSMakeRange(lastUsedLocation, searchEndLocation - lastUsedLocation);
NSString *remainingText = [string substringWithRange:remainingRange];
[result appendString:remainingText];
}
+ NSLog(@"result : %@", result);
return result;
}
@@ -859,6 +861,7 @@ - (GBCrossRefData)dataForRemoteMemberLinkInString:(NSString *)string searchRange
// Get link components. Index 0 contains full text, including optional template prefix/suffix, index 1 optional prefix, index 2 object name, index 3 selector.
NSString *linkText = [components objectAtIndex:0];
+ NSString *linkDisplayText = [components objectAtIndex:1];
NSString *objectName = [components objectAtIndex:2];
NSString *selector = [components objectAtIndex:3];
@@ -869,7 +872,7 @@ - (GBCrossRefData)dataForRemoteMemberLinkInString:(NSString *)string searchRange
if (!referencedObject) {
referencedObject = [self.store protocolWithName:objectName];
if (!referencedObject) {
- if (self.settings.warnOnInvalidCrossReference) GBLogXWarn(self.currentSourceInfo, @"Invalid %@ reference found near %@, unknown object!", linkText, self.currentSourceInfo);
+ if (self.settings.warnOnInvalidCrossReference) GBLogXWarn(self.currentSourceInfo, @"Invalid %@ reference found near %@, unknown object : %@ !", linkText, self.currentSourceInfo, objectName);
result.range = [string rangeOfString:linkText options:0 range:searchRange];
result.markdown = [NSString stringWithFormat:@"[%@ %@]", objectName, selector];
return result;
@@ -890,7 +893,14 @@ - (GBCrossRefData)dataForRemoteMemberLinkInString:(NSString *)string searchRange
// Create link data and return.
result.range = [string rangeOfString:linkText options:0 range:searchRange];
result.address = [self.settings htmlReferenceForObject:referencedMember fromSource:self.currentContext];
- result.description = [NSString stringWithFormat:@"[%@ %@]", objectName, selector];
+ if( [linkDisplayText length] > 0 )
+ {
+ result.description = linkDisplayText;
+ }
+ else
+ {
+ result.description = [NSString stringWithFormat:@"[%@ %@]", objectName, selector];
+ }
result.markdown = [self markdownLinkWithDescription:result.description address:result.address flags:flags];
return result;
}
View
30 Testing/GBCommentsProcessor-PreprocessingTesting.m
@@ -589,6 +589,36 @@ - (void)testStringByConvertingCrossReferencesInString_shouldKeepManualObjectLink
assertThat(result4, is(@"[text](docs/document.html)"));
}
+- (void)testStringByConvertingCrossReferencesInString_shouldKeepManualObjectMethodLinksAndUpdateAddress {
+ GBClassData *class = [GBClassData classDataWithName:@"Class"];
+ GBCategoryData *category = [GBCategoryData categoryDataWithName:@"Category" className:@"Class"];
+ GBProtocolData *protocol = [GBProtocolData protocolDataWithName:@"Protocol"];
+ GBDocumentData *document = [GBDocumentData documentDataWithContents:@"c" path:@"document.ext"];
+
+ GBMethodArgument *argument = [GBMethodArgument methodArgumentWithName:@"method"];
+ GBMethodData *method1 = [GBTestObjectsRegistry instanceMethodWithArguments:argument, nil];
+ GBMethodData *method2 = [GBTestObjectsRegistry instanceMethodWithNames:@"doSomething", @"withVars", nil];
+ GBMethodData *property = [GBTestObjectsRegistry propertyMethodWithArgument:@"value"];
+ [class.methods registerMethod:method1];
+ [class.methods registerMethod:method2];
+ [class.methods registerMethod:property];
+
+ GBStore *store = [GBTestObjectsRegistry storeWithObjects:class, category, protocol, document, nil];
+ GBCommentsProcessor *processor = [self processorWithStore:store];
+
+ NSString *result1 = [processor stringByConvertingCrossReferencesInString:@"[text](+[Class method])" withFlags:0];
+ NSString *result2 = [processor stringByConvertingCrossReferencesInString:@"[text]([Class doSomething:withVars:])" withFlags:0];
+ NSString *result3 = [processor stringByConvertingCrossReferencesInString:@"[text](-[Class value])" withFlags:0];
+ NSString *result4 = [processor stringByConvertingCrossReferencesInString:@"[text with space](+[Class method])" withFlags:0];
+ NSString *result5 = [processor stringByConvertingCrossReferencesInString:@"[doSomething:withVars:]([Class doSomething:withVars:])" withFlags:0];
+
+ assertThat(result1, is(@"[text](Classes/Class.html#//api/name/method)"));
+ assertThat(result2, is(@"[text](Classes/Class.html#//api/name/doSomething:withVars:)"));
+ assertThat(result3, is(@"[text](Classes/Class.html#//api/name/value)"));
+ assertThat(result4, is(@"[text with space](Classes/Class.html#//api/name/method)"));
+ assertThat(result5, is(@"[doSomething:withVars:](Classes/Class.html#//api/name/doSomething:withVars:)"));
+}
+
- (void)testStringByConvertingCrossReferencesInString_shouldIgnoreKnownObjectsInManualLinkDescriptionOrTitle {
// setup
GBClassData *class = [GBClassData classDataWithName:@"Class"];
View
4 appledoc.xcodeproj/project.pbxproj
@@ -1383,6 +1383,7 @@
"$(inherited)",
"\"$(SRCROOT)/Libraries\"",
);
+ MACOSX_DEPLOYMENT_TARGET = 10.7;
PRODUCT_NAME = appledoc;
};
name = Debug;
@@ -1408,6 +1409,7 @@
"$(inherited)",
"\"$(SRCROOT)/Libraries\"",
);
+ MACOSX_DEPLOYMENT_TARGET = 10.7;
PRODUCT_NAME = appledoc;
};
name = Release;
@@ -1474,6 +1476,7 @@
"$(inherited)",
"\"$(SRCROOT)/Libraries\"",
);
+ MACOSX_DEPLOYMENT_TARGET = 10.7;
OTHER_LDFLAGS = (
"-framework",
Foundation,
@@ -1511,6 +1514,7 @@
"$(inherited)",
"\"$(SRCROOT)/Libraries\"",
);
+ MACOSX_DEPLOYMENT_TARGET = 10.7;
OTHER_LDFLAGS = (
"-framework",
Foundation,
Something went wrong with that request. Please try again.