Module: indigo

indigo

indigoJS is the simplest localization and templating framework running on node platform.

indigoJS is a flexible library, allowing multiple configurations from the JSON file. By default indigoJS assigns a server port number from a system environment process.env.PORT if this varible is not defined on the host server, indigoJS reads the server properties from the JSON file. In case we would like to force, always start server on the port defined in the app.json we should assign true value to the force property, by default this field is ommited.

The cache property sets the header cache value for static files (in the seconds). By assigning it to zero it will prevent browser from caching.

The property webdir specifies path to the all web static resources.

By defining the environment variable as prod indigo including a minifying version of the static resources (.min.js, .min.css, compressed less) that simulates file output in deployed server, by default the value set's to dev.

Version:
  • 1.0

Example

conf/app.json { "server": { "port": 8585, "force": true, "cache": 86400, "webdir": "/examples/account/web", ... }, "environment": "dev" ... }

Members

staticindigo.appconfObject

JSON object represents application configuration.

staticindigo.debugfunction

Reference to debugging utility.

staticindigo.localesObject

Reference to libs/locales.

staticindigo.loggerObject

Reference to logging API's.

staticindigo.loggerObject

Reference to HTTP server.

Methods

close(done)

Explicitly closing http server by using unittests.

Name Type Description
done function

Callback function executing after services are terminated.

error(err, req, res)

Render an error template.

Name Type Description
err Object

Contains information about errors.

req express.Request

Defines an object to provide client request information.

res express.Response

Defines an object to assist a server in sending a response to the client.

getAppConf(appconf){Object}

Creating appconf object.

Name Type Description
appconf JSON | String

Path to the app.json file or application configuration object.

Returns:
Return reference to the configuration object.

getLocale(req, keyName){Object}

Return object with key/value pair when values will be localized base on client locale request.

Name Type Default Description
req express.Request

Defines an object to provide client request information.

keyName String 'locale' optional

Customize req.params key name refering to locale code.

Returns:
Collection of localization messages.

getNewURL(req, res, url, redirectURL){String}

Verify path to existing file in application web directory based of locale rule in libs/locales/accept-rules.json.

Name Type Description
req express.Request

Defines an object to provide client request information.

res express.Response

Defines an object to assist a server in sending a response to the client.

url String

Client request to the locale file.

redirectURL String optional

Redirect URL in case url could not verify.

Returns:
New URL base on web appllication directory defined in locale dependencies.

getWebDir(){String}

Return path to application webroot directory.

Returns:
Absolute path to webroot directory.

init(appconf){Object}

Initialization of module members by using JSON configuration object.

Name Type Description
appconf JSON | String

Path to the app.json file or application configuration object.

Returns:
Return reference to the configuration object.

libs(module){Object}

Import a module under libs directory.

Name Type Description
module String

File name.

render(req, res, fileName, locales)

Rendering HTML templates.

Name Type Description
req express.Request

Defines an object to provide client request information.

res express.Response

Defines an object to assist a server in sending a response to the client.

fileName String

Name of HTML file under application web directory.

locales Object optional

Reference to the object with localization values.

start(appconf, before, after)

Starting a server. It is called after the init method.

Name Type Description
appconf JSON | String

Path to the app.json file or application configuration object.

before function optional

Callback function before starting http server.

after function optional

Callback function after server started.

Examples

require('indigojs').start(__dirname + '/config/app.json', function(http, app) { //before }, function(http, app) { //after } });

require('indigojs').start({server:80, webdir:"/web"});

static(path, webdir)

Include Express directory handler.

Name Type Description
path String

URI path.

webdir String

Absolute path to the web directory.

substitute(str, rest)

Substitutes "{n}" tokens within the specified string with the respective arguments passed in.

Name Type Description
str String

The string to make substitutions in. This string can contain special tokens of the form {n}, where n is a zero based index, that will be replaced with the additional parameters found at that index if specified.

rest String

— Additional parameters that can be substituted in the str parameter at each {n} location, where n is an integer (zero based) index value into the array of values specified.