sbt plugin for generating documentation.
Takes a documentation.conf file in the root of an sbt project and turns it into a delicious README.
Uses HOCON (although other markup formats may supported in the future) for data and
mustache for document rendering.
Get started by adding the following to your project/plugins.sbt
resolvers += "netlogo-extension-documentation" at "https://dl.cloudsmith.io/public/netlogo/netlogo-extension-documentation/maven/"
addSbtPlugin("org.nlogo" % "netlogo-extension-documentation" % "0.8.2")Or for sbt 0.13.x
resolvers += Resolver.url(
"NetLogo-JVM",
url("http://dl.bintray.com/content/netlogo/NetLogo-JVM"))(
Resolver.ivyStylePatterns)
addSbtPlugin("org.nlogo" % "netlogo-extension-documentation" % "0.7.2")Then add the following to your build.sbt
enablePlugins(org.nlogo.build.ExtensionDocumentationPlugin)Finally, add a simple documentation.conf
extensionName = "my-ext"
markdownTemplate = """
# Your NetLogo Extension
This extension contains NetLogo primitives
{{> BUILDING.md}}
## Primitives
{{#primitives}}
{{> primTemplate}}
{{/primitives}}
"""
primTemplate = """
### `{{name}}`
```NetLogo
{{#examples}}
{{{#isOptional}}({{/isOptional}}{{primitive.fullName}}{{#args}} *{{argumentPlaceholder}}*{{/args}}{{#isOptional}}){{/isOptional}}
{{/examples}}
```
{{{description}}}
"""
primitives = [
{
name: a-command,
type: command,
arguments: [ { name: my-turtle, type: turtle } ],
description: "does thing to turtle"
},
{
name: a-reporter,
type: reporter,
returns: anything,
arguments: [ { name: list-of-stuff, type: list } ],
description: "returns a thing from the list"
}
]
Then run the extensionDocument sbt command and you'll see a shiny new README!
These are the recognized top-level keys in documentation.conf.
-
markdownTemplate: Template for the README.md. Required to useextensionDocument. -
primTemplate: Template for rendering primitives in the README.md. This produces a list of strings, accessible within themarkdownTemplateasallPrimitives. -
primitives: Array of primitive objects. Required to useextensionDocument. -
tableOfContents: Optional object mapping tags to ToC sections. Looks like{ "tag1": "Full Section Name 1", "tag2": "Full Section Name 2" } -
additionalVariables: Optional object with keys will be available tomarkdownTemplate. -
filesToIncludeInManual: Optional array of strings. If present, tells the NetLogo manual which files to include when building. It is recommended that instructions on how to build the extension, as well as licensing information be ommitted from the NetLogo manual. -
extensionName: Optional string. If present all prims will have the string, along with a colon, prefixed to their name.
Primitives have the following keys:
name: Required. Primitive will be ommitted ifnameis not present.type: Strongly Recommended. Must be eithercommandorreporter. Defaults tocommandif not present.returns: Strongly Recommended for reporters. Specifies the return type of the primitive. Defaults to wildcard / anything if not present.arguments: Optional. List of arguments to the primitive. If the primitive accepts no arguments, this key may be omitted.alternateArguments: Optional. List of arguments to the primitive. Use this if the primitive accepts a different set of arguments than under arguments. An argument is an objecttypekey and an optionalnamekey. thetypekey should be one of the types listed below.description: Strongly recommended. Description of the primitive, in Markdown.
The following types are recognized. All other types are assumed to be a custom type.
""or"anything": wildcard type / any type"list""string""boolean""number""patchset""turtleset""linkset""turtle""patch""symbol""command block""optional command block""reporter block""command": anonymous command or name of command"reporter": anonymous reporter or name of reporter"reference""code block""repeatable x": Repeatable of x- all others: custom type with specified name
- Use mustache partials to include files from
extensionDocumentationIncludePath. This defauls to the project root, but may be changed. Usage:{{> FILENAME.md }}. Note that the same variables will be available toFILENAME.mdas are available in the markdown template, if you would like to include mustached in those files. contentsis a list of table of contents objects that look like the following:
{
fullCategoryName: "Full Name here",
shortCategoryName: "tagName",
prims: <List of prims as described in Primitives template below>
}
primitivesis a decorated list of primitive objects. You can use this in conjunction withprimTemplate, which is available as a partial. This looks like:{{#primitives}}{{> primTemplate}}{{/primitives}}`- any variables from
additionalConfigwill be available. For instance, if you hadadditionalConfig: { netlogoUrl = "ccl.northwestern.edu/netlogo/" }, you could use the following in the markdown template:[The NetLogo Website]({{netlogoUrl}}).
name: The name of the primitive_name_: The name of the primitive, lowercased.argumentPlaceholder: The name of the primitive with spaces replaced by underscores so it is a single word.description: (remember to use{{{,}}}, as this is in markdown)primitive: a Primitive object (see PrimitiveData.scala)isInfix: boolean value, true only if primitive is infix primexamples: a list of objects encapsulating argument sets. There will always be one element inexamples, even if theargumentskey wasn't specified. Examples contains the following:name: The name of the primitive call, including the extension prefix_name_: The name of the primitive call, lowercasedprimitive: The Primitive object this example belongs to (see PrimitiveData.scala)args: a list of argument values from above (NamedTypein PrimitiveData.scala). Each argument has the following keys:name: the name given to the argumenttypeName: The TypeName of the argument. Use{{typeName.name}}to get the human-readable name of the type
leftArg: a single argument value (infix primitives only)rightArgs: a list of argument values, omitting left argument (infix primitives only)isOptional: boolean value, true if this example is for an alternative set of arguments whose length is different than the primary example.
- All variables defined in
additionalConfigare also available.
The following are top-level keys which were superseded in 0.7.0 but are still available for convenience.
allPrimitiveswas a list of strings created by running each primitive through the primTemplate. Useprimitivesand theprimTemplatepartial instead. The extension documentation plugin will automatically convert the typically-used{{#allPrimitives}}{{{.}}}{{/allPrimitives}}to{{#primitives}}{{> primTemplate }}{{/allPrimitives}}, but this conversion will likely be removed in future versions.includeis a lambda that includes files fromextensionDocumentationIncludePath. This defauls to the project root, but may be changed. Use like:{{#include}}FILENAME.md{{/include}}.includewill likely be phased out in a future version - it is recommended to use partials instead ({{> FILENAME.md}}).
The netlogo-extension-documentation plugin is in the public domain. To the extent possible under law, Uri Wilensky has waived all copyright and related or neighboring rights.
Package repository hosting is graciously provided by Cloudsmith.
