/** * Jinja-Bun: Jinja2/Django Template Language engine for Bun/JavaScript * * 100% compatible with Django Template Language (DTL) * High performance template rendering for Bun runtime * * @example * ```typescript * import { Environment } from 'jinja-bun' * * const env = new Environment({ * templates: './templates', * autoescape: true, * }) * * const html = await env.render('page.html', { * title: 'Hello', * items: [1, 2, 3], * }) * ``` */ import { TemplateNode } from './parser'; import { FilterFunction } from './filters'; import { CompileOptions } from './compiler'; import type { PanelOptions } from './debug'; export interface EnvironmentOptions { /** Template directory path */ templates?: string; /** Auto-escape HTML (default: true) */ autoescape?: boolean; /** Custom filters */ filters?: Record; /** Global variables available in all templates */ globals?: Record; /** URL resolver for {% url %} tag */ urlResolver?: (name: string, args: any[], kwargs: Record) => string; /** Static file resolver for {% static %} tag */ staticResolver?: (path: string) => string; /** Cache compiled templates (default: true) */ cache?: boolean; /** Maximum number of templates to cache (LRU eviction, default: 100) */ cacheMaxSize?: number; /** Template file extensions to try (default: ['.html', '.jinja', '.jinja2']) */ extensions?: string[]; /** Enable debug panel injection (default: false) */ debug?: boolean; /** Debug panel options */ debugOptions?: PanelOptions; /** Timezone for date/time operations (e.g., 'Europe/Rome', 'UTC', 'America/New_York') */ timezone?: string; } export interface CacheStats { /** Number of templates currently in cache */ size: number; /** Maximum cache size */ maxSize: number; /** Number of cache hits */ hits: number; /** Number of cache misses */ misses: number; /** Hit rate percentage */ hitRate: number; } export declare class Environment { private options; private runtime; private templateCache; private routes; private cacheHits; private cacheMisses; constructor(options?: EnvironmentOptions); /** * Render a template file with the given context */ render(templateName: string, context?: Record): Promise; /** * Render a template string directly */ renderString(source: string, context?: Record): Promise; /** * Internal: Render with debug panel */ private renderWithDebug; /** * Internal: Render string with debug panel */ private renderStringWithDebug; /** * Internal: Inject debug panel into HTML */ private injectDebugPanel; /** * Compile a template string to AST (useful for caching) */ compile(source: string): TemplateNode; /** * Load and compile a template file (with LRU cache) */ loadTemplate(templateName: string): Promise; /** * Clear the template cache and reset stats */ clearCache(): void; /** * Get current cache size */ cacheSize(): number; /** * Get cache statistics */ cacheStats(): CacheStats; /** * Add a custom filter */ addFilter(name: string, fn: FilterFunction): void; /** * Add a global variable */ addGlobal(name: string, value: any): void; /** * Register a URL route for {% url %} tag (Django-style) */ addUrl(name: string, pattern: string): void; /** * Register multiple URL routes */ addUrls(routes: Record): void; private resolveTemplatePath; private defaultUrlResolver; private defaultStaticResolver; } /** * Quick render function for simple use cases */ export declare function render(source: string, context?: Record, options?: EnvironmentOptions): Promise; /** * Create a template function (like Jinja2's Template class) */ export declare function Template(source: string, options?: EnvironmentOptions): { render(context?: Record): Promise; }; /** * Compile a template to an optimized JavaScript function (AOT mode) * Returns a sync function that is 10-50x faster than runtime rendering * * Note: This function does NOT support {% extends %} or {% include %}. * Use compileWithInheritance() for templates with inheritance. * * @example * ```typescript * const renderUser = compile('

{{ name|upper }}

') * const html = renderUser({ name: 'world' }) //

WORLD

* ``` */ export declare function compile(source: string, options?: CompileOptions): (ctx: Record) => string; export interface CompileWithInheritanceOptions extends CompileOptions { /** Base directory for resolving template paths */ templates: string; /** File extensions to try (default: ['.html', '.jinja', '.jinja2', '']) */ extensions?: string[]; } /** * Compile a template with full inheritance support (extends/include/block) * Resolves all template inheritance at compile-time for maximum AOT performance. * * IMPORTANT: All {% extends %} and {% include %} must use static string literals. * Dynamic template names (variables) are not supported in AOT mode. * * @example * ```typescript * // page.html: {% extends "base.html" %}{% block content %}Hello{% endblock %} * const renderPage = await compileWithInheritance('page.html', { * templates: './templates' * }) * const html = renderPage({ title: 'Home' }) // Full page with base template * ``` */ export declare function compileWithInheritance(templateName: string, options: CompileWithInheritanceOptions): Promise<(ctx: Record) => string>; /** * Compile a template with inheritance to JavaScript code string * For build tools and CLI usage. */ export declare function compileWithInheritanceToCode(templateName: string, options: CompileWithInheritanceOptions): Promise; /** * Compile a template to JavaScript code string (for build tools/CLI) * The generated code can be saved to a file and imported directly * * @example * ```typescript * const code = compileToCode('

{{ name }}

', { functionName: 'renderHeader' }) * // Returns: "function renderHeader(__ctx) { ... }" * ``` */ export declare function compileToCode(source: string, options?: CompileOptions): string; export { Lexer, TokenType } from './lexer'; export type { Token } from './lexer'; export { Parser } from './parser'; export type { TemplateNode, ASTNode, ExpressionNode } from './parser/nodes'; export { Runtime, Context } from './runtime'; export { builtinFilters } from './filters'; export type { FilterFunction } from './filters'; export { TemplateError, TemplateSyntaxError, TemplateRuntimeError } from './errors'; export type { CompileOptions } from './compiler'; export { builtinTests } from './tests'; export type { TestFunction } from './tests'; export { flattenTemplate, canFlatten } from './compiler/flattener'; export type { TemplateLoader } from './compiler/flattener'; export { renderWithDebug, renderStringWithDebug, createDebugRenderer, debugMiddleware, generateDebugPanel, } from './debug'; export type { DebugData, PanelOptions, DebugRenderOptions } from './debug'; //# sourceMappingURL=index.d.ts.map