The following commands let you can manage firedoc themes locally.
firedoc-theme install url [--name name]
firedoc-theme uninstall [name]
firedoc-theme clear
The complete firedoc theme distrubution should be the below:
themes/default/
├── assets
│ ├── css
│ ├── favicon.png
│ ├── img
│ ├── index.html
│ ├── js
│ └── vendor
├── i18n
│ ├── en.json
│ └── zh.json
├── layouts
│ ├── main.handlebars
│ └── xhr.handlebars
├── partials
│ ├── attrs.handlebars
│ ├── class-tree.handlebars
│ ├── classes.handlebars
│ ├── enums.handlebars
│ ├── events.handlebars
│ ├── files.handlebars
│ ├── index.handlebars
│ ├── items-index.handlebars
│ ├── method.handlebars
│ ├── module.handlebars
│ ├── options.handlebars
│ ├── props.handlebars
│ └── sidebar.handlebars
├── locals.js
└── theme.json
The next, we will walk them as detailed as possible.
- The directory "layouts" stores the skelton layout file.
- The directory "partials" stores the detailed templates for
modules
,classes
and other templates used by the former. - The directory "assets" stores the static resources like scripts, css files and fonts.
- The directory "i18n" stores the i18n resources for templates, naming as
{lang}.json
. - The file
locals.js
is used to support a programable for theme developer, it is expected to export a function, which could rewrite the locals for templates variables.
By default, all templates should have the ability to access to the following variables in his template context:
{
globals: {
classes: [ /* all classes */ ],
modules: [ /* all modules */ ]
},
i18n: {
/* Just for i18n templates object
}
}
But as in some special templates, the firedoc would make some shortcuts for the corresponding template:
module
: themodule
template would be directly called at firedoc itself to generatemodules/*.html
todest
path, so that to simplify this spec, firedoc attaches the correspondingmodule
object to the current context.classes
: theclasses
template would be directly called at firedoc itself to generateclasses/*.html
todest
path, so that to simplify this spec, firedoc attaches the correspondingclass
object to the current context.
The i18n in firedoc theme template just looks like add a map variable i18n
into template locals
, and the firedoc will depends on the --lang
option's value to decide what file under i18n
would be used. The complete example are at themes/default.
At template, we just can use i18n map by the below super simple way:
<p>{{i18n.EXAMPLE_I18N_TEXT}}</p>
Sometimes, theme-maker might want a way to implement a new feature without any help from firedoc, so the locals.js
would help the themer. Here is an example:
module.exports = function (modules, classes, locals) {
// TODO
};
Then you could work with modules
, classes
and locals
that you want, like if you want to add a timestamp for all classes:
module.exports = function (modules, _, _) {
modules.forEach(function (mod) {
mod.timestamp = Date.now();
});
}
The result for the programming is that you can use the timestamp
at module
template:
Timestamp: {{timestamp}}