Alternative docstring pattern and added note to documentation.

This commit is contained in:
Florian Nücke 2014-10-07 17:53:45 +02:00
parent 09a7dd36bb
commit c9c5c66eb6
2 changed files with 13 additions and 2 deletions

View File

@ -88,6 +88,14 @@ public @interface Callback {
* more importantly you should document the expected parameters and return * more importantly you should document the expected parameters and return
* type here. * type here.
* <p/> * <p/>
* <em>Important</em>: the recommended format is either<br/>
* <tt>function(arg:type[, optionArg:type]):resultType -- Description.</tt><br/>
* or<br/>
* <tt>function(arg:type[, optionArg:type]):resultType; Description.</tt><br/>
* where the argument list can be of any format (as long as it doesn't contain
* further braces), and the return type is optional. These two formats are
* recognized by OC's NEI component documentation plugin. If you use a
* different format, the doc string will be used as-is.
*/ */
String doc() default ""; String doc() default "";

View File

@ -55,6 +55,8 @@ class DocumentationHandler(val pages: Option[Array[String]]) extends IUsageHandl
private val DocPattern = """^function(\([^)]*\)[^-]*) -- (.*)$""".r private val DocPattern = """^function(\([^)]*\)[^-]*) -- (.*)$""".r
private val VexPattern = """^function(\([^)]*\)[^-]*); (.*)$""".r
private def wrap(line: String, width: Int) = GuiDraw.fontRenderer.listFormattedStringToWidth(line, width) private def wrap(line: String, width: Int) = GuiDraw.fontRenderer.listFormattedStringToWidth(line, width)
override def getUsageHandler(input: String, ingredients: AnyRef*): IUsageHandler = { override def getUsageHandler(input: String, ingredients: AnyRef*): IUsageHandler = {
@ -67,8 +69,9 @@ class DocumentationHandler(val pages: Option[Array[String]]) extends IUsageHandl
val doc = callback.annotation.doc val doc = callback.annotation.doc
if (Strings.isNullOrEmpty(doc)) name if (Strings.isNullOrEmpty(doc)) name
else { else {
val (signature, documentation) = DocPattern findFirstIn doc match { val (signature, documentation) = doc match {
case Some(DocPattern(head, tail)) => (name + head, tail) case DocPattern(head, tail) => (name + head, tail)
case VexPattern(head, tail) => (name + head, tail)
case _ => (name, doc) case _ => (name, doc)
} }
wrap(signature, 160).map(EnumChatFormatting.BLACK.toString + _).mkString("\n") + wrap(signature, 160).map(EnumChatFormatting.BLACK.toString + _).mkString("\n") +