WaibuMpa

WaibuMpa class definition.

Never call this function directly!!! It's only-meant to be called by the Bajo framework during plugin initialization.

Constructor

new WaibuMpa()

Constructor

Members

config

Properties
TypeDescription
TConfig

Configuration object

configDev

Properties
TypeDescription
TConfigDev

Development configuration object

configProd

Properties
TypeDescription
TConfigProd

Production configuration object

htmlTags :Array.<string>

All supported HTML tags

Type:
  • Array.<string>

iconsetMappings :Object

Iconset mappings

Type:
  • Object

Methods

(async) _addRoutes(options) → {Promise.<void>}

Add routes to the application.

Parameters:
NameTypeDescription
optionsObject

The options for adding routes

Properties
NameTypeDescription
appPrefixstring

The application prefix

prefixstring

The route prefix

modsArray

The route modules

appCtxObject

The application context

cfgObject

The configuration object

Returns:
Type: 
Promise.<void>

(async) _applyFormat(options) → {Promise.<string>}

Apply formatting to the given text based on the options.

Parameters:
NameTypeDescription
optionsObject

The options for formatting

Properties
NameTypeAttributesDefaultDescription
textstring

The text to format

localsObject<optional>
{}

The local variables for the template

optsObject<optional>
{}

The options for formatting

Returns:
  • The formatted text
Type: 
Promise.<string>

(async) _buildRoute(options) → {Promise.<void>}

Build routes based on the provided options.

Parameters:
NameTypeDescription
optionsObject

The options for building routes

Properties
NameTypeDescription
filesArray

The route files

pathPrefixstring

The path prefix for the routes

dirstring

The directory containing route files

nsstring

The namespace for the routes

cfgObject

The configuration object

parentObject

The parent route object

urlPrefixstring

The URL prefix for the routes

subRouteboolean

Whether the route is a sub-route

Returns:
Type: 
Promise.<void>

(async) _buildRoutes(prefix) → {Promise.<void>}

Build routes for the application.

Parameters:
NameTypeDescription
prefixstring

The route prefix

Returns:
Type: 
Promise.<void>

_decorate()

Decorate the request and reply objects with additional properties and methods.

(async) _handleError(err, req, reply) → {Promise.<string>}

Handle general errors.

Parameters:
NameTypeDescription
errError

The error object

reqObject

The request object

replyObject

The reply object

Returns:
  • The rendered view
Type: 
Promise.<string>

(async) _handleNotFound(err, req, reply) → {Promise.<string>}

Handle not found errors.

Parameters:
NameTypeDescription
errError

The error object

reqObject

The request object

replyObject

The reply object

Returns:
  • The rendered view
Type: 
Promise.<string>

(async) _handleSession() → {Promise.<void>}

Handle session setup.

Returns:
Type: 
Promise.<void>

(async) _handleSubApp() → {Promise.<void>}

Handle sub-applications.

Returns:
Type: 
Promise.<void>

(async) _loadResource(mod, item) → {Promise.<Array>}

Load resources for the given module and item.

Parameters:
NameTypeDescription
modObject

The module object

itemstring

The item key to load resources for

Returns:
  • The loaded resources
Type: 
Promise.<Array>

(async) _trashOldSession() → {Promise.<void>}

Trash old sessions.

Returns:
Type: 
Promise.<void>

buildUrl(optionsopt) → {string}

Build a URL based on the provided options.

Parameters:
NameTypeAttributesDefaultDescription
optionsObject<optional>
{}

Options for building the URL

Properties
NameTypeAttributesDefaultDescription
excludeArray.<string><optional>
[]

Keys to exclude from the query string

prefixstring<optional>
'?'

Prefix for the query string

basestring<optional>

Base path for the URL

urlstring<optional>
''

URL to build upon

paramsObject<optional>
{}

Parameters to include in the query string

prettyUrlboolean<optional>

Whether to use a pretty URL format

Returns:
  • The constructed URL
Type: 
string

getAppTitle(req) → {string}

Get the title of the application.

Parameters:
NameTypeDescription
reqObject

The request object

Returns:
  • The title of the application
Type: 
string

getIconset(name, nameOnlyopt) → {Object|string|undefined}

Get an iconset by name.

Parameters:
NameTypeAttributesDefaultDescription
namestring

The name of the iconset

nameOnlyboolean<optional>
false

Whether to return only the name

Returns:
  • The iconset object, name, or undefined if not found
Type: 
Object | string | undefined

getMenuPages(menu, pathopt, subPathopt) → {Array}

Get the pages from a menu based on the path and subPath.

Parameters:
NameTypeAttributesDescription
menuObject

The menu object

pathstring<optional>

The path to filter the pages

subPathstring | function<optional>

The subPath to filter the pages or a function to handle the filtering

Returns:
  • The filtered pages
Type: 
Array

getPluginTitle(name, req) → {string}

Get the title of a plugin.

Parameters:
NameTypeDescription
namestring

The name of the plugin

reqObject

The request object

Returns:
  • The title of the plugin
Type: 
string

getResource(name) → {Object}

Get the resource information for a given name.

Parameters:
NameTypeDescription
namestring

The name of the resource

Returns:
  • The resource information
Type: 
Object

getSessionId(rawCookie, secure) → {string}

Get the session ID from the raw cookie.

Parameters:
NameTypeDescription
rawCookiestring

The raw cookie string

secureboolean

Whether the cookie is secure

Returns:
  • The session ID
Type: 
string

getTheme(name, nameOnlyopt) → {Object|string|undefined}

Get a theme by name.

Parameters:
NameTypeAttributesDefaultDescription
namestring

The name of the theme

nameOnlyboolean<optional>
false

Whether to return only the name

Returns:
  • The theme object, name, or undefined if not found
Type: 
Object | string | undefined

getViewEngine(ext) → {Object}

Get the view engine for a given file extension.

Parameters:
NameTypeDescription
extstring

The file extension

Returns:
  • The view engine
Type: 
Object

groupAttrs(attribsopt, keysopt, removeEmptyopt) → {Object}

Group attributes by keys.

Parameters:
NameTypeAttributesDefaultDescription
attribsObject<optional>
{}

The attributes to group

keysArray | string<optional>
[]

The keys to group by

removeEmptyboolean<optional>
true

Whether to remove empty groups

Returns:
  • The grouped attributes
Type: 
Object

(async) init()

Initialize the plugin

jsonStringify(obj, replaceropt, spaceopt) → {string}

Custom JSON stringify function.

Parameters:
NameTypeAttributesDescription
objany

The object to stringify

replacerboolean | function<optional>

The replacer function or true for custom handling

spacenumber | string<optional>

The space argument for JSON.stringify

Returns:
  • The JSON string
Type: 
string

minify(text) → {string}

Minify HTML text.

Parameters:
NameTypeDescription
textstring

The HTML text to minify

Returns:
  • The minified HTML
Type: 
string

paginationLayout(totalItems, itemsPerPageopt, currentPageopt) → {Array}

Generate pagination layout.

Parameters:
NameTypeAttributesDescription
totalItemsnumber | Object

The total number of items or an object containing pagination info

itemsPerPagenumber<optional>

The number of items per page

currentPagenumber<optional>

The current page number

Returns:
  • The pagination layout
Type: 
Array

parseAttribs(text, optionsopt) → {Object}

Parse attributes from a string or object.

Parameters:
NameTypeAttributesDefaultDescription
textstring | Object

The text or object to parse

optionsObject<optional>
{}

The options for parsing

Properties
NameTypeAttributesDefaultDescription
delimiterstring<optional>
' '

The delimiter for splitting the text

kvDelimiterstring<optional>
'='

The delimiter for key-value pairs

camelCasedKeyboolean<optional>
true

Whether to camelCase the keys

trimValueboolean<optional>
true

Whether to trim the values

Returns:
  • The parsed attributes
Type: 
Object

(async) render(tpl, localsopt, optsopt) → {Promise.<string>}

Render a template using the appropriate view engine.

Parameters:
NameTypeAttributesDefaultDescription
tplstring

The template file path

localsObject<optional>
{}

The local variables for the template

optsObject<optional>
{}

The options for rendering

Returns:
  • The rendered template
Type: 
Promise.<string>

(async) renderString(text, localsopt, optsopt) → {Promise.<string>}

Render a string using the appropriate view engine.

Parameters:
NameTypeAttributesDefaultDescription
textstring

The string to render

localsObject<optional>
{}

The local variables for the template

optsObject<optional>
{}

The options for rendering

Returns:
  • The rendered string
Type: 
Promise.<string>

(async) renderView(options) → {Promise.<string>}

Render a view with the given options.

Parameters:
NameTypeDescription
optionsObject

The options for rendering the view

Properties
NameTypeAttributesDefaultDescription
tplstring

The template to render

paramsObject<optional>
{}

The parameters for the template

optsObject<optional>
{}

The options for rendering

replyObject

The reply object

Returns:
  • The rendered view
Type: 
Promise.<string>

stringifyAttribs(obj, kebabCasedKeyopt) → {string}

Stringify attributes from an object.

Parameters:
NameTypeAttributesDefaultDescription
objObject

The object to stringify

kebabCasedKeyboolean<optional>
true

Whether to kebab-case the keys

Returns:
  • The stringified attributes
Type: 
string

stripHtmlTags(html, optionsopt) → {string}

Strip HTML tags from a string.

Parameters:
NameTypeAttributesDefaultDescription
htmlstring

The HTML string to strip

optionsObject<optional>
{}

The options for stripping

Returns:
  • The stripped string
Type: 
string

urlToBreadcrumb(url, optionsopt) → {Array}

Convert a URL to a breadcrumb array.

Parameters:
NameTypeAttributesDefaultDescription
urlstring

The URL to convert

optionsObject<optional>
{}

The options for conversion

Properties
NameTypeAttributesDefaultDescription
basestring<optional>
''

The base URL to remove

delimiterstring<optional>
'/'

The delimiter for splitting the URL

returnPartsboolean<optional>
false

Whether to return the parts array

handlerfunction<optional>

The handler function for each breadcrumb

handlerScopeObject<optional>

The scope for the handler function

handlerOptsObject<optional>
{}

The options for the handler function

Returns:
  • The breadcrumb array
Type: 
Array