Show Menu
Cheatography

Total.js cheat sheet Cheat Sheet (DRAFT) by

Total.js Platform is a collection of server-side & client-side JavaScript/Node.js libraries, Web Components, icons, practices, and complete apps written in pure JavaScript, mostly without dependencies. Free and open-source.

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Contro­llers

Controller Instance
var controller = this;
returns
instance
contro­lle­r.body
Gets the parsed data from the request body.
returns
object
contro­ller.ip
Gets the HTTP host address
returns
string
contro­lle­r.l­anguage
Gets/Sets the controller language for the locali­zation
returns
string
contro­lle­r.p­arams
Gets a dynamic params from URL
returns
object
contro­lle­r.query
Gets the parsed data from the URL address query
returns
object
contro­lle­r.req
Gets the HTTP request
returns
object
contro­lle­r.res
Gets the HTTP response
returns
object
contro­lle­r.url
Gets a relative lower-case URL
returns
string
contro­lle­r.user
Gets the user instance if exists
returns
object
contro­lle­r.c­all­bac­k([­vie­w_n­ame])
Returns data as JSON or view
returns
Function
contro­lle­r.f­ile­(fi­lename, [callb­ack])
Sends the file into response
returns controller
instance
contro­lle­r.f­ile­fs(­name, id,[ca­llb­ack])
Sends a stored file in FileSt­orage
returns controller
instance
contro­lle­r.h­ost­nam­e([­path])
Gets the hostname
returns
string
contro­lle­r.l­ayo­ut(­name)
Sets a layout before the current view
returns controller
instance
contro­lle­r.i­nva­lid­(error)
Creates an ErrorB­uilder instance
returns
ErrorB­uilder
contro­lle­r.p­lai­n(text, [headers])
Sends the plain text
returns controller
instance
contro­lle­r.p­rox­y(o­pt/url)
Creates a proxy for the current request
returns
object
contro­lle­r.r­edi­rec­t(url, [perma­ment])
Creates a redire­ction
returns controller
instance
contro­lle­r.s­ucc­ess­([s­ucc­ess], [value])
Alias for
contro­lle­r.j­son­(SU­CCE­SS(­true))
returns controller
instance
contro­lle­r.t­hro­w40­4([­pro­blem])
Sends a
404 error - Not found
into response
returns controller
instance
contro­lle­r.v­iew­(na­me/url, [model])
Sends the view
returns controller
instance
or
string

Info

Setup

$ sudo npm install -g total4
$ total4 create empty myapp
Create an empty project from template.
To list available commands:
$ total4 help

To list available templates:
$ total4 templates

To create from template:
$ total4 create <te­mpl­ate­_na­me> <pa­th/­to/­emp­ty/­fol­der>

Start Script

// index.js
var opt = {};
opt.port = 5000;

require('total4/debug')(opt);

$ (delegate)

$.body
Returns body data from the request
returns
object
$.cont­roller
Contains s current instance of
Controller
returns controller
instance
$.files
Returns list of uploaded files
returns
Array HttpFile
$.headers
Returns current request headers
returns
object
$.id
Returns the value of the first parsed dynamic parameter
returns
string
$.ip
Returns IP address form the Request
returns
string
$.language
Returns parsed language from the Request
returns
String
$.model
Returns the current model according to the
Schema
returns
object
$.params
Returns parsed dynamic parameters from URL
returns
object
$.req
Returns the current Request instance
returns
Request
$.res
Returns the current Response instance
returns
Response
$.user
Returns
user
instance from the Request
returns
object
$.acti­on(­schema, [data])
This method is an alias fron the
CALL()
method
returns
Caller
$.call­bac­k([­error], [value])
Performs a callback
returns
Function
$.done­([arg])
It wraps
$.succ­ess()
and
$.inva­lid()
method into the one function
returns
Functi­on(err, response)
$.inva­lid­(name, [error])
This method appends an
Error
to
ErrorB­uilder
returns
ErrorB­uilder
$.redi­rec­t(url)
Performs redirect directly from the operation
returns
Function
$.succ­ess­([is], [value])
This method returns preddefind success object
returns
{ success: true }
 

Project Structure (MVC)

Total.js project contains a simple directory structure, and all direct­ories are optional. You can choose what you want to use and when. Read more in docs

Schemas

schema­s.f­ields
Returns all fields names from the schema
schema­s.d­efi­ne(­name, type)
Defines the fields for the current entity
schema­s.a­cti­on(­name, options)
Registers a new schema action
action
options
Options for regist­ering new schema action
option­s.name {String}
(optio­nal), a human readable action name
option­s.p­arams {String}
(optio­nal), a parameter for the schema
option­s.query {String}
(optio­nal), query arguments for the schema
option­s.input {String}
(optio­nal), input data schema
option­s.a­ction {Funct­ion($, model)}
(requi­red), a function that will be executed
Schemas are one of the most used parts of the Total.js framework. Schemas offer you full control over incoming data.