@mojojs/core
    Preparing search index...

    Class Renderer

    Renderer class.

    Index
    _viewIndex: ViewIndex | undefined = 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.

    • Register a template engine.

      Parameters

      • name: string
      • engine: ViewEngine

      Returns this

    • Find a view for render parameters.

      Parameters

      Returns ViewSuggestion | null

      // 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<EngineResult | null>

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

      Parameters

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

      Returns Promise<boolean>

    • Prepare views for rendering.

      Returns Promise<void>