import { Root } from "./ast"; import { RenderContext } from "./context"; import { Filter } from "./filter"; import { Loader } from "./loader"; import { Parser } from "./parse"; import { Tag } from "./tag"; import { Template } from "./template"; import { Undefined } from "./undefined"; import { ContextScope } from "./types"; import { RenderStream } from "./io/output_stream"; /** * Liquid environment options. */ export type EnvironmentOptions = { /** * When `true`, render context variables will be HTML escaped before output. * @defaultValue `false` */ autoEscape?: boolean; /** * An optional object who's properties will be added to the render context * of every template rendered from this environment. * * `globals` is not copied, so updates to it after environment construction * will be visible to templates. * @defaultValue An empty `Object`. */ globals?: ContextScope; /** * A template loader. Used to load templates from a file system or database, * for example. * @defaultValue An empty `MapLoader`. */ loader?: Loader; /** * The maximum number of times a render context can be copied or extended. * This helps us guard against recursive use of the `include` or `render` * tags. * @defaultValue 30 */ maxContextDepth?: number; /** * The maximum "size" of a render context local namespace. Rather than the * number of bytes in memory a local namespace occupies, "size" is a non- * specific indication of how much a template uses the local namespace when * it is rendered, typically using the `assign` and `capture` tags. * * If `localNamespaceLimit` is `undefined` or less than 0, there is no limit. * Otherwise a `LocalNamespaceLimitError`is thrown when the namespace's size * exceeds the limit. * @defaultValue undefined */ localNamespaceLimit?: number; /** * The maximum number of loop iteration allowed before a `LoopIterationLimitError` * is thrown. * * If `loopIterationLimit` is undefined or less than 0, there is no soft limit. * @defaultValue undefined */ loopIterationLimit?: number; /** * The maximum number of bytes that can be written to a template's output * stream, per render, before an `OutputStreamLimitError` is thrown. * * If `outputStreamLimit` is undefined or less than 0, there is no soft limit. * @defaultValue undefined */ outputStreamLimit?: number; /** * The sequence of characters indicating the start of a liquid output statement. * @defaultValue `{{` */ statementStartString?: string; /** * The sequence of characters indicating the end of a liquid output statement. * @defaultValue `}}` */ statementEndString?: string; /** * When `true`, a `NoSuchFilterError` will be raised if a template attempts * to use an undefined filter. When `false`, undefined filters are silently * ignored. * @defaultValue `true` */ strictFilters?: boolean; /** * The sequence of characters indicating the start of a liquid tag. * @defaultValue `{%` */ tagStartString?: string; /** * The sequence of characters indicating the end of a liquid tag. * @defaultValue `}}` */ tagEndString?: string; /** * A function that accepts the name of a template variable name and * returns a subclass of `Undefined`. * @defaultValue A `LaxUndefined` factory function. */ undefinedFactory?: (name: string) => Undefined; /** * A factory function that will be used to create a render stream * for each template rendered from the environment. */ renderStreamFactory?: () => RenderStream; }; /** * Optional meta data and utilities for managing liquid templates. */ export type TemplateContext = { /** * A name or identifier for the template. This name will be used * in error messages. */ name?: string; /** * Extra global render context variables. Usually added by a * template loader. */ matter?: ContextScope; /** * Additional, arbitrary data that a loader can use to scope or * otherwise narrow its search space. */ loaderContext?: ContextScope; /** * A function that will return `true` if this template is up to * date, or `false` if it needs to be loaded again. */ upToDate?: () => Promise; /** * A synchronous version of `upToDate`. */ upToDateSync?: () => boolean; }; /** * Shared configuration from which templates can be loaded and parsed. * @see {@link EnvironmentOptions} */ export declare class Environment { #private; autoEscape: boolean; globals: ContextScope; loader: Loader; maxContextDepth: number; localNamespaceLimit: number; loopIterationLimit: number; private _outputStreamLimit; readonly statementStartString: string; readonly statementEndString: string; strictFilters: boolean; readonly tagStartString: string; readonly tagEndString: string; protected templateClass: typeof Template; readonly undefinedFactory: (name: string) => Undefined; renderStreamFactory: (stream?: RenderStream) => RenderStream; /** * An object mapping filter names to filter functions. */ readonly filters: { [keys: string]: Filter; }; /** * An object mapping tag names to tag implementations. */ readonly tags: { [keys: string]: Tag; }; /** * Environment constructor. * * @param options - Environment options. */ constructor({ autoEscape, globals, loader, maxContextDepth, localNamespaceLimit, loopIterationLimit, outputStreamLimit, statementStartString, statementEndString, strictFilters, tagStartString, tagEndString, undefinedFactory, renderStreamFactory, }?: EnvironmentOptions); /** * Return an environment configured with the given options. The `globals` * and `loader` options are ignored when creating implicit environments. * * @param options - Options for the implicit environment. */ static getImplicitEnvironment(options?: EnvironmentOptions): Environment; /** * Load a template using the configured template loader. * @param name - The name or identifier of the template to load. * @param globals - An optional object who's properties will be added * to the render context every time the resulting template is rendered. * @param context - A reference to the active render context, if one is * active. * @param loaderContext - Additional, arbitrary data that a loader can use * to scope or otherwise narrow its search space. * @returns A `Template` bound to this environment, ready to be rendered. * @throws `NoSuchTemplateError` if a template with the given name can not * be found. */ getTemplate(name: string, globals?: ContextScope, context?: RenderContext, loaderContext?: { [index: string]: unknown; }): Promise