Skip to content

Commit e040db9

Browse files
committed
fix fmt error
1 parent 69093aa commit e040db9

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

aiscript-runtime/src/endpoint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,4 +607,4 @@ pub(crate) fn convert_field(field: ast::Field) -> Field {
607607
pub fn render(template: &str, context: serde_json::Value) -> Result<String, String> {
608608
let engine = template::get_template_engine();
609609
engine.render(template, &context)
610-
}
610+
}

aiscript-runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ mod endpoint;
2323
mod error;
2424
mod openapi;
2525
mod parser;
26-
mod utils;
2726
mod template;
27+
mod utils;
2828

2929
use aiscript_lexer as lexer;
3030

aiscript-runtime/src/template.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::path::Path;
33
use std::sync::Arc;
44
use std::sync::RwLock;
55

6-
76
/// Template engine for AIScript
87
pub struct TemplateEngine {
98
env: RwLock<Environment<'static>>,
@@ -19,7 +18,7 @@ impl TemplateEngine {
1918
let path = std::path::Path::new("templates").join(name);
2019
match std::fs::read_to_string(path) {
2120
Ok(content) => Ok(Some(content)),
22-
Err(_) => Ok(None)
21+
Err(_) => Ok(None),
2322
}
2423
});
2524

@@ -29,41 +28,47 @@ impl TemplateEngine {
2928
}
3029

3130
/// Render a template with the given context
32-
pub fn render(&self, template_name: &str, context: &serde_json::Value) -> Result<String, String> {
31+
pub fn render(
32+
&self,
33+
template_name: &str,
34+
context: &serde_json::Value,
35+
) -> Result<String, String> {
3336
let env = self.env.read().unwrap();
34-
35-
// 获取模板
36-
let template = env.get_template(template_name)
37+
38+
// get the template
39+
let template = env
40+
.get_template(template_name)
3741
.map_err(|e| format!("Failed to load template '{}': {}", template_name, e))?;
38-
39-
// 渲染模板并返回结果
40-
template.render(context)
42+
43+
// render the template and return the result
44+
template
45+
.render(context)
4146
.map_err(|e| format!("Failed to render template '{}': {}", template_name, e))
4247
}
4348

4449
/// Reload the templates
4550
pub fn reload(&self) -> Result<(), String> {
46-
let mut env = self.env.write().unwrap();
51+
let mut env = self.env.write().unwrap();
4752

48-
//reload templates
53+
//reload templates
4954
env.set_loader(|name| -> Result<Option<String>, minijinja::Error> {
5055
let path = std::path::Path::new("templates").join(name);
5156
match std::fs::read_to_string(path) {
5257
Ok(content) => Ok(Some(content)),
53-
Err(_) => Ok(None)
58+
Err(_) => Ok(None),
5459
}
5560
});
5661

5762
Ok(())
5863
}
5964
}
6065

61-
//Create a global instance of the template engine
66+
//Create a global instance of the template engine
6267
lazy_static::lazy_static! {
6368
static ref TEMPLATE_ENGINE: TemplateEngine = TemplateEngine::new();
6469
}
6570

66-
//Get the template engine instance
71+
//Get the template engine instance
6772
pub fn get_template_engine() -> &'static TemplateEngine {
6873
&TEMPLATE_ENGINE
69-
}
74+
}

0 commit comments

Comments
 (0)