ViewEngineUnit

libflitter/views/ViewEngineUnit~ ViewEngineUnit

The view engine unit is responsible for registering the view engine with the underlying Express installation. It also defines a function for instantly creating route handlers from view names. This unit sets Pug as the view engine, though that would be relatively easy to alter.

Constructor

new ViewEngineUnit(views_diropt)

Source:

Instantiate the unit class. Resolves the fully-qualified path to the views directory.

Parameters:
Name Type Attributes Default Description
views_dir string <optional>
'./app/views'

path to the views directory

Extends

Members

directory :string

Source:

The fully-qualified path to the views directory.

Type:
  • string

Methods

(async) cleanup(app) → {Promise.<void>}

Source:
Inherited From:

Cleans up the unit's resources before Flitter closes.

Parameters:
Name Type Description
app module:libflitter/app/FlitterApp~FlitterApp

the Flitter app

Returns:
Type
Promise.<void>

directories() → {Object}

Source:
Overrides:

Get the directories provided by this unit. Currently, "views" mapped to module:libflitter/views/ViewEngineUnit~ViewEngineUnit#directory.

Returns:
Type
Object

(async) error(response, status, params) → {Promise.<*>}

Source:

Sends an HTTP error and renders the error view with the corresponding status code. If the status code cannot be resolved to an integer, the request status will default to 400.

Parameters:
Name Type Description
response Express/Response

the Express response to be served

status string | int

HTTP or error status code

params Object

collection of arguments to be passed to the view. The "code" key will be overwritten with the status.

Returns:
Type
Promise.<*>

(async) go(app, context) → {Promise.<void>}

Source:
Overrides:

Loads the unit. Binds the view helper function to the global context and configures Express to use the Pug view engine.

Parameters:
Name Type Description
app module:libflitter/app/FlitterApp~FlitterApp

the Flitter app

context module:libflitter/Context~Context

the unit's context

Returns:
Type
Promise.<void>

migrations() → {string}

Source:

Get the fully-qualified path to the migrations provided by this unit.

Returns:
Type
string

name() → {string}

Source:
Overrides:

Get the name of the unit.

Returns:

"views"

Type
string

(async) view(response, view_name, args, resource_list) → {Promise.<*>}

Source:

Render a view to the provided response. Passes through arguments and retrieves the specified resources for the view.

Parameters:
Name Type Description
response Express/Response

the Express response to be served

view_name string

the Flitter canonical name of the view to be served

args Object

collection of arguments to be passed directly to the view

resource_list Array.<module:libflitter/views/ViewEngineUnit~ViewEngineUnit~ResourceSpec>

array of resource specifications to be retrieved and passed to the view

Returns:
Type
Promise.<*>