imars.com - Stéphane Lavergne's web site
Go to site navigation

NDlite

Extract documentation from source code.

Summary

Introduction

Legal

Copyright (C) 2008 Stephane Lavergne http://www.imars.com/

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Description

Useful for public and private API documentation, but also for plain text files with minimal formatting. Implements a subset of the excellent www.NaturalDocs.org philosophy.

Example

$doc = new NDlite();
$doc->parseFile($path_to_my_source_file);
echo "<h1>Developer documentation for: " . $doc->guessTitle() . "</h1>\n";
echo $doc->toXHTML(array('private' => true));

TODO

Known Bugs

Future Developments

Methods

NDlite

function NDlite($path = false, $URL = false)

Creates an instance of the NDlite class.

If you supply the optional path and url arguments, references to unknown symbols will cause lookups in the parsed source's current directory, then the root of the document path, for a matching basename.

Example

$doc = new NDlite("/usr/local/src/", "/cgi-bin/ndlite.cgi?q=");

As you can see, it becomes easy to use a standard query if you'd like, although I personally prefer the use of PATH_INFO to make NDlite less apparent to the end-user on a web site. If you're using NDlite for pre-processing, your URL might be simply the base of your site's output directory, like “/api-docs/” for example.

Parameters

path
Path to your documentation tree on disk. (Optional.)
URL
Base URL to reach this NDline instance. (Optional.)

parseFile

function parseFile($filename)

Load a file from disk into this instance. Internally, this is a wrapper around parseString() which calls PHP's file_get_contents() for you.

Parameters

filename
The file path to read.

Returns

The result of parseString().

parseString

function parseString($input)

Load a source in the form of a string, into this instance.

Parameters

input
The string containing source code to parse for comments.

Returns

Always true as of this version.

guessTitle

function guessTitle($fallback = false)

Guess the title of this instance. Only useful after parsing some source.

Parameters

fallback
Alternative if no suitable candidate is found. (Optional.)

Returns

The first of “File”, “Title”, “Class” or “Group” title found, or your fallback if none is found, or false if no fallback is provided.

toXHTML

function toXHTML($flags = false)

Produce XHTML documentation from the current source. It is up to your application to jazz it up with CSS as you'd like.

Parameters

flags
Named array of options. (Optional.)

Valid flags

private
Set true to include private topics, false or omit to limit display to regular topics only.
summary
Set false to explicitly request omitting the summary.

Returns

The XHTML string ready to display or save.

Post a comment:

(not displayed, optional)

(optional)

Don't write in these two boxes:

(URLs will become hyperlinks, please omit "http://".)

Site navigation