Runjucks
    Preparing search index...

    Class Environment

    Index

    Constructors

    Methods

    • Registers an async filter (input, ...args) => any. The function is called synchronously on the main thread during render, but registered as an async filter so it's available in renderStringAsync / renderTemplateAsync.

      Parameters

      • name: string
      • func: unknown

      Returns void

    • Registers an async global callable (...args) => any.

      Parameters

      • name: string
      • func: unknown

      Returns void

    • Custom tag extension (Nunjucks addExtension): tags, optional blocks map (opening tag → end tag name), and process(context, args, body)body is null for simple tags.

      Parameters

      • extensionName: string
      • tags: string[]
      • blocks: Record<string, string> | null | undefined
      • process: unknown

      Returns void

    • Registers (input, ...args) => any. Overrides a built-in filter with the same name.

      Parameters

      • name: string
      • func: unknown

      Returns void

    • Registers a global: JSON-serializable value, or a JavaScript function invoked for {{ name(...) }} (Nunjucks-style keyword args as a trailing object). See NUNJUCKS_PARITY.md (P1).

      Parameters

      • name: string
      • value: unknown

      Returns void

    • Registers (value, ...args) => boolean (truthy return) for is tests and for select / reject. Built-in tests (odd, even, …) take precedence over the same name.

      Parameters

      • name: string
      • func: unknown

      Returns void

    • Subset of Nunjucks configure: autoescape (truthy/falsy coercion like Nunjucks), dev, throwOnUndefined, trimBlocks, lstripBlocks, and tags are applied.

      Parameters

      Returns void

    • Returns an introspection-only descriptor for a registered extension (tags + block end tags).

      Parameters

      • name: string

      Returns ExtensionDescriptor | null

    • Loads a named template from this environment’s loader (same idea as Nunjucks getTemplate).

      Parameters

      • name: string
      • OptionaleagerCompile: boolean | null

      Returns Template

    • Returns whether a custom extension with this name is registered (Nunjucks hasExtension).

      Parameters

      • name: string

      Returns boolean

    • Clears parse caches for named templates and inline renderString / Template sources (Nunjucks invalidateCache).

      Returns void

    • Unregisters a custom extension by name (Nunjucks removeExtension). Returns true if it existed.

      Parameters

      • name: string

      Returns boolean

    • Renders with this environment. Env is required so custom filters can call back into JavaScript synchronously.

      Parameters

      • template: string
      • context: any

      Returns string

    • Async render of an inline template string. Returns a Promise<string>.

      Async render of an inline template string. Returns a Promise<string>.

      Supports async-only tags (asyncEach, asyncAll, ifAsync) and async filters/globals.

      Implementation note: Rendering executes synchronously on the calling thread (the Node.js main thread) via a current-thread tokio runtime. The result is wrapped in an already-resolved/rejected Promise. This matches the Nunjucks renderString callback API surface but does not yield the event loop during render. This is an intentional trade-off: the async renderer's future holds &mut borrows that are !Send, preventing off-thread execution. True non-blocking rendering would require an Arc<Mutex<...>>-based state design in a future major version.

      Parameters

      • template: string
      • context: any

      Returns Promise<string>

    • Same as [render_string], but context is a JSON string (see [render_string_from_json]).

      Parameters

      • template: string
      • contextJson: string

      Returns string

    • Renders a named template from the map set via [set_template_map].

      Parameters

      • name: string
      • context: any

      Returns string

    • Async render of a named template. Returns a Promise<string>. Same blocking-then-Promise-wrap behavior as [render_string_async].

      Parameters

      • name: string
      • context: any

      Returns Promise<string>

    • Parameters

      • enabled: boolean

      Returns void

    • Parameters

      • enabled: boolean

      Returns void

    • Sync callback (name: string) => string | null | { src: string }. null / undefined JSON as null means template not found. Replaces any previous loader (same as setTemplateMap / setLoaderRoot). Does not use the named parse cache per key (sources may change arbitrarily).

      Parameters

      • callback: unknown

      Returns void

    • Loads named templates from a directory on disk (relative paths under root). Replaces any previous loader. See [runjucks_core::FileSystemLoader].

      Parameters

      • path: string

      Returns void

    • Fixes the PRNG used by | random for reproducible tests (omit / pass undefined to use a fresh non-deterministic seed per render).

      Parameters

      • Optionalseed: number | null

      Returns void

    • Sets an in-memory template map (name → source). Enables renderTemplate, {% include %}, {% extends %}, etc.

      Parameters

      • map: Record<string, string>

      Returns void