UNPKG

@eggjs/view

Version:

Base view plugin for egg

49 lines (48 loc) 2.17 kB
import type { Context, EggCore } from '@eggjs/core'; import { ViewManager, type ViewManagerConfig, type RenderOptions } from './view_manager.js'; declare const RENDER: unique symbol; declare const RENDER_STRING: unique symbol; declare const GET_VIEW_ENGINE: unique symbol; declare const SET_LOCALS: unique symbol; /** * View instance for each request. * * It will find the view engine, and render it. * The view engine should be registered in {@link ViewManager}. */ export declare class ContextView { protected ctx: Context; protected app: EggCore; protected viewManager: ViewManager; protected config: ViewManagerConfig; constructor(ctx: Context); /** * Render a file by view engine * @param {String} name - the file path based on root * @param {Object} [locals] - data used by template * @param {Object} [options] - view options, you can use `options.viewEngine` to specify view engine * @return {Promise<String>} result - return a promise with a render result */ render(name: string, locals?: Record<string, any>, options?: RenderOptions): Promise<string>; /** * Render a template string by view engine * @param {String} tpl - template string * @param {Object} [locals] - data used by template * @param {Object} [options] - view options, you can use `options.viewEngine` to specify view engine * @return {Promise<String>} result - return a promise with a render result */ renderString(tpl: string, locals?: Record<string, any>, options?: RenderOptions): Promise<string>; [RENDER](name: string, locals?: Record<string, any>, options?: RenderOptions): Promise<string>; [RENDER_STRING](tpl: string, locals?: Record<string, any>, options?: RenderOptions): Promise<string>; [GET_VIEW_ENGINE](name: string): import("./view_manager.js").ViewEngine; /** * set locals for view, inject `locals.ctx`, `locals.request`, `locals.helper` * @private */ [SET_LOCALS](locals?: Record<string, any>): { ctx: Context; request: import("@eggjs/core").Request; helper: import("egg").Helper; } & Record<string, any>; } export {};