-
Notifications
You must be signed in to change notification settings - Fork 4
II.6.g. Boards
Place your custom board files into the boards
directory. One file may export one or several boards.
Example 1 (mu.js
):
var Board = require("./board");
module.exports = new Board("mu", "Music");
Example 2 (mu.js
):
var Board = require("./board");
var Tools = require("../helpers/tools");
module.exports = new Board("mov", Tools.translate("Movies"));
In the second example the board's title will be translatable. See: II.6.c. Translations.
Example 3: (multiple.js
):
var Board = require("./board");
module.exports = [
new Board("mu", "Music"),
new Board("mov", "Movies"),
new Board("tv", "TV series")
];
All three files will be automatically loaded by ololord.js.
Note: You may also add Board
settings with the Board.defineSetting(name, defaultValue)
method.
Constructor.
-
id
The string captcha engine identifier. -
title
Human-readable title. Either a string, or a result ofTools.translate.noop
(translation object). -
options
Additional options:
-
defaultUserName
The default user name used if not specified on post creation. -
groupName
The board group this board belongs to. -
priority
The priority of this board (uses to order boards in the navigation bar).
Example:
var board = new Board("echo", Tools.translate.noop("Boardsphere echo", "boardTitle"));
Must return a list of custom board information fields, which will be sent to clients through the III. REST API.
Example:
board.customBoardInfoFields = function() {
return ["maxLinkLength"];
};
This method is called when checking a captcha. engineName
is normally a string
captcha engine identifier.
Note: It is better to use configuration file to set captcha engines supported by the boards.
This method is called when checking if a file with with the MIME-type fileType
may be attached to a post on the board.
Note: It is better to use configuration file to set file types supported by the boards.
This method is called when a new post is added, or when an existing post is edited. It is used to get extra data from custom fields.
-
req
The Express reuqest object. -
fields
Post form fields (Object
). -
files
Post form files (Object
). Specified when creating a new post only. -
oldPost
An object representing a post. Specified when editing an existing post only.
Example:
board.postExtraData = function(req, fields) {
if (fields.thread)
return Promise.resolve(null);
var link = fields.link;
var result = testLink(link);
if (result)
return Promise.reject(result);
if (link.substr(0, 4) != "http")
link = "http://" + link;
return Promise.resolve(link);
};
Used to store post extra data in the database. May be overwritten to store complex data.
Used to load post extra data from the database. May be overwritten in conjunction with stroeExtraData
to load complex data.
Used to remove post extra data from the database. May be overwritten in conjunction with stroeExtraData
to remove complex data.
Must return a list of objects representing Express routes. Each object must have the following fields:
-
method
HTTP method (GET
,POST
, etc.). NormallyGET
. -
path
Route path relative to/api
path. -
handler
Handler function (thereq
andres
arguments will be passed to it).
Must return a list of objects representing Express routes. Each object must have the following fields:
-
method
HTTP method (GET
,POST
, etc.). NormallyPOST
. -
path
Route path relative to/action
path. -
handler
Handler function (thereq
andres
arguments will be passed to it).
A list of extra scripts (JavaScript), that will be inserted into the page. The scripts may be specified using one of the following format:
-
{ source: theSource }
Thesrc
attribute of ascript
tag will be set totheSource
exactly. -
{ fileName: theFileName }
Thesrc
attribute of ascript
tag will be set totheFileName
prefixed by the site path prefix (see I.4. Basic configuration) and the "js/" suffix. -
{ value: theValue }
Thevalue
will be used as a rawscript
tag content.
An optional parameter noEmbed
may be specified to prevent embedding the script into the page.
A list of extra stylesheets (CSS), that will be inserted into the page. The stylesheets may be specified using one of the following format:
-
{ source: theSource }
Thehref
attribute of alink
tag will be set totheSource
exactly. -
{ fileName: theFileName }
Thehref
attribute of alink
tag will be set totheFileName
prefixed by the site path prefix (see I.4. Basic configuration) and the "js/" suffix.
An optional parameter noEmbed
may be specified to prevent embedding the stylesheet into the page.
Used to test post form values and files when creating a thread or a post.
Must return a resolving Promise if the parameters are OK, and a rejecting Promise with an error message (non-empty string
) as a value otherwise.
-
req
The Express reuqest object. -
fields
Post form fields (Object
). -
files
Post form files (Object
).
Note: This function is used to test custom parameters only. Common fields, such as post text or subject, as long as the files, are tested separately.
May be used to add custom translations to the model.
translate
is a function accepting two obligatory parameters: the translation source text and the disambiguation. The latter will be used as a translation identifier in the template. See: II.6.c. Postform rules and translations.
A method that is used to render custom post header data.
May return an Object
with the fields named from 0
to 160
(step 10
), and function
values. Each function is called from within the template engine and is passed the following arguments:
-
it
Model root. -
thread
Current thread model. -
post
Current post model.
Normally, controller.sync
method is used to render the post header part.
Example:
board.customPostHeaderPart = function() {
return {
100: function(it, thread, post) {
var model = merge.recursive(it, post.extraData || {
likeCount: 0,
dislikeCount: 0
});
model.thread = thread;
model.post = post;
return controller.sync("socPostHeaderPart", model);
}
};
};
A method that is used to render custom post body data.
May return an Object
with the fields named from 0
to 50
(step 10
), and function
values. Each function is called from within the template engine and is passed the following arguments:
-
it
Model root. -
thread
Current thread model. -
post
Current post model.
Normally, controller.sync
method is used to render the post header part.
Example:
board.customPostBodyPart = function() {
return {
20: function(it, thread, post) {
if (!post.extraData)
return "";
var model = merge.recursive(it, post.extraData);
model.thread = thread;
model.post = post;
return controller.sync("rpgPostBodyPart", model);
}
};
};
Note: Take a look at the boards/board.js
file and other files in the boards
directory for better understanding of how to create custom boards.