Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "containers"

Index

Type aliases

FilterFunction

FilterFunction: (str: string) => any | Promise<any>

Type declaration

    • (str: string): any | Promise<any>
    • Parameters

      • str: string

      Returns any | Promise<any>

HelperFunction

HelperFunction: (content: HelperContent, blocks: Array<HelperBlock>, config: SqrlConfig) => string | Promise<string>

Type declaration

Variables

filters

filters: Cacher<(str: string) => any | Promise<any>> = new Cacher<FilterFunction>({ e: XMLEscape })

helpers

helpers: Cacher<(content: HelperContent, blocks: Array<HelperBlock>, config: SqrlConfig) => string | Promise<string>> = new Cacher<HelperFunction>({each: function (content: HelperContent, blocks: Array<HelperBlock>) {var res = ''var arr = content.params[0]errWithBlocksOrFilters('each', blocks, false)if (content.async) {return new Promise(function (resolve) {asyncArrLoop(arr, 0, content.exec, res, resolve)})} else {for (var i = 0; i < arr.length; i++) {res += content.exec(arr[i], i)}return res}},foreach: function (content: HelperContent, blocks: Array<HelperBlock>) {var obj = content.params[0]errWithBlocksOrFilters('foreach', blocks, false)if (content.async) {return new Promise(function (resolve) {asyncObjLoop(obj, Object.keys(obj), 0, content.exec, '', resolve)})} else {var res = ''for (var key in obj) {if (!hasOwnProp(obj, key)) continueres += content.exec(key, obj[key]) // todo: check on order}return res}},include: function (content: IncludeHelperContent,blocks: Array<HelperBlock>,config: SqrlConfig): string {errWithBlocksOrFilters('include', blocks, false)var template = config.storage.templates.get(content.params[0])if (!template) {throw SqrlErr('Could not fetch template "' + content.params[0] + '"')}return template(content.params[1], config)} as HelperFunction,extends: function (content: IncludeHelperContent,blocks: Array<HelperBlock>,config: SqrlConfig): string {var data: GenericData = content.params[1] || {}data.content = content.exec()for (var i = 0; i < blocks.length; i++) {var currentBlock = blocks[i]data[currentBlock.name] = currentBlock.exec()}var template = config.storage.templates.get(content.params[0])if (!template) {throw SqrlErr('Could not fetch template "' + content.params[0] + '"')}return template(data, config)} as HelperFunction,useScope: function (content: HelperContent, blocks: Array<HelperBlock>): string {errWithBlocksOrFilters('useScope', blocks, false)return content.exec(content.params[0])} as HelperFunction})

nativeHelpers

nativeHelpers: Cacher<Function> = new Cacher<Function>({if: function (buffer: ParentTemplateObject, env: SqrlConfig) {errWithBlocksOrFilters('if', false, buffer.f, true)var returnStr = 'if(' + buffer.p + '){' + compileScope(buffer.d, env) + '}'if (buffer.b) {for (var i = 0; i < buffer.b.length; i++) {var currentBlock = buffer.b[i]if (currentBlock.n === 'else') {returnStr += 'else{' + compileScope(currentBlock.d, env) + '}'} else if (currentBlock.n === 'elif') {returnStr += 'else if(' + currentBlock.p + '){' + compileScope(currentBlock.d, env) + '}'}}}return returnStr},try: function (buffer: ParentTemplateObject, env: SqrlConfig) {errWithBlocksOrFilters('try', false, buffer.f, true)if (!buffer.b || buffer.b.length !== 1 || buffer.b[0].n !== 'catch') {throw SqrlErr("native helper 'try' only accepts 1 block, 'catch'")}var returnStr = 'try{' + compileScope(buffer.d, env) + '}'var currentBlock = buffer.b[0]returnStr +='catch' +(currentBlock.res ? '(' + currentBlock.res + ')' : '') +'{' +compileScope(currentBlock.d, env) +'}'return returnStr},block: function (buffer: ParentTemplateObject, env: SqrlConfig) {errWithBlocksOrFilters('block', buffer.b, buffer.f, true)var returnStr ='if(!' +env.varName +'[' +buffer.p +']){tR+=(' +compileScopeIntoFunction(buffer.d, '', env) +')()}else{tR+=' +env.varName +'[' +buffer.p +']}'return returnStr}})

templates

templates: Cacher<(data: object, config: SqrlConfig, cb?: CallbackFn) => string> = new Cacher<TemplateFunction>({})

Functions

XMLEscape

  • XMLEscape(str: unknown): string

asyncArrLoop

  • asyncArrLoop(arr: Array<any>, index: number, fn: Function, res: string, cb: Function): void
  • Parameters

    • arr: Array<any>
    • index: number
    • fn: Function
    • res: string
    • cb: Function

    Returns void

asyncObjLoop

  • asyncObjLoop(obj: {}, keys: Array<string>, index: number, fn: Function, res: string, cb: Function): void
  • Parameters

    • obj: {}
      • [index: string]: any
    • keys: Array<string>
    • index: number
    • fn: Function
    • res: string
    • cb: Function

    Returns void

errWithBlocksOrFilters

  • errWithBlocksOrFilters(name: string, blocks: Array<any> | false, filters: Array<any> | false, native?: undefined | false | true): void
  • Parameters

    • name: string
    • blocks: Array<any> | false
    • filters: Array<any> | false
    • Optional native: undefined | false | true

    Returns void

replaceChar

  • replaceChar(s: string): string

Object literals

escMap

escMap: object

"

": "&quot;" = "&quot;"

&

&: "&amp;" = "&amp;"

'

': "&#39;" = "&#39;"

<

<: "&lt;" = "&lt;"

>

>: "&gt;" = "&gt;"

Generated using TypeDoc