Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Leafdoc (or 🍂doc for short) is a NaturalDocs- and JSdoc-like documentation generator.
Leafdoc's goals are to help produce documentation which is:
See Leafdoc's documentation as generated by Leafdoc, or a test of partial Leaflet documentation as generated by Leafdoc.
git clone [...]
npm install
js test.js
Then open the Leafdoc.html file in a web browser.
The syntax is pretty much the tried-and-true directives-in-comment-blocks from
JSdoc, NaturalDocs and a gazillion others. But instead of an @
symbol, Leafdoc
uses a leaf:
/*
* 🍂method addDir: this
* 🍂param dirname: String
* 🍂param extension: String
*
* Recursively scans a directory, and parses any files that match the given `extension`
*/
Leafdoc was designed with compactness in mind, so it accepts comment blocks consisting of adjacent //
comment lines, and a shorthand syntax for function/method parameters. This is equivalent to the example just above:
// 🍂method addDir (dirname: String, extension: String): this
// Recursively scans a directory, and parses any files that match the given `extension`
If you need to be even more compact, use a semicolon (;
) to put several
directives in the same line:
// 🍂namespace Math; 🍂method sum(a: Int, b: Int): Int ; Returns the sum of two numbers
🍂class
and 🍂namespace
should be at the top of your files. They define
the context of the rest of the directives. A namespace can be used in more than
one file (for example, when plugging more functionality to an existing class).
🍂example
lets some space to demonstrate how the class / namespace is meant to be used.
🍂section
allows you to group several functions, events, methods or options
together, thematically. You may need to have sections without an explicit name
to add stuff to the default section.
Methods, functions, options, etc are a generic thing internally named "documentable":
🍂method
🍂function
🍂factory
🍂option
🍂event
🍂example
🍂property
Functions/methods/factories can have parameters, specified with
🍂param (name)
, 🍂param (name): (type)
or inline (see below).
Classes, namespaces and documentables can have 🍂aka (alternative name)
,
(short for Also Known As). This allows to create links to the same thing using
different names.
Anything can have several 🍂comment
s, explaining the thing. 🍂comment
directives can be implicit, because any (non-empty) line without an explicit
directive equals to a comment.
If a function (or any other documentable) has several alternative uses, use
the 🍂alternative
directive after to re-defining the documentable, e.g.:
/*
🍂method on(type: String, fn: Function): this
Adds the function `fn` as an event handler for the `type` event.
🍂alternative
🍂method on(types: String, fn: Function): this
Given an array of event types (strings), attaches `fn` as an event handler to each of them.
*/
In this example, the two alternatives are on(type, fn)
and on(fnMap)
. They will be shown as two different documentables.
🍂inherits (parent)
means that a class or namespace inherits all documentables
from another class or namespace.
🍂uninheritable
is applied only to sections, and hides them from the
documentation of children classes.
Any documentable has the same syntax: name, optional parameters, optional type / return type/value, default value.
name [ ( params ) ] [: type] [= default]
where params
is
name[?] [ : type ] [ , name[?] [ : type ] [ , name[?] [ : type ] ... ] ]
and where name
is a valid unicode identifier, or an ellipsis (…
). type
and default
are freeform and can have spaces.
Which means the following are possible:
An option usually has a type and a default value:
🍂option enabled: Boolean = true
But we can omit the default value:
🍂option enabled: Boolean
Or omit just the data type:
🍂option enabled = true
Or even just say there is an option:
🍂option enabled
A function with a return type:
🍂function get: String
A function with one parameter:
🍂function get(id: Int): String
Or two:
A function with one parameter:
🍂function sum(a: Int, b: Int): Int
The last function can also be written without the parameters shorthand:
🍂function sum: Int
🍂param a: Int
🍂param b: Int
Use an interrogation sign to specify a parameter as optional:
🍂function update(force? : Boolean): null
Use ellipsis to mark optional parameters:
🍂function update(…): null
You can specify everything (name, params, type, default), but no documentable uses them all in the templates. The usual schema is:
Params | Type | Default | |
---|---|---|---|
example | |||
option | X | X | |
property | X | X | |
event | X | ||
method | X | X | |
function | X | X | |
factory | X |
The output relies on a set of handlebars
templates. By default, the ones in
templates/basic
will be used. In order to use another set of templates, pass
the
templateDir` option to the Leafdoc constructor, like so:
var l = new Leafdoc({templateDir: 'leaflet'});
I will write no detailed docs on how to modify the templates. If you know some
HTML and handlebars
, just copy them and hack things away :-)
Your code might have several things of the same kind, which you want to show in the same fashion as documentables. Maybe it's files, or icons, or you have 5 trivial sub-classes which only merit one line.
You can define custom documentables by doing so:
var l = new Leafdoc();
l.registerDocumentable('icon', 'Available icons');
Whenever you add a custom documentable, you'll need to create its handlebars
template too! Failure to do so will throw an error when you are building your
documentation.
Your custom documentable will accept parameters, type, and default as the rest of documentables, and can follow the shorthand syntax. You will have to map parameters, type and default to something that makes sense for that documentable. For example, the template might map an icon's filename to the documentable's default:
🍂icon happy = 'icons/happy.gif'
A happy face
Licensed under the GNU General Public License version 3 (or "GPL3"). Check the full text at https://www.gnu.org/licenses/gpl-3.0.html.
Run apt-get install ttf-ancient-fonts
and don't ask why the fallback file for emojis is packaged as "ancient fonts".
(Linux only) Write this into a plain text file:
keycode 46 = l L l L U1F342 Lstroke lstroke
Then run xmodmap name-of-the-file
. Now 🍂 is mapped to AltGr+l
.
Of course, you can always do leafdoc.setLeadingCharacter('@');
, but that's boring.
FAQs
A lightweight NaturalDocs-like LeafletJS-style documentation generator
The npm package leafdoc receives a total of 224 weekly downloads. As such, leafdoc popularity was classified as not popular.
We found that leafdoc demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.