\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Louis Bertson} \pdfinfo{ /Title (total-js-cheat-sheet.pdf) /Creator (Cheatography) /Author (Louis Bertson) /Subject (Total.js Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{8CC152} \definecolor{LightBackground}{HTML}{F7FBF4} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Total.js Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Louis Bertson} via \textcolor{DarkBackground}{\uline{cheatography.com/183053/cs/38094/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Louis Bertson \\ \uline{cheatography.com/louis-bertson} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 7th April, 2023.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{x{2.584 cm} x{2.508 cm} x{2.508 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Controllers}} \tn % Row 0 \SetRowColor{LightBackground} Controller Instance & `var controller = this;` & returns `instance` \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{`controller.body`} & Gets the parsed data from the request body. & returns `object` \tn % Row Count 6 (+ 4) % Row 2 \SetRowColor{LightBackground} \seqsplit{`controller.ip`} & Gets the HTTP host address & returns `string` \tn % Row Count 8 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{`controller.language`} & Gets/Sets the controller language for the localization & returns `string` \tn % Row Count 13 (+ 5) % Row 4 \SetRowColor{LightBackground} \seqsplit{`controller.params`} & Gets a dynamic params from URL & returns `object` \tn % Row Count 16 (+ 3) % Row 5 \SetRowColor{white} \seqsplit{`controller.query`} & Gets the parsed data from the URL address query & returns `object` \tn % Row Count 20 (+ 4) % Row 6 \SetRowColor{LightBackground} \seqsplit{`controller.req`} & Gets the HTTP request & returns `object` \tn % Row Count 22 (+ 2) % Row 7 \SetRowColor{white} \seqsplit{`controller.res`} & Gets the HTTP response & returns `object` \tn % Row Count 24 (+ 2) % Row 8 \SetRowColor{LightBackground} \seqsplit{`controller.url`} & Gets a relative lower-case URL & returns `string` \tn % Row Count 27 (+ 3) % Row 9 \SetRowColor{white} \seqsplit{`controller.user`} & Gets the user instance if exists & returns `object` \tn % Row Count 30 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{2.584 cm} x{2.508 cm} x{2.508 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Controllers (cont)}} \tn % Row 10 \SetRowColor{LightBackground} `controller.callback({[}view\_name{]})` & Returns data as JSON or view & returns `Function` \tn % Row Count 3 (+ 3) % Row 11 \SetRowColor{white} \seqsplit{`controller.file(filename}, {[}callback{]})` & Sends the file into response & returns controller `instance` \tn % Row Count 6 (+ 3) % Row 12 \SetRowColor{LightBackground} \seqsplit{`controller.filefs(name}, id,{[}callback{]})` & Sends a stored file in FileStorage & returns controller `instance` \tn % Row Count 10 (+ 4) % Row 13 \SetRowColor{white} `controller.hostname({[}path{]})` & Gets the hostname & returns `string` \tn % Row Count 13 (+ 3) % Row 14 \SetRowColor{LightBackground} \seqsplit{`controller.layout(name)`} & Sets a layout before the current view & returns controller `instance` \tn % Row Count 16 (+ 3) % Row 15 \SetRowColor{white} \seqsplit{`controller.invalid(error)`} & Creates an ErrorBuilder instance & returns \seqsplit{`ErrorBuilder`} \tn % Row Count 19 (+ 3) % Row 16 \SetRowColor{LightBackground} \seqsplit{`controller.plain(text}, {[}headers{]})` & Sends the plain text & returns controller `instance` \tn % Row Count 22 (+ 3) % Row 17 \SetRowColor{white} \seqsplit{`controller.proxy(opt/url)`} & Creates a proxy for the current request & returns `object` \tn % Row Count 25 (+ 3) % Row 18 \SetRowColor{LightBackground} \seqsplit{`controller.redirect(url}, {[}permament{]})` & Creates a redirection & returns controller `instance` \tn % Row Count 28 (+ 3) % Row 19 \SetRowColor{white} `controller.success({[}success{]}, {[}value{]})` & Alias for \seqsplit{`controller.json(SUCCESS(true))`} & returns controller `instance` \tn % Row Count 32 (+ 4) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{2.584 cm} x{2.508 cm} x{2.508 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Controllers (cont)}} \tn % Row 20 \SetRowColor{LightBackground} `controller.throw404({[}problem{]})` & Sends a `404 error - Not found` into response & returns controller `instance` \tn % Row Count 4 (+ 4) % Row 21 \SetRowColor{white} \seqsplit{`controller.view(name/url}, {[}model{]})` & Sends the view & returns controller `instance` or `string` \tn % Row Count 8 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.48 cm} x{5.52 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Info}} \tn % Row 0 \SetRowColor{LightBackground} Website & \{\{link="https://totaljs.com"\}\}https://totaljs.com\{\{/link\}\} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} Docs & \{\{link="https://docs.totaljs.com"\}\}https://docs.totaljs.com\{\{/link\}\} \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} Total.js Cloud & \{\{link="https://platform.totaljs.com/?open=cloud"\}\}https://platform.totaljs.com\{\{/link\}\} \tn % Row Count 10 (+ 4) % Row 3 \SetRowColor{white} Telegram Community & \{\{link="https://t.me/totaljs/1"\}\}https://t.me/totaljs\{\{/link\}\} \tn % Row Count 13 (+ 3) % Row 4 \SetRowColor{LightBackground} Blog & \{\{link="https://blog.totaljs.com"\}\}https://blog.totaljs.com\{\{/link\}\} \tn % Row Count 16 (+ 3) % Row 5 \SetRowColor{white} Tutorials & \{\{link="https://www.youtube.com/results?search\_query=Total.js"\}\}Youtube Videos\{\{/link\}\} \tn % Row Count 20 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Setup}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{`\$ sudo npm install -g total4` \newline `\$ total4 create empty myapp`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Create an empty project from template. \newline To list available commands: `\$ total4 help` \newline To list available templates: `\$ total4 templates` \newline To create from template: `\$ total4 create \textless{}template\_name\textgreater{} \textless{}path/to/empty/folder\textgreater{}`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Start Script}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{// index.js \newline var opt = \{\}; \newline opt.port = 5000; \newline \newline require('total4/debug')(opt);} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\{\{popup="https://docs.totaljs.com/total4/6b8ac001nf51c/"\}\}Read more `options` in docs \{\{/popup\}\}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.204 cm} x{2.964 cm} x{2.432 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{\$ (delegate)}} \tn % Row 0 \SetRowColor{LightBackground} `\$.body` & Returns body data from the request & returns `object` \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \seqsplit{`\$.controller`} & Contains s current instance of `Controller` & returns controller `instance` \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} `\$.files` & Returns list of uploaded files & returns `Array HttpFile` \tn % Row Count 8 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{`\$.headers`} & Returns current request headers & returns `object` \tn % Row Count 11 (+ 3) % Row 4 \SetRowColor{LightBackground} `\$.id` & Returns the value of the first parsed dynamic parameter & returns `string` \tn % Row Count 15 (+ 4) % Row 5 \SetRowColor{white} `\$.ip` & Returns IP address form the Request & returns `string` \tn % Row Count 18 (+ 3) % Row 6 \SetRowColor{LightBackground} \seqsplit{`\$.language`} & Returns parsed language from the Request & returns `String` \tn % Row Count 21 (+ 3) % Row 7 \SetRowColor{white} `\$.model` & Returns the current model according to the `Schema` & returns `object` \tn % Row Count 25 (+ 4) % Row 8 \SetRowColor{LightBackground} `\$.params` & Returns parsed dynamic parameters from URL & returns `object` \tn % Row Count 28 (+ 3) % Row 9 \SetRowColor{white} `\$.req` & Returns the current Request instance & returns `Request` \tn % Row Count 31 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{2.204 cm} x{2.964 cm} x{2.432 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{\$ (delegate) (cont)}} \tn % Row 10 \SetRowColor{LightBackground} `\$.res` & Returns the current Response instance & returns `Response` \tn % Row Count 3 (+ 3) % Row 11 \SetRowColor{white} `\$.user` & Returns `user` instance from the Request & returns `object` \tn % Row Count 6 (+ 3) % Row 12 \SetRowColor{LightBackground} \seqsplit{`\$.action(schema}, {[}data{]})` & This method is an alias fron the `CALL()` method & returns `Caller` \tn % Row Count 10 (+ 4) % Row 13 \SetRowColor{white} `\$.callback({[}error{]}, {[}value{]})` & Performs a callback & returns `Function` \tn % Row Count 13 (+ 3) % Row 14 \SetRowColor{LightBackground} `\$.done({[}arg{]})` & It wraps `\$.success()` and `\$.invalid()` method into the one function & returns \seqsplit{`Function(err}, response)` \tn % Row Count 18 (+ 5) % Row 15 \SetRowColor{white} \seqsplit{`\$.invalid(name}, {[}error{]})` & This method appends an `Error` to `ErrorBuilder` & returns \seqsplit{`ErrorBuilder`} \tn % Row Count 22 (+ 4) % Row 16 \SetRowColor{LightBackground} \seqsplit{`\$.redirect(url)`} & Performs redirect directly from the operation & returns `Function` \tn % Row Count 25 (+ 3) % Row 17 \SetRowColor{white} \$.success({[}is{]}, {[}value{]}) & This method returns preddefind success object & returns `\{ success: true \}` \tn % Row Count 28 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{\{\{popup="https://docs.totaljs.com/total4/40d14001kg51c/"\}\}Read more in docs\{\{/popup\}\}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Project Structure (MVC)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{8.4cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/louis-bertson_1680689982_ProjectStructure.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Total.js project contains a simple directory structure, and all directories are optional. You can choose what you want to use and when. \{\{popup="https://docs.totaljs.com/total4/40d60001cf51c/"\}\}Read more in docs\{\{/popup\}\}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.84 cm} x{4.16 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Schemas}} \tn % Row 0 \SetRowColor{LightBackground} `schemas.fields` & Returns all fields names from the schema \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{`schemas.define(name}, type)` & Defines the fields for the current entity \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \seqsplit{`schemas.action(name}, options)` & Registers a new schema action \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} action `options` & Options for registering new schema action \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} `options.name \{String\}` & (optional), a human readable action name \tn % Row Count 12 (+ 2) % Row 5 \SetRowColor{white} `options.params \{String\}` & (optional), a parameter for the schema \tn % Row Count 14 (+ 2) % Row 6 \SetRowColor{LightBackground} `options.query \{String\}` & (optional), query arguments for the schema \tn % Row Count 17 (+ 3) % Row 7 \SetRowColor{white} `options.input \{String\}` & (optional), input data schema \tn % Row Count 19 (+ 2) % Row 8 \SetRowColor{LightBackground} `options.action \{Function(\$, model)\}` & (required), a function that will be executed \tn % Row Count 22 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\bf{Schemas}} are one of the most used parts of the Total.js framework. Schemas offer you full control over incoming data.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}