-
Notifications
You must be signed in to change notification settings - Fork 11
ParserOptions
When parsing and executing a new Template, you have to set all your related options and the template in a ParserOptions
object. The object controls everything that is important for your Template.
It is no longer recommanded to create a ParserOptions object directly but to create one with the ParserOptionsBuilder. Although the ParserOptions object will remain in code it should not be used directly. Therefor this documentation will remain relevant.
The ParserOptions
and all property types implement ISealed
to prevent changes to the ParserOptions
while the Parser
is running. When for the first time a ParserOptions
is used by a Parser
the options are sealed to prevent changes. I you try to change any property of an ParserOptions
object when its already sealed, an InvalidOperationException
is thrown.
The partials store is used to supply external partials to a template.
All partial stores must implement the IPartialStore
or can implement the IAsyncPartialsStore
for an async interface.
Note: when implementing the
IAsyncPartialsStore
you do not have to actually implement the methods fromIPartialStore
but only its async counterparts
The morestachio Lib provides some default implementations:
An simple implementation that stores compiled partials in a Key-Value structure in memory via the DefaultPartialsStore.Partials
property.
This partial store sources its partials directly from disk.
See: https://github.com/JPVenson/morestachio/wiki/Templates-Partials#file-backed-partial-store
Allows you to use more than one Partial store by chaining them together and searching in each store for a matching partial.
This property is used to add custom tags and blocks to your template. (See https://github.com/JPVenson/morestachio/wiki/Custom-Tags)
When you have created your custom DocumentItem
add them to this list and they will become available for use in your template.
You can also provide a custom implementation of the ICustomDocumentList
to add a custom lookup for your DocumentItem
s
This is experimental and should stay at false
See: https://github.com/JPVenson/morestachio/wiki/How-to-supply-Values
The ParserOptions.CultureInfo
property can be set to provide a culture different from the system/app culture morestachio is running in. It is used to convert objects into strings and is especially important when formatting numbers.
This event is raised during rendering when a expression is set that cannot be resolved.
See: https://github.com/JPVenson/morestachio/wiki/Formatter
The maximum depth for nesting partials.
See: https://github.com/JPVenson/morestachio/wiki/Templates-Partials
This is experimental and should stay at ScopingBehavior.ScopeAnyway
The mode on how to react when the ParserOptions.PartialStackSize
is exceeded.
See: https://github.com/JPVenson/morestachio/wiki/Templates-Partials
The mode on how to react when a called formatter does not exist and no formatter is matching the provided arguments.
-
UnmatchedFormatterBehavior.Null
: When set toNull
, the result of an formatter call that cannot be resolved is always a null value -
UnmatchedFormatterBehavior.ParentValue
: When set toParentValue
the result will be the last value that could been resolved
As the name suggests, this controls how tags that are nether build-in tags nor resolved by ParserOptions.CustomDocumentItemProviders
are handled.
The UnmatchedTagBehavior
is an flag enum so you can provide multiple options.
-
UnmatchedTagBehavior.ThrowError
: An error is added to theMorestachioDocumentInfo.Errors
collection when parsed -
UnmatchedTagBehavior.LogWarning
: If anParserOptions.Logger
is set, an log entry is written with the LogLevelWarning
-
UnmatchedTagBehavior.Output
: The tag is rendered to the output as is. (this will of course not happen whenUnmatchedTagBehavior.ThrowError
is also present) -
UnmatchedTagBehavior.Ignore
: This flag only works if present alone. If any other Flag is present, the other flag takes priority over theIgnore
flag
When set to anything else then TimeSpan.Zero
the Rendering will abort after the set time with a TimeoutException
.
For most cases, Morestachio assumes you have your Template present in memory as a String. If you want to provide templates from other sources like network streams, you can create your own ITemplateContainer
and provide your own set of TokenMatch
. The default constructor of the ParserOptions
does use a declare overloads for string
templates but also provides constructores for use with ITemplateContainer
.
See: https://github.com/JPVenson/morestachio/wiki/Keywords#path-syntax
When set to anything else then 0, the Renderer will enforce the exact number of bytes to be not exceeded.
The StreamFactory
is responsible for providing output Streams to the renderer.
The ByteCounterFactory
provides three Delegates:
The ByteCounterFactory.Output
property should provide the target stream where the final template is written to. If you want to write to a FileSystem you should provide a FileStream
This is WIP design and should by now always return a new MemoryStream
As morestachio can enforce strict size limitations, this should return a wrapper for your ByteCounterFactory.Output
that implements IByteCounterStream
.
The encoding used to write its string contents during rendering to the IByteCounterStream
Can be set to log events both from the Morestachio framework and you template via the Logger Formatters.
See: https://github.com/JPVenson/morestachio/wiki/Predefined-Formatter#class-LoggingFormatter
The subtitution value for c# null
values when rendered to the output.
See: https://github.com/JPVenson/morestachio/wiki/Predefined-Formatter#class-LoggingFormatter
When set to true, this disables the Build-In support for Dictionary<string, object>
handling.
See: https://github.com/JPVenson/morestachio/wiki/How-to-supply-Values#parseroptionshandledictionaryasobject
Creates a new ParserOptions object containing all data and references from the original
Whenever a ContextObject is needed during rendering, this method is invoked. When overwritten you can supply your own ContextObjects with custom behavior.