Skip to content
JPVenson edited this page Jul 7, 2022 · 2 revisions

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.

ParserOptions vs ParserOptionsBuilder

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.

ISealed

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.

PartialsStore IPartialsStore property

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 from IPartialStore but only its async counterparts

The morestachio Lib provides some default implementations:

DefaultPartialStore: IPartialStore

An simple implementation that stores compiled partials in a Key-Value structure in memory via the DefaultPartialsStore.Partials property.

FileSystemPartialStore: IAsyncPartialsStore

This partial store sources its partials directly from disk.
See: https://github.com/JPVenson/morestachio/wiki/Templates-Partials#file-backed-partial-store

PartialsStoreAggregator: IAsyncPartialsStore

Allows you to use more than one Partial store by chaining them together and searching in each store for a matching partial.

CustomDocumentItemProviders ICustomDocumentList property

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 DocumentItems

ProfileExecution bool property

This is experimental and should stay at false

ValueResolver IValueResolver property

See: https://github.com/JPVenson/morestachio/wiki/How-to-supply-Values

CultureInfo CultureInfo property

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.

UnresolvedPath InvalidPath event

This event is raised during rendering when a expression is set that cannot be resolved.

Formatters IMorestachioFormatterService property

See: https://github.com/JPVenson/morestachio/wiki/Formatter

PartialStackSize uint property

The maximum depth for nesting partials.
See: https://github.com/JPVenson/morestachio/wiki/Templates-Partials

ScopingBehavior ScopingBehavior property

This is experimental and should stay at ScopingBehavior.ScopeAnyway

StackOverflowBehavior PartialStackOverflowBehavior property

The mode on how to react when the ParserOptions.PartialStackSize is exceeded.
See: https://github.com/JPVenson/morestachio/wiki/Templates-Partials

UnmatchedFormatterBehavior UnmatchedFormatterBehavior property

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 to Null, the result of an formatter call that cannot be resolved is always a null value
  • UnmatchedFormatterBehavior.ParentValue: When set to ParentValue the result will be the last value that could been resolved

UnmatchedTagBehavior 'UnmatchedTagBehavior' property

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 the MorestachioDocumentInfo.Errors collection when parsed
  • UnmatchedTagBehavior.LogWarning: If an ParserOptions.Logger is set, an log entry is written with the LogLevel Warning
  • UnmatchedTagBehavior.Output: The tag is rendered to the output as is. (this will of course not happen when UnmatchedTagBehavior.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 the Ignore flag

Timeout Timespan property

When set to anything else then TimeSpan.Zero the Rendering will abort after the set time with a TimeoutException.

Template ITemplateContainer property

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.

DisableContentEscaping bool property

See: https://github.com/JPVenson/morestachio/wiki/Keywords#path-syntax

MaxSize long property

When set to anything else then 0, the Renderer will enforce the exact number of bytes to be not exceeded.

StreamFactory ByteCounterFactory property

The StreamFactory is responsible for providing output Streams to the renderer.
The ByteCounterFactory provides three Delegates:

Output: Func<Stream>

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

TempStream: Func<Stream>

This is WIP design and should by now always return a new MemoryStream

GetByteCounterStream: Func<ParserOptions, IByteCounterStream>

As morestachio can enforce strict size limitations, this should return a wrapper for your ByteCounterFactory.Output that implements IByteCounterStream.

Encoding Encoding property

The encoding used to write its string contents during rendering to the IByteCounterStream

Logger ILogger property

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

Null string property

The subtitution value for c# null values when rendered to the output.
See: https://github.com/JPVenson/morestachio/wiki/Predefined-Formatter#class-LoggingFormatter

HandleDictionaryAsObject bool property

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

Copy method

Creates a new ParserOptions object containing all data and references from the original

virtual CreateContextObject method

Whenever a ContextObject is needed during rendering, this method is invoked. When overwritten you can supply your own ContextObjects with custom behavior.

Clone this wiki locally