We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1f513e0 commit c1c5e9dCopy full SHA for c1c5e9d
crates/template/src/lib.rs
@@ -170,6 +170,15 @@ pub fn render(
170
}
171
172
173
+pub fn render_custom(
174
+ template_content: &str,
175
+ ctx: &serde_json::Map<String, serde_json::Value>,
176
+) -> Result<String, crate::Error> {
177
+ let env = get_environment();
178
+ let tpl = env.template_from_str(template_content)?;
179
+ tpl.render(ctx).map_err(Into::into)
180
+}
181
+
182
#[cfg(test)]
183
mod tests {
184
use super::*;
plugins/template/build.rs
@@ -1,4 +1,4 @@
1
-const COMMANDS: &[&str] = &["render"];
+const COMMANDS: &[&str] = &["render", "render_custom"];
2
3
fn main() {
4
tauri_plugin::Builder::new(COMMANDS).build();
plugins/template/js/bindings.gen.ts
@@ -14,6 +14,14 @@ async render(name: Template, ctx: Partial<{ [key in string]: JsonValue }>) : Pro
14
if(e instanceof Error) throw e;
15
else return { status: "error", error: e as any };
16
17
+},
18
+async renderCustom(templateContent: string, ctx: Partial<{ [key in string]: JsonValue }>) : Promise<Result<string, string>> {
19
+ try {
20
+ return { status: "ok", data: await TAURI_INVOKE("plugin:template|render_custom", { templateContent, ctx }) };
21
+} catch (e) {
22
+ if(e instanceof Error) throw e;
23
+ else return { status: "error", error: e as any };
24
25
26
27
plugins/template/permissions/autogenerated/commands/render_custom.toml
@@ -0,0 +1,13 @@
+# Automatically generated - DO NOT EDIT!
+"$schema" = "../../schemas/schema.json"
5
+[[permission]]
6
+identifier = "allow-render-custom"
7
+description = "Enables the render_custom command without any pre-configured scope."
8
+commands.allow = ["render_custom"]
9
10
11
+identifier = "deny-render-custom"
12
+description = "Denies the render_custom command without any pre-configured scope."
13
+commands.deny = ["render_custom"]
plugins/template/permissions/autogenerated/reference.md
@@ -5,6 +5,7 @@ Default permissions for the plugin
#### This default permission set includes the following:
- `allow-render`
+- `allow-render-custom`
## Permission Table
@@ -38,6 +39,32 @@ Enables the render command without any pre-configured scope.
38
39
40
Denies the render command without any pre-configured scope.
41
42
+</td>
43
+</tr>
44
45
+<tr>
46
+<td>
47
48
+`template:allow-render-custom`
49
50
51
52
53
+Enables the render_custom command without any pre-configured scope.
54
55
56
57
58
59
60
61
+`template:deny-render-custom`
62
63
64
65
66
+Denies the render_custom command without any pre-configured scope.
67
68
</td>
69
</tr>
70
</table>
plugins/template/permissions/default.toml
@@ -1,3 +1,3 @@
[default]
description = "Default permissions for the plugin"
-permissions = ["allow-render"]
+permissions = ["allow-render", "allow-render-custom"]
plugins/template/permissions/schemas/schema.json
@@ -307,10 +307,22 @@
307
"markdownDescription": "Denies the render command without any pre-configured scope."
308
},
309
{
310
- "description": "Default permissions for the plugin\n#### This default permission set includes:\n\n- `allow-render`",
+ "description": "Enables the render_custom command without any pre-configured scope.",
311
+ "type": "string",
312
+ "const": "allow-render-custom",
313
+ "markdownDescription": "Enables the render_custom command without any pre-configured scope."
314
+ },
315
+ {
316
+ "description": "Denies the render_custom command without any pre-configured scope.",
317
318
+ "const": "deny-render-custom",
319
+ "markdownDescription": "Denies the render_custom command without any pre-configured scope."
320
321
322
+ "description": "Default permissions for the plugin\n#### This default permission set includes:\n\n- `allow-render`\n- `allow-render-custom`",
323
"type": "string",
324
"const": "default",
- "markdownDescription": "Default permissions for the plugin\n#### This default permission set includes:\n\n- `allow-render`"
325
+ "markdownDescription": "Default permissions for the plugin\n#### This default permission set includes:\n\n- `allow-render`\n- `allow-render-custom`"
326
327
]
328
plugins/template/src/commands.rs
@@ -9,3 +9,13 @@ pub async fn render<R: tauri::Runtime>(
) -> Result<String, String> {
app.render(name, ctx)
+#[tauri::command]
+#[specta::specta]
+pub async fn render_custom<R: tauri::Runtime>(
+ app: tauri::AppHandle<R>,
+ template_content: String,
+ ctx: serde_json::Map<String, serde_json::Value>,
+) -> Result<String, String> {
+ app.render_custom(&template_content, ctx)
plugins/template/src/ext.rs
@@ -4,6 +4,12 @@ pub trait TemplatePluginExt<R: tauri::Runtime> {
name: hypr_template::Template,
ctx: serde_json::Map<String, serde_json::Value>,
) -> Result<String, String>;
+ fn render_custom(
+ &self,
+ ) -> Result<String, String>;
impl<R: tauri::Runtime, T: tauri::Manager<R>> TemplatePluginExt<R> for T {
@@ -17,4 +23,15 @@ impl<R: tauri::Runtime, T: tauri::Manager<R>> TemplatePluginExt<R> for T {
.map(|s| s.trim().to_string())
.map_err(|e| e.to_string())
+ #[tracing::instrument(skip_all)]
28
29
30
31
32
+ ) -> Result<String, String> {
33
+ hypr_template::render_custom(template_content, &ctx)
34
+ .map(|s| s.trim().to_string())
35
+ .map_err(|e| e.to_string())
36
+ }
37
plugins/template/src/lib.rs
@@ -11,7 +11,10 @@ const PLUGIN_NAME: &str = "template";
fn make_specta_builder<R: tauri::Runtime>() -> tauri_specta::Builder<R> {
tauri_specta::Builder::<R>::new()
.plugin_name(PLUGIN_NAME)
- .commands(tauri_specta::collect_commands![commands::render::<Wry>,])
+ .commands(tauri_specta::collect_commands![
+ commands::render::<Wry>,
+ commands::render_custom::<Wry>,
+ ])
.typ::<hypr_gbnf::Grammar>()
.error_handling(tauri_specta::ErrorHandlingMode::Result)
0 commit comments