ringdocdocumentation for Ring packages

Extending ringdoc

A project can add its own directives, pages that are not in the sidebar, and a step that runs before the pages are made.

ringdoc has no knowledge of any one package. What a package needs beyond the standard features stays in the package: the project file docproject.ring names Ring functions, and ringdoc calls them.

Your own directive#

Ring
aDocProject = [
	...
	:directives = [ ["stats","statsHtml"] ],
	...
]

func statsHtml cText
	return "<p>" + len(aFiles) + " files</p>"

A line {{stats}} or {{stats:some text}} in a page is replaced by the HTML the function returns. The function gets the text after the colon (an empty string when there is none). The functions can be in docproject.ring itself, or in Ring files named by :load (relative to the project folder):

Ring
:load = [ "docfunctions.ring" ],

A step before the pages are made#

Ring
:prebuild = "makeApiPages",

The function is called once, after the assets are copied and before the pages are made. It can write files into the source folder and change the list of pages aDocPages (items are [name, title, group]). The folder helpers hereFolder() (the project), rootFolder() and docsFolder() (the site) are available.

A page made of HTML#

A page of :pages whose source folder has name.html and no name.md is made from that file: the file is the body of the page, as HTML. This is the way for a function that generates pages, such as a class reference from the data of a library. The file may start with the same --- block as a Markdown page (title:, lead:).

Pages outside the sidebar#

A fourth item in a page makes it hidden:

Ring
["api-system","System","API","hidden"]

A hidden page is built, searched and can be linked, but it is not in the sidebar and not in the previous/next links. The PDF leaves hidden pages out unless the project has :pdfhidden = true.

The example#

samples/UsingRingDoc/hello/docproject.ring has a directive ({{greeting:Ring}}), a :prebuild function that writes a hidden HTML page, and the functions themselves:

samples/UsingRingDoc/hello/docproject.ring
samples/UsingRingDoc/hello/docproject.ring
# The example project of ringdoc: a tiny package (hello.ring) with a guide and a reference page made from its source.
#
#     ringdoc build

aDocProject = [
	:name = "Hello",
	:tagline = "an example",
	:logo = "H",
	:description = "A tiny Ring package that shows what ringdoc makes",
	:footer = "Hello - an example of a documentation made with ringdoc.",
	:source = "src",
	:output = "docs",
	:directives = [ ["greeting","greetingHtml"] ],
	:prebuild = "makeGenerated",
	:galleries = [
		[ :name = "samples", :folder = "samples", :prefix = "hello-", :run = "ring samples/{file}" ]
	],
	:pages = [
		["index","Overview","Start"],
		["guide","Guide","Start"],
		["samples","Samples","Start"],
		["reference","Reference","Reference"],
		["generated","A generated page","Extras","hidden"]
	]
]

# {{greeting:Ring}} in a page: the HTML that this function returns
func greetingHtml cText

	return '<p class="greeting">Hello, ' + cText + '!</p>'

# called before the pages are made: writes a page as HTML (a page of the project that is not in the sidebar)
func makeGenerated

	writeText(hereFolder() + "/src/generated.html","<h2 id=" + '"generated"' + ">Made by the project</h2><p>This page was written by the function makeGenerated of docproject.ring.</p>")
ringdoc - documentation made with ringdoc.