minijinja-js 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,82 @@
1
+ <div align="center">
2
+ <img src="https://github.com/mitsuhiko/minijinja/raw/main/artwork/logo.png" alt="" width=320>
3
+ <p><strong>MiniJinja for JavaScript: a powerful template engine</strong></p>
4
+
5
+ [![License](https://img.shields.io/github/license/mitsuhiko/minijinja)](https://github.com/mitsuhiko/minijinja/blob/main/LICENSE)
6
+ [![Crates.io](https://img.shields.io/crates/d/minijinja.svg)](https://crates.io/crates/minijinja)
7
+ [![rustc 1.63.0](https://img.shields.io/badge/rust-1.63%2B-orange.svg)](https://img.shields.io/badge/rust-1.63%2B-orange.svg)
8
+ [![Documentation](https://docs.rs/minijinja/badge.svg)](https://docs.rs/minijinja)
9
+
10
+ </div>
11
+
12
+ `minijinja-js` is an experimental binding of
13
+ [MiniJinja](https://github.com/mitsuhiko/minijinja) to JavaScript. It has somewhat
14
+ limited functionality compared to the Rust version. These bindings use
15
+ `wasm-bindgen`.
16
+
17
+ You might want to use MiniJinja instead of Jinja2 when the full feature set
18
+ of Jinja2 is not required and you want to have the same rendering experience
19
+ of a data set between Rust, Python and JavaScript.
20
+
21
+ This exposes a bunch of MiniJinja via wasm to the browser, but not all of it.
22
+
23
+ This package can be useful if you have MiniJinja templates that you want to
24
+ evaluate as a sandbox in a browser for a user or on the backend. Given the
25
+ overheads that this creates size and performance wise, it would not be wise to
26
+ use this for actual template rendering in the browser.
27
+
28
+ ## Example
29
+
30
+ Render a template from a string:
31
+
32
+ ```typescript
33
+ import { Environment } from "minijinja-js";
34
+
35
+ const env = new Environment();
36
+ env.debug = true;
37
+ const result = env.renderStr('Hello {{ name }}!', { name: 'World' });
38
+ console.log(result);
39
+ ```
40
+
41
+ Render a template registered to the engine:
42
+
43
+ ```typescript
44
+ import { Environment } from "minijinja-js";
45
+
46
+ const env = new Environment();
47
+ env.addTemplate('index.html', 'Hello {{ name }}!');
48
+ const result = env.renderTemplate('index.html', { name: 'World' });
49
+ console.log(result);
50
+ ```
51
+
52
+ Evaluate an expression:
53
+
54
+ ```typescript
55
+ import { Environment } from "minijinja-js";
56
+
57
+ const env = new Environment();
58
+ const result = env.evalExpr('1 + 1', {});
59
+ console.log(result);
60
+ ```
61
+
62
+ ## Known Limitations
63
+
64
+ There are various limitations with the binding today, some of which can be fixed,
65
+ others probably not so much. You might run into the following:
66
+
67
+ * Access of the template engine state from JavaScript is not possible.
68
+ * You cannot register a custom auto escape callback or a finalizer
69
+ * If the engine panics, the WASM runtime corrupts.
70
+
71
+ ## Sponsor
72
+
73
+ If you like the project and find it useful you can [become a
74
+ sponsor](https://github.com/sponsors/mitsuhiko).
75
+
76
+ ## License and Links
77
+
78
+ - [Documentation](https://docs.rs/minijinja/)
79
+ - [Examples](https://github.com/mitsuhiko/minijinja/tree/main/examples)
80
+ - [Issue Tracker](https://github.com/mitsuhiko/minijinja/issues)
81
+ - [MiniJinja Playground](https://mitsuhiko.github.io/minijinja-playground/)
82
+ - License: [Apache-2.0](https://github.com/mitsuhiko/minijinja/blob/main/LICENSE)
@@ -0,0 +1,82 @@
1
+ <div align="center">
2
+ <img src="https://github.com/mitsuhiko/minijinja/raw/main/artwork/logo.png" alt="" width=320>
3
+ <p><strong>MiniJinja for JavaScript: a powerful template engine</strong></p>
4
+
5
+ [![License](https://img.shields.io/github/license/mitsuhiko/minijinja)](https://github.com/mitsuhiko/minijinja/blob/main/LICENSE)
6
+ [![Crates.io](https://img.shields.io/crates/d/minijinja.svg)](https://crates.io/crates/minijinja)
7
+ [![rustc 1.63.0](https://img.shields.io/badge/rust-1.63%2B-orange.svg)](https://img.shields.io/badge/rust-1.63%2B-orange.svg)
8
+ [![Documentation](https://docs.rs/minijinja/badge.svg)](https://docs.rs/minijinja)
9
+
10
+ </div>
11
+
12
+ `minijinja-js` is an experimental binding of
13
+ [MiniJinja](https://github.com/mitsuhiko/minijinja) to JavaScript. It has somewhat
14
+ limited functionality compared to the Rust version. These bindings use
15
+ `wasm-bindgen`.
16
+
17
+ You might want to use MiniJinja instead of Jinja2 when the full feature set
18
+ of Jinja2 is not required and you want to have the same rendering experience
19
+ of a data set between Rust, Python and JavaScript.
20
+
21
+ This exposes a bunch of MiniJinja via wasm to the browser, but not all of it.
22
+
23
+ This package can be useful if you have MiniJinja templates that you want to
24
+ evaluate as a sandbox in a browser for a user or on the backend. Given the
25
+ overheads that this creates size and performance wise, it would not be wise to
26
+ use this for actual template rendering in the browser.
27
+
28
+ ## Example
29
+
30
+ Render a template from a string:
31
+
32
+ ```typescript
33
+ import { Environment } from "minijinja-js";
34
+
35
+ const env = new Environment();
36
+ env.debug = true;
37
+ const result = env.renderStr('Hello {{ name }}!', { name: 'World' });
38
+ console.log(result);
39
+ ```
40
+
41
+ Render a template registered to the engine:
42
+
43
+ ```typescript
44
+ import { Environment } from "minijinja-js";
45
+
46
+ const env = new Environment();
47
+ env.addTemplate('index.html', 'Hello {{ name }}!');
48
+ const result = env.renderTemplate('index.html', { name: 'World' });
49
+ console.log(result);
50
+ ```
51
+
52
+ Evaluate an expression:
53
+
54
+ ```typescript
55
+ import { Environment } from "minijinja-js";
56
+
57
+ const env = new Environment();
58
+ const result = env.evalExpr('1 + 1', {});
59
+ console.log(result);
60
+ ```
61
+
62
+ ## Known Limitations
63
+
64
+ There are various limitations with the binding today, some of which can be fixed,
65
+ others probably not so much. You might run into the following:
66
+
67
+ * Access of the template engine state from JavaScript is not possible.
68
+ * You cannot register a custom auto escape callback or a finalizer
69
+ * If the engine panics, the WASM runtime corrupts.
70
+
71
+ ## Sponsor
72
+
73
+ If you like the project and find it useful you can [become a
74
+ sponsor](https://github.com/sponsors/mitsuhiko).
75
+
76
+ ## License and Links
77
+
78
+ - [Documentation](https://docs.rs/minijinja/)
79
+ - [Examples](https://github.com/mitsuhiko/minijinja/tree/main/examples)
80
+ - [Issue Tracker](https://github.com/mitsuhiko/minijinja/issues)
81
+ - [MiniJinja Playground](https://mitsuhiko.github.io/minijinja-playground/)
82
+ - License: [Apache-2.0](https://github.com/mitsuhiko/minijinja/blob/main/LICENSE)
@@ -0,0 +1,89 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ type UndefinedBehavior = "strict" | "chainable" | "lenient" | "semi_strct";
4
+ /**
5
+ * Represents a MiniJinja environment.
6
+ */
7
+ export class Environment {
8
+ free(): void;
9
+ constructor();
10
+ /**
11
+ * Registers a new template by name and source.
12
+ */
13
+ addTemplate(name: string, source: string): void;
14
+ /**
15
+ * Removes a template by name.
16
+ */
17
+ removeTemplate(name: string): void;
18
+ /**
19
+ * Clears all templates from the environment.
20
+ */
21
+ clearTemplates(): void;
22
+ /**
23
+ * Renders a registered template by name with the given context.
24
+ */
25
+ renderTemplate(name: string, ctx: any): string;
26
+ /**
27
+ * Renders a string template with the given context.
28
+ *
29
+ * This is useful for one-off template rendering without registering the template. The
30
+ * template is parsed and rendered immediately.
31
+ */
32
+ renderStr(source: string, ctx: any): string;
33
+ /**
34
+ * Like `renderStr` but with a named template for auto escape detection.
35
+ */
36
+ renderNamedStr(name: string, source: string, ctx: any): string;
37
+ /**
38
+ * Evaluates an expression with the given context.
39
+ *
40
+ * This is useful for evaluating expressions outside of templates. The expression is
41
+ * parsed and evaluated immediately.
42
+ */
43
+ evalExpr(expr: string, ctx: any): any;
44
+ /**
45
+ * Registers a filter function.
46
+ */
47
+ addFilter(name: string, func: Function): void;
48
+ /**
49
+ * Registers a test function.
50
+ */
51
+ addTest(name: string, func: Function): void;
52
+ /**
53
+ * Enables python compatibility.
54
+ */
55
+ enablePyCompat(): void;
56
+ /**
57
+ * Registers a value as global.
58
+ */
59
+ addGlobal(name: string, value: any): void;
60
+ /**
61
+ * Removes a global again.
62
+ */
63
+ removeGlobal(name: string): void;
64
+ /**
65
+ * Enables or disables debug mode.
66
+ */
67
+ debug: boolean;
68
+ /**
69
+ * Enables or disables block trimming.
70
+ */
71
+ trimBlocks: boolean;
72
+ /**
73
+ * Enables or disables the lstrip blocks feature.
74
+ */
75
+ lstripBlocks: boolean;
76
+ /**
77
+ * Enables or disables keeping of the final newline.
78
+ */
79
+ keepTrailingNewline: boolean;
80
+ /**
81
+ * Reconfigures the behavior of undefined variables.
82
+ */
83
+ undefinedBehavior: UndefinedBehavior;
84
+ /**
85
+ * Configures the max-fuel for template evaluation.
86
+ */
87
+ get fuel(): number | undefined;
88
+ set fuel(value: number | null | undefined);
89
+ }
@@ -0,0 +1,4 @@
1
+ import * as wasm from "./minijinja_js_bg.wasm";
2
+ export * from "./minijinja_js_bg.js";
3
+ import { __wbg_set_wasm } from "./minijinja_js_bg.js";
4
+ __wbg_set_wasm(wasm);