mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-24 01:28:35 +02:00
Cargo format
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
pub mod format;
|
||||
pub mod parser;
|
||||
pub mod renderer;
|
||||
pub mod format;
|
||||
|
||||
pub use parser::*;
|
||||
pub use renderer::*;
|
||||
pub use renderer::*;
|
||||
|
||||
@@ -3,25 +3,20 @@ use std::fmt::Display;
|
||||
use ts_rs::TS;
|
||||
|
||||
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize, TS)]
|
||||
#[ts(export, export_to="parser.ts")]
|
||||
#[ts(export, export_to = "parser.ts")]
|
||||
pub struct Tokens {
|
||||
pub tokens: Vec<Token>,
|
||||
}
|
||||
|
||||
impl Display for Tokens {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let str = self
|
||||
.tokens
|
||||
.iter()
|
||||
.map(|t| t.to_string())
|
||||
.collect::<Vec<String>>()
|
||||
.join("");
|
||||
let str = self.tokens.iter().map(|t| t.to_string()).collect::<Vec<String>>().join("");
|
||||
write!(f, "{}", str)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize, TS)]
|
||||
#[ts(export, export_to="parser.ts")]
|
||||
#[ts(export, export_to = "parser.ts")]
|
||||
pub struct FnArg {
|
||||
pub name: String,
|
||||
pub value: Val,
|
||||
@@ -36,7 +31,7 @@ impl Display for FnArg {
|
||||
|
||||
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize, TS)]
|
||||
#[serde(rename_all = "snake_case", tag = "type")]
|
||||
#[ts(export, export_to="parser.ts")]
|
||||
#[ts(export, export_to = "parser.ts")]
|
||||
pub enum Val {
|
||||
Str { text: String },
|
||||
Var { name: String },
|
||||
@@ -71,7 +66,7 @@ impl Display for Val {
|
||||
|
||||
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize, TS)]
|
||||
#[serde(rename_all = "snake_case", tag = "type")]
|
||||
#[ts(export, export_to="parser.ts")]
|
||||
#[ts(export, export_to = "parser.ts")]
|
||||
pub enum Token {
|
||||
Raw { text: String },
|
||||
Tag { val: Val },
|
||||
@@ -396,9 +391,7 @@ impl Parser {
|
||||
return false;
|
||||
}
|
||||
|
||||
let cmp = self.chars[self.pos..self.pos + value.len()]
|
||||
.iter()
|
||||
.collect::<String>();
|
||||
let cmp = self.chars[self.pos..self.pos + value.len()].iter().collect::<String>();
|
||||
|
||||
if cmp == value {
|
||||
// We have a match, so advance the current index
|
||||
|
||||
@@ -80,10 +80,7 @@ async fn render_tag<T: TemplateCallback>(
|
||||
match cb.run(name.as_str(), resolved_args.clone()).await {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
warn!(
|
||||
"Failed to run template callback {}({:?}): {}",
|
||||
name, resolved_args, e
|
||||
);
|
||||
warn!("Failed to run template callback {}({:?}): {}", name, resolved_args, e);
|
||||
"".to_string()
|
||||
}
|
||||
}
|
||||
@@ -116,10 +113,7 @@ mod tests {
|
||||
let template = "";
|
||||
let vars = HashMap::new();
|
||||
let result = "";
|
||||
assert_eq!(
|
||||
parse_and_render(template, &vars, &empty_cb).await,
|
||||
result.to_string()
|
||||
);
|
||||
assert_eq!(parse_and_render(template, &vars, &empty_cb).await, result.to_string());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -128,10 +122,7 @@ mod tests {
|
||||
let template = "Hello World!";
|
||||
let vars = HashMap::new();
|
||||
let result = "Hello World!";
|
||||
assert_eq!(
|
||||
parse_and_render(template, &vars, &empty_cb).await,
|
||||
result.to_string()
|
||||
);
|
||||
assert_eq!(parse_and_render(template, &vars, &empty_cb).await, result.to_string());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -140,10 +131,7 @@ mod tests {
|
||||
let template = "${[ foo ]}";
|
||||
let vars = HashMap::from([("foo".to_string(), "bar".to_string())]);
|
||||
let result = "bar";
|
||||
assert_eq!(
|
||||
parse_and_render(template, &vars, &empty_cb).await,
|
||||
result.to_string()
|
||||
);
|
||||
assert_eq!(parse_and_render(template, &vars, &empty_cb).await, result.to_string());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -156,10 +144,7 @@ mod tests {
|
||||
vars.insert("baz".to_string(), "baz".to_string());
|
||||
|
||||
let result = "foo: bar: baz";
|
||||
assert_eq!(
|
||||
parse_and_render(template, &vars, &empty_cb).await,
|
||||
result.to_string()
|
||||
);
|
||||
assert_eq!(parse_and_render(template, &vars, &empty_cb).await, result.to_string());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -168,10 +153,7 @@ mod tests {
|
||||
let template = "hello ${[ word ]} world!";
|
||||
let vars = HashMap::from([("word".to_string(), "cruel".to_string())]);
|
||||
let result = "hello cruel world!";
|
||||
assert_eq!(
|
||||
parse_and_render(template, &vars, &empty_cb).await,
|
||||
result.to_string()
|
||||
);
|
||||
assert_eq!(parse_and_render(template, &vars, &empty_cb).await, result.to_string());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -187,12 +169,7 @@ mod tests {
|
||||
fn_name: &str,
|
||||
args: HashMap<String, String>,
|
||||
) -> Result<String, String> {
|
||||
Ok(format!(
|
||||
"{fn_name}: {}, {:?} {:?}",
|
||||
args.len(),
|
||||
args.get("a"),
|
||||
args.get("b")
|
||||
))
|
||||
Ok(format!("{fn_name}: {}, {:?} {:?}", args.len(), args.get("a"), args.get("b")))
|
||||
}
|
||||
}
|
||||
assert_eq!(parse_and_render(template, &vars, &CB {}).await, result);
|
||||
@@ -218,10 +195,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(
|
||||
parse_and_render(template, &vars, &CB {}).await,
|
||||
result.to_string()
|
||||
);
|
||||
assert_eq!(parse_and_render(template, &vars, &CB {}).await, result.to_string());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -241,9 +215,6 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(
|
||||
parse_and_render(template, &vars, &CB {}).await,
|
||||
result.to_string()
|
||||
);
|
||||
assert_eq!(parse_and_render(template, &vars, &CB {}).await, result.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user