@mojojs/core
Version:
Real-time web framework
77 lines (76 loc) • 2.54 kB
TypeScript
import type { MojoContext, MojoRenderOptions } from './types.js';
interface EngineResult {
format: string;
output: string | Buffer;
}
interface ViewSuggestion {
engine: string;
format: string;
path: string;
variant?: string;
}
type ViewIndex = Record<string, ViewSuggestion[]>;
interface ViewEngine {
render: (ctx: MojoContext, options: MojoRenderOptions) => Promise<Buffer>;
}
/**
* Renderer class.
*/
export declare class Renderer {
/**
* Try to negotiate compression for dynamically generated response content and gzip compress it automatically.
*/
autoCompress: boolean;
/**
* The default template engine to use for rendering in cases where auto-detection doesn't work, like for inline
* templates, defaults to `tmpl`.
*/
defaultEngine: string;
/**
* 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.
*/
defaultFormat: string;
/**
* Template engines.
*/
engines: Record<string, ViewEngine>;
/**
* Minimum output size in bytes required for compression to be used if enabled, defaults to `860`.
*/
minCompressSize: number;
/**
* Directories to look for templates in, first one has the highest precedence.
*/
viewPaths: string[];
_viewIndex: ViewIndex | undefined;
/**
* Register a template engine.
*/
addEngine(name: string, engine: ViewEngine): this;
/**
* Find a view for render parameters.
* @example
* // Find path to JSON view
* const suggestion = renderer.findView({view: 'foo', 'format': 'json'});
* const {path} = suggestion;
*/
findView(options: MojoRenderOptions): ViewSuggestion | null;
/**
* Render output through one of the template engines.
*/
render(ctx: MojoContext, options: MojoRenderOptions): Promise<EngineResult | null>;
/**
* Finalize dynamically generated response content and compress it if possible.
*/
respond(ctx: MojoContext, result: EngineResult, options: {
status?: number;
}): Promise<boolean>;
/**
* Prepare views for rendering.
*/
warmup(): Promise<void>;
_renderInline(ctx: MojoContext, options: MojoRenderOptions): Promise<EngineResult | null>;
_renderView(ctx: MojoContext, options: MojoRenderOptions): Promise<EngineResult | null>;
}
export {};