C# Class Scriban.TemplateContext

The template context contains the state of the page, the model.
ファイルを表示 Open project: lunet-io/scriban Class Usage Examples

Private Properties

Property Type Description
EnterFunction void
EnterLoop void
ExitFunction void
ExitLoop void
GetListAccessor IListAccessor
GetOrSetValue object
GetStoreForSet IEnumerable
GetValueInternal object
PopVariableScope void
PushVariableScope void
StepLoop bool

Public Methods

Method Description
Evaluate ( ScriptNode scriptNode ) : object

Evaluates the specified script node.

Result is set to null when calling directly this method.

Evaluate ( ScriptNode scriptNode, bool aliasReturnedFunction ) : object

Evaluates the specified script node.

Result is set to null when calling directly this method.

GetDefaultBuiltinObject ( ) : ScriptObject

Gets a ScriptObject with all default builtins registered.

GetMemberAccessor ( object target ) : IMemberAccessor

Gets the member accessor for the specified object.

GetValue ( ScriptExpression target ) : object

Gets the value from the specified expression using the current ScriptObject bound to the model context.

PopGlobal ( ) : IScriptObject

Pops the previous model context.

PopOutput ( ) : string

Pops a previous output.

PopSourceFile ( ) : string

Pops the source file being executed.

PushGlobal ( IScriptObject scriptObject ) : void

Pushes a new model context accessible to the template.

PushOutput ( ) : void

Pushes a new output used for rendering the current template while keeping the previous output.

PushSourceFile ( string sourceFile ) : void

Pushes the source file path being executed. This should have enough information so that template loading/include can work correctly.

SetReadOnly ( ScriptVariable variable, bool isReadOnly = true ) : void

Sets the variable to read only.

This will not throw an exception if a previous variable was readonly.

SetValue ( ScriptExpression target, object value ) : void

Sets the target expression with the specified value.

SetValue ( ScriptVariable variable, object value, bool asReadOnly ) : void

Sets the variable with the specified value.

TemplateContext ( ) : System

Initializes a new instance of the TemplateContext class.

TemplateContext ( ScriptObject builtin ) : System

Initializes a new instance of the TemplateContext class.

Write ( SourceSpan span, object textAsObject ) : void

Writes an object value to the current Output.

Write ( string text ) : void

Writes the text to the current Output

Private Methods

Method Description
EnterFunction ( ScriptNode caller ) : void
EnterLoop ( ScriptLoopStatementBase loop ) : void
ExitFunction ( ) : void
ExitLoop ( ) : void
GetListAccessor ( object target ) : IListAccessor
GetOrSetValue ( ScriptExpression targetExpression, object valueToSet, bool setter, int level ) : object
GetStoreForSet ( ScriptVariable variable ) : IEnumerable
GetValueInternal ( ScriptVariable variable ) : object
PopVariableScope ( ScriptVariableScope scope ) : void
PushVariableScope ( ScriptVariableScope scope ) : void
StepLoop ( ) : bool

Method Details

Evaluate() public method

Evaluates the specified script node.
Result is set to null when calling directly this method.
public Evaluate ( ScriptNode scriptNode ) : object
scriptNode Scriban.Runtime.ScriptNode The script node.
return object

Evaluate() public method

Evaluates the specified script node.
Result is set to null when calling directly this method.
public Evaluate ( ScriptNode scriptNode, bool aliasReturnedFunction ) : object
scriptNode Scriban.Runtime.ScriptNode The script node.
aliasReturnedFunction bool if set to true and a function would be evaluated as part of this node, return the object function without evaluating it.
return object

GetDefaultBuiltinObject() public static method

Gets a ScriptObject with all default builtins registered.
public static GetDefaultBuiltinObject ( ) : ScriptObject
return ScriptObject

GetMemberAccessor() public method

Gets the member accessor for the specified object.
public GetMemberAccessor ( object target ) : IMemberAccessor
target object The target object to get a member accessor.
return IMemberAccessor

GetValue() public method

Gets the value from the specified expression using the current ScriptObject bound to the model context.
public GetValue ( ScriptExpression target ) : object
target ScriptExpression The expression
return object

PopGlobal() public method

Pops the previous model context.
Unexpected PopGlobal() not matching a PushGlobal
public PopGlobal ( ) : IScriptObject
return IScriptObject

PopOutput() public method

Pops a previous output.
public PopOutput ( ) : string
return string

PopSourceFile() public method

Pops the source file being executed.
Cannot PopSourceFile more than PushSourceFile
public PopSourceFile ( ) : string
return string

PushGlobal() public method

Pushes a new model context accessible to the template.
public PushGlobal ( IScriptObject scriptObject ) : void
scriptObject IScriptObject The script object.
return void

PushOutput() public method

Pushes a new output used for rendering the current template while keeping the previous output.
public PushOutput ( ) : void
return void

PushSourceFile() public method

Pushes the source file path being executed. This should have enough information so that template loading/include can work correctly.
public PushSourceFile ( string sourceFile ) : void
sourceFile string The source file.
return void

SetReadOnly() public method

Sets the variable to read only.
This will not throw an exception if a previous variable was readonly.
If variable is null
public SetReadOnly ( ScriptVariable variable, bool isReadOnly = true ) : void
variable ScriptVariable The variable.
isReadOnly bool if set to true the variable will be set to readonly.
return void

SetValue() public method

Sets the target expression with the specified value.
If target is null
public SetValue ( ScriptExpression target, object value ) : void
target ScriptExpression The target expression.
value object The value.
return void

SetValue() public method

Sets the variable with the specified value.
If variable is null If an existing variable is already read-only
public SetValue ( ScriptVariable variable, object value, bool asReadOnly ) : void
variable ScriptVariable The variable.
value object The value.
asReadOnly bool if set to true the variable set will be read-only.
return void

TemplateContext() public method

Initializes a new instance of the TemplateContext class.
public TemplateContext ( ) : System
return System

TemplateContext() public method

Initializes a new instance of the TemplateContext class.
public TemplateContext ( ScriptObject builtin ) : System
builtin ScriptObject The builtin object used to expose builtin functions, default is .
return System

Write() public method

Writes an object value to the current Output.
public Write ( SourceSpan span, object textAsObject ) : void
span Scriban.Parsing.SourceSpan The span of the object to render.
textAsObject object The text as object.
return void

Write() public method

Writes the text to the current Output
public Write ( string text ) : void
text string The text.
return void