Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tests and implementation for links with references to [Class method] …

…with custom title. Refs #237
  • Loading branch information...
commit 15817ad245ae0c82c9bec29d07eff5db1b51b96f 1 parent 7c302cd
kenji21 authored
3  Application/GBCommentComponentsProvider.m
View
@@ -99,7 +99,8 @@ - (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+)\\]");
+ GBRETURN_ON_DEMAND(@"\\[?(\\w*)\\]?\\(?[+-]?\\[([^]\\s]+)\\s+(\\S+)\\]\\)?");
}
}
18 Processing/GBCommentsProcessor.m
View
@@ -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;
}
26 Testing/GBCommentsProcessor-PreprocessingTesting.m
View
@@ -589,6 +589,32 @@ - (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];
+
+ 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)"));
+}
+
- (void)testStringByConvertingCrossReferencesInString_shouldIgnoreKnownObjectsInManualLinkDescriptionOrTitle {
// setup
GBClassData *class = [GBClassData classDataWithName:@"Class"];
Please sign in to comment.
Something went wrong with that request. Please try again.