@samveys/template
.tpl.html dikompilasi jadi modul ES, tanpa eval
Daftar ini dibaca dari versi 1.0.2; jalankan pnpm sync untuk memperbaruinya.
import { compileTemplate, createTemplateEngine, escapeHtml, template, TEMPLATE_EXTENSION, SafeString } from '@samveys/template'
Fungsi (4)
compileTemplate
Fungsi
Compiles template `source` to the source of an ES module. `file` is the name shown in errors. Throws `SVS_E109` with the file and line of the problem, e.g. a forbidden member such as `constructor`.
function compileTemplate(source: string, file: string): string;
Diekspor dari packages/template/src/codegen.ts
createTemplateEngine
Fungsi
Tidak ada komentar dokumentasi.
function createTemplateEngine(options: TemplateEngineOptions): TemplateEngine;
Diekspor dari packages/template/src/engine.ts
escapeHtml
Fungsi
Escapes `& < > " ' \`` (and prints a {@link SafeString} unchanged). `null` and `undefined` print nothing.
function escapeHtml(value: unknown): string;
Diekspor dari packages/template/src/runtime.ts
template
Fungsi
The `@samveys/template` plugin: registers the `template` engine with `@samveys/view`. Templates are `<viewsDir>/<name>.tpl.html` (`users.index` → `users/index.tpl.html`) and are compiled to ES modules in `cacheDir`; nothing is evaluated from strings.
function template(options?: TemplateOptions): import("@samveys/core").Plugin<TemplateOptions>;
Diekspor dari packages/template/src/plugin.ts
Nilai (1)
TEMPLATE_EXTENSION
Nilai
Tidak ada komentar dokumentasi.
const TEMPLATE_EXTENSION = ".tpl.html";
Diekspor dari packages/template/src/engine.ts
Class (1)
SafeString
Class
HTML that is already safe: `{{ }}` prints it as is. Slots and sections are `SafeString`s.
class SafeString {
readonly value: string;
constructor(value: string);
toString(): string;
}
Diekspor dari packages/template/src/runtime.ts
Interface (3)
TemplateEngine
Interface
Tidak ada komentar dokumentasi.
interface TemplateEngine extends ViewEngine {
/** Compiles a template without rendering it; returns the generated module source. */
compile(name: string): Promise<string>;
}
Diekspor dari packages/template/src/engine.ts
TemplateEngineOptions
Interface
Tidak ada komentar dokumentasi.
interface TemplateEngineOptions {
/** Absolute directory with the templates. */
readonly viewsDir: string;
/** Absolute directory for the generated modules (`storage/views`). */
readonly cacheDir: string;
/** Sub-directory of `viewsDir` with components for `<x-name>`. Default `components`. */
readonly componentsDir?: string;
/** Recompile when the source changes. Default false; the plugin enables it when `app.env === 'local'`. */
readonly watch?: boolean;
/** Helpers filled in by other plugins (`vite`, `csrfToken`). Read at render time. */
readonly helpers?: ViewHelpers;
}
Diekspor dari packages/template/src/engine.ts
TemplateOptions
Interface
Tidak ada komentar dokumentasi.
interface TemplateOptions {
/** Directory with the `.tpl.html` files. Default `<rootDir>/resources/views`. */
readonly viewsDir?: string;
/** Directory for the compiled modules. Default `<rootDir>/storage/views`. */
readonly cacheDir?: string;
/** Sub-directory of `viewsDir` with `<x-…>` components. Default `components`. */
readonly componentsDir?: string;
/** Recompile templates when their source changes. Default: on when the app environment is `local`. */
readonly watch?: boolean;
}
Diekspor dari packages/template/src/plugin.ts