Renderer class.

Hierarchy

  • Renderer

Constructors

Properties

_viewIndex: undefined | ViewIndex = undefined
autoCompress: boolean = true

Try to negotiate compression for dynamically generated response content and gzip compress it automatically.

defaultEngine: string = 'tmpl'

The default template engine to use for rendering in cases where auto-detection doesn't work, like for inline templates, defaults to tmpl.

defaultFormat: string = 'html'

The default format to render if format is not set, defaults to html. Note that changing the default away from html is not recommended, as it has the potential to break, for example, plugins with bundled templates.

engines: Record<string, ViewEngine> = {}

Template engines.

minCompressSize: number = 860

Minimum output size in bytes required for compression to be used if enabled, defaults to 860.

viewPaths: string[] = ...

Directories to look for templates in, first one has the highest precedence.

Methods

  • Parameters

    Returns Promise<null | EngineResult>

  • Parameters

    Returns Promise<null | EngineResult>

  • Register a template engine.

    Parameters

    • name: string
    • engine: ViewEngine

    Returns Renderer

  • Find a view for render parameters.

    Parameters

    Returns null | ViewSuggestion

    Example

    // Find path to JSON view
    const suggestion = renderer.findView({view: 'foo', 'format': 'json'});
    const {path} = suggestion;
  • Render output through one of the template engines.

    Parameters

    Returns Promise<null | EngineResult>

  • Finalize dynamically generated response content and compress it if possible.

    Parameters

    • ctx: MojoContext
    • result: EngineResult
    • options: {
          status?: number;
      }
      • Optional status?: number

    Returns Promise<boolean>

  • Prepare views for rendering.

    Returns Promise<void>

Generated using TypeDoc