js.util.LogicTemplate

Parse templates with logic [singleton].

Summary
js.util.LogicTemplateParse templates with logic [singleton].
Variables
optionsparser config
Functions
parseparse template string.
findTemplate
parser
tokenizesplit logic template to tokens
generateJSgenerate native JS from <parsedTree>
replacetemplater was written on PHP, so this function is port from it.
buildLineBuilds php or js string.
braceVaradd braces and quotes to var name
makeVariableNamemake full variable name
trimright trim
isArraycheck if obj is Array
toArraymakes array
lCasetoLowerCase wrapper
addSlasheswraps slashes with more slashes
getJSFreturn JS template function
js.util.LogicTplUnit
Functions
collectorNewCreates collectors.
collectorPushPushes element in collector
oFunction makes object from Array or pass as is if object.
lGet Object\Array length.

Variables

options

options: { braces: [ '{{', '}}' ], replaceArray: { 'and': '&&', 'or': '||', 'not': '!' }, 'checkVars': true, 'cache': true }

parser config

Functions

parse

parse: function(text,
identity)

parse template string.  Wraps parser

Parameters

texttemplate string

Return

<parsedTree>

findTemplate

findTemplate: function(text)

Parameters

textincoming string

Return

logic template item (string)

parser

parser: function(text)

Parameters

textincoming string

Return

<parsedTree>

tokenize

tokenize: function(text,
lastTID)

split logic template to tokens

Parameters

textincoming string
lastTID [optional](default: 0)

Return

<parsedTree>

generateJS

generateJS: function (identity)

generate native JS from <parsedTree>

Parameters

identity [optional]- cache identity of template.  Now not used, instead of this it just take last parsed

Return

js code

replace

replace: function(search,
replace,
subject)

templater was written on PHP, so this function is port from it.  It do one replacement of each search

Parameters

searcharray of substring to search
replacearray of substring to replace ( replaces have equal indexes to search array)
subjectstring

Return

replaced string

buildLine

buildLine: function(text,
logic,
php,
checkVars)

Builds php or js string.  It’s about access to ancestors variables.

Parameters

textvariable string
logic<logicUnit>
bool phpif true - php || js
checkVarsif true - vars would be checked for existance

Return

formatted text

braceVar

braceVar: function(aVar,
autoQuote)

add braces and quotes to var name

Parameters

aVarvariable string
bool autoQuoteif true - don’t add quotes

Return

formatted var

makeVariableName

makeVariableName: function(aVar,
php,
checkVars)

make full variable name

Parameters

aVarvariable string
bool phpif true - php || js
checkVarsif true - vars would be checked for existance

Return

formatted var name

trim

trim: function(text)

right trim

Parameters

texttext to trim

Return

right trimmed text

isArray

isArray: function(obj)

check if obj is Array

Parameters

objobject to check

Return

true if array || false

toArray

toArray: function(obj)

makes array

Parameters

objobject to check

Return

obj if is Array || [ obj ]

lCase

lCase:function(text)

toLowerCase wrapper

Parameters

texttext to lower

Return

lowered text

addSlashes

addSlashes: function(str)

wraps slashes with more slashes

Parameters

texttext to add slashes

Return

slashed text

getJSF

getJSF: function(text)

return JS template function

Parameters

texttext of logic template

Return

LogicTplUnit

js.util.LogicTplUnit

Summary
Functions
collectorNewCreates collectors.
collectorPushPushes element in collector
oFunction makes object from Array or pass as is if object.
lGet Object\Array length.

Functions

collectorNew

collectorNew: function( )

Creates collectors.  Use in tpls

this.collectorNew( 'button', 'item', 'ololo' .. )

collectorPush

collectorPush: function(name,
val)

Pushes element in collector

Parameters

namecollector name
valvalue to push
this.collectorPush( 'button', el.value )

o

o: function(a)

Function makes object from Array or pass as is if object.  Cool named function to minimize template code.

Parameters

oobject

Return

Array ? object || as is

l

Get Object\Array length.  Cool named function to minimize template code.

Parameters

oobject

Return

length

options: { braces: [ '{{', '}}' ], replaceArray: { 'and': '&&', 'or': '||', 'not': '!' }, 'checkVars': true, 'cache': true }
parser config
parse: function(text,
identity)
parse template string.
findTemplate: function(text)
parser: function(text)
tokenize: function(text,
lastTID)
split logic template to tokens
generateJS: function (identity)
generate native JS from parsedTree
replace: function(search,
replace,
subject)
templater was written on PHP, so this function is port from it.
buildLine: function(text,
logic,
php,
checkVars)
Builds php or js string.
braceVar: function(aVar,
autoQuote)
add braces and quotes to var name
makeVariableName: function(aVar,
php,
checkVars)
make full variable name
trim: function(text)
right trim
isArray: function(obj)
check if obj is Array
toArray: function(obj)
makes array
lCase:function(text)
toLowerCase wrapper
addSlashes: function(str)
wraps slashes with more slashes
getJSF: function(text)
return JS template function
collectorNew: function( )
Creates collectors.
collectorPush: function(name,
val)
Pushes element in collector
o: function(a)
Function makes object from Array or pass as is if object.
Close