Templates class

LG entrance, including properties that LG file has, and evaluate functions.

Constructors

Templates(Template[], TemplateImport[], Diagnostic[], Templates[], string, string, ExpressionParser, ImportResolverDelegate, string[], string, Record<string, Templates>)

Creates a new instance of the Templates class.

Properties

allDiagnostics

Gets all diagnostics from current lg file and reference lg files.

allTemplates

Gets all templates from current lg file and reference lg files.

content

LG content.

diagnostics

diagnostics.

enableFromFile

Indicates whether fromFile is allowed in LG templates.

expressionParser

expression parser.

id

Id of the lg resource.

importResolver

Delegate for resolving resource id of imported lg file.

imports

import elements that this LG file contains directly.

inlineTemplateIdPrefix

Temp Template ID for inline content.

lgOptions

Gets the evluation options for the current LG file. @returns A value indicating whether the options when evaluating LG templates.

namedReferences

Map from import alias to templates.

namespace

Gets the namespace to register for the current LG file. @returns A string value representing the namespace to register for the current LG file.

options

LG file options.

references

all references that this LG file has from Imports otice: reference includs all child imports from the lg file, not only the children belong to this lgfile directly. so, reference count may >= imports count.

source

Source of the lg resource. Full path for lg file.

Methods

addTemplate(string, string[], string)

Add a new template and return LG file.

analyzeTemplate(string, AnalyzerOptions)

Analyze a template to get the static analyzer results including variables and template references.

deleteTemplate(string)

Delete an exist template.

evaluate(string, object, EvaluationOptions)

Evaluate a template with given name and scope.

evaluateText(string, object, EvaluationOptions)

Use to evaluate an inline template str.

expandTemplate(string, object, EvaluationOptions)

Expand a template with given name and scope. Return all possible responses instead of random one.

parseFile(string, ImportResolverDelegate, ExpressionParser)

Parse a file and return LG file.

parseResource(LGResource, ImportResolverDelegate, ExpressionParser)

Parser to turn lg content into a Templates.

parseText(string, string, ImportResolverDelegate, ExpressionParser)

Parser to turn lg content into a Templates.

push(Template[])

Appends 1 or more templates to the collection.

toArray()

Gets the collection of templates.

toString()

Returns a string representation of a Templates content.

updateTemplate(string, string, string[], string)

Update a template and return LG file.

Constructor Details

Templates(Template[], TemplateImport[], Diagnostic[], Templates[], string, string, ExpressionParser, ImportResolverDelegate, string[], string, Record<string, Templates>)

Creates a new instance of the Templates class.

new Templates(items?: Template[], imports?: TemplateImport[], diagnostics?: Diagnostic[], references?: Templates[], content?: string, id?: string, expressionParser?: ExpressionParser, importResolverDelegate?: ImportResolverDelegate, options?: string[], source?: string, namedReferences?: Record<string, Templates>)

Parameters

items

Template[]

Optional. List of Template instances.

imports

TemplateImport[]

Optional. List of TemplateImport instances.

diagnostics

Diagnostic[]

Optional. List of Diagnostic instances.

references

Templates[]

Optional. List of Templates instances.

content

string

Optional. Content of the current Templates instance.

id

string

Optional. Id of the current Templates instance.

expressionParser

ExpressionParser

Optional. ExpressionParser to parse the expressions in the content.

importResolverDelegate
ImportResolverDelegate

Optional. Resolver to resolve LG import id to template text.

options

string[]

Optional. List of strings representing the options during evaluation of the templates.

source

string

Optional. Templates source.

namedReferences

Record<string, Templates>

Optional. eferences that imported with the "as" syntax,for example: import as myAlias.

Property Details

allDiagnostics

Gets all diagnostics from current lg file and reference lg files.

Diagnostic[] allDiagnostics

Property Value

All diagnostics from current lg file and reference lg files.

allTemplates

Gets all templates from current lg file and reference lg files.

Template[] allTemplates

Property Value

All templates from current lg file and reference lg files.

content

LG content.

content: string

Property Value

string

diagnostics

diagnostics.

diagnostics: Diagnostic[]

Property Value

enableFromFile

Indicates whether fromFile is allowed in LG templates.

static enableFromFile: boolean = false

Property Value

boolean

expressionParser

expression parser.

expressionParser: ExpressionParser

Property Value

ExpressionParser

id

Id of the lg resource.

id: string

Property Value

string

importResolver

Delegate for resolving resource id of imported lg file.

importResolver: ImportResolverDelegate

Property Value

imports

import elements that this LG file contains directly.

imports: TemplateImport[]

Property Value

inlineTemplateIdPrefix

Temp Template ID for inline content.

static inlineTemplateIdPrefix: string = "__temp__"

Property Value

string

lgOptions

Gets the evluation options for the current LG file. @returns A value indicating whether the options when evaluating LG templates.

EvaluationOptions lgOptions

Property Value

namedReferences

Map from import alias to templates.

namedReferences: Record<string, Templates>

Property Value

Record<string, Templates>

namespace

Gets the namespace to register for the current LG file. @returns A string value representing the namespace to register for the current LG file.

string namespace

Property Value

string

options

LG file options.

options: string[]

Property Value

string[]

references

all references that this LG file has from Imports otice: reference includs all child imports from the lg file, not only the children belong to this lgfile directly. so, reference count may >= imports count.

references: Templates[]

Property Value

source

Source of the lg resource. Full path for lg file.

source: string

Property Value

string

Method Details

addTemplate(string, string[], string)

Add a new template and return LG file.

function addTemplate(templateName: string, parameters: string[], templateBody: string): Templates

Parameters

templateName

string

New template name.

parameters

string[]

New params.

templateBody

string

New template body.

Returns

New lg file.

analyzeTemplate(string, AnalyzerOptions)

Analyze a template to get the static analyzer results including variables and template references.

function analyzeTemplate(templateName: string, analyzerOptions?: AnalyzerOptions): AnalyzerResult

Parameters

templateName

string

Template name to be evaluated.

analyzerOptions
AnalyzerOptions

Options for analyzing template.

Returns

Analyzer result.

deleteTemplate(string)

Delete an exist template.

function deleteTemplate(templateName: string): Templates

Parameters

templateName

string

Which template should delete.

Returns

Return the new lg file.

evaluate(string, object, EvaluationOptions)

Evaluate a template with given name and scope.

function evaluate(templateName: string, scope?: object, opt: EvaluationOptions): any

Parameters

templateName

string

Template name to be evaluated.

scope

object

The state visible in the evaluation.

opt
EvaluationOptions

EvaluationOptions in evaluating a template.

Returns

any

Evaluate result.

evaluateText(string, object, EvaluationOptions)

Use to evaluate an inline template str.

function evaluateText(inlineStr: string, scope?: object, opt: EvaluationOptions): any

Parameters

inlineStr

string

Inline string which will be evaluated.

scope

object

Scope object or JToken.

opt
EvaluationOptions

EvaluationOptions in evaluating a template.

Returns

any

Evaluated result object.

expandTemplate(string, object, EvaluationOptions)

Expand a template with given name and scope. Return all possible responses instead of random one.

function expandTemplate(templateName: string, scope?: object, opt: EvaluationOptions): any[]

Parameters

templateName

string

Template name to be evaluated.

scope

object

The state visible in the evaluation.

opt
EvaluationOptions

EvaluationOptions in expanding a template.

Returns

any[]

Expand result.

parseFile(string, ImportResolverDelegate, ExpressionParser)

Parse a file and return LG file.

static function parseFile(filePath: string, importResolver?: ImportResolverDelegate, expressionParser?: ExpressionParser): Templates

Parameters

filePath

string

LG absolute file path..

importResolver
ImportResolverDelegate

Resolver to resolve LG import id to template text.

expressionParser

ExpressionParser

Expression parser for evaluating expressions.

Returns

New lg file.

parseResource(LGResource, ImportResolverDelegate, ExpressionParser)

Parser to turn lg content into a Templates.

static function parseResource(resource: LGResource, importResolver?: ImportResolverDelegate, expressionParser?: ExpressionParser): Templates

Parameters

resource
LGResource

LG resource.

importResolver
ImportResolverDelegate

Resolver to resolve LG import id to template text.

expressionParser

ExpressionParser

Expression parser for evaluating expressions.

Returns

Entity.

parseText(string, string, ImportResolverDelegate, ExpressionParser)

Warning

This API is now deprecated.

This method will soon be deprecated. Use ParseResource instead.

Parser to turn lg content into a Templates.

static function parseText(content: string, id: string, importResolver?: ImportResolverDelegate, expressionParser?: ExpressionParser): Templates

Parameters

content

string

Text content contains lg templates.

id

string

Id is the identifier of content. If importResolver is undefined, id must be a full path string.

importResolver
ImportResolverDelegate

Resolver to resolve LG import id to template text.

expressionParser

ExpressionParser

Expression parser for evaluating expressions.

Returns

Entity.

push(Template[])

Appends 1 or more templates to the collection.

function push(args: Template[])

Parameters

args

Template[]

List of templates to add.

toArray()

Gets the collection of templates.

function toArray(): Template[]

Returns

A reference to the internal list of collection templates.

toString()

Returns a string representation of a Templates content.

function toString(): string

Returns

string

A string representation of a Templates content.

updateTemplate(string, string, string[], string)

Update a template and return LG file.

function updateTemplate(templateName: string, newTemplateName: string, parameters: string[], templateBody: string): Templates

Parameters

templateName

string

Orignial template name.

newTemplateName

string

New template name.

parameters

string[]

New params.

templateBody

string

New template body.

Returns

New lg file.