mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-17 23:14:03 +01:00
A bit more chaining cleanup
This commit is contained in:
@@ -54,7 +54,7 @@ pub enum InternalEventPayload {
|
||||
|
||||
GetHttpRequestByIdRequest(GetHttpRequestByIdRequest),
|
||||
GetHttpRequestByIdResponse(GetHttpRequestByIdResponse),
|
||||
|
||||
|
||||
FindHttpResponsesRequest(FindHttpResponsesRequest),
|
||||
FindHttpResponsesResponse(FindHttpResponsesResponse),
|
||||
|
||||
@@ -210,6 +210,7 @@ pub struct TemplateFunction {
|
||||
pub enum TemplateFunctionArg {
|
||||
Text(TemplateFunctionTextArg),
|
||||
Select(TemplateFunctionSelectArg),
|
||||
Checkbox(TemplateFunctionCheckboxArg),
|
||||
HttpRequest(TemplateFunctionHttpRequestArg),
|
||||
}
|
||||
|
||||
@@ -253,6 +254,14 @@ pub struct TemplateFunctionSelectArg {
|
||||
pub options: Vec<TemplateFunctionSelectOption>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
||||
#[serde(default, rename_all = "camelCase")]
|
||||
#[ts(export)]
|
||||
pub struct TemplateFunctionCheckboxArg {
|
||||
#[serde(flatten)]
|
||||
pub base: TemplateFunctionBaseArg,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
||||
#[serde(default, rename_all = "camelCase")]
|
||||
#[ts(export)]
|
||||
|
||||
@@ -40,6 +40,7 @@ impl Display for FnArg {
|
||||
pub enum Val {
|
||||
Str { text: String },
|
||||
Var { name: String },
|
||||
Bool { value: bool },
|
||||
Fn { name: String, args: Vec<FnArg> },
|
||||
Null,
|
||||
}
|
||||
@@ -49,6 +50,7 @@ impl Display for Val {
|
||||
let str = match self {
|
||||
Val::Str { text } => format!(r#""{}""#, text.to_string().replace(r#"""#, r#"\""#)),
|
||||
Val::Var { name } => name.to_string(),
|
||||
Val::Bool { value } => value.to_string(),
|
||||
Val::Fn { name, args } => {
|
||||
format!(
|
||||
"{name}({})",
|
||||
@@ -176,6 +178,10 @@ impl Parser {
|
||||
} else if let Some(v) = self.parse_ident() {
|
||||
if v == "null" {
|
||||
Some(Val::Null)
|
||||
} else if v == "true" {
|
||||
Some(Val::Bool { value: true })
|
||||
} else if v == "false" {
|
||||
Some(Val::Bool { value: false })
|
||||
} else {
|
||||
Some(Val::Var { name: v })
|
||||
}
|
||||
@@ -397,6 +403,23 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn var_boolean() {
|
||||
let mut p = Parser::new("${[ true ]}${[ false ]}");
|
||||
assert_eq!(
|
||||
p.parse().tokens,
|
||||
vec![
|
||||
Token::Tag {
|
||||
val: Val::Bool { value: true },
|
||||
},
|
||||
Token::Tag {
|
||||
val: Val::Bool { value: false },
|
||||
},
|
||||
Token::Eof
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn var_multiple_names_invalid() {
|
||||
let mut p = Parser::new("${[ foo bar ]}");
|
||||
@@ -516,7 +539,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn fn_mixed_args() {
|
||||
let mut p = Parser::new(r#"${[ foo(aaa=bar,bb="baz \"hi\"", c=qux ) ]}"#);
|
||||
let mut p = Parser::new(r#"${[ foo(aaa=bar,bb="baz \"hi\"", c=qux, z=true ) ]}"#);
|
||||
assert_eq!(
|
||||
p.parse().tokens,
|
||||
vec![
|
||||
@@ -538,6 +561,10 @@ mod tests {
|
||||
name: "c".into(),
|
||||
value: Val::Var { name: "qux".into() }
|
||||
},
|
||||
FnArg {
|
||||
name: "z".into(),
|
||||
value: Val::Bool { value: true }
|
||||
},
|
||||
],
|
||||
}
|
||||
},
|
||||
|
||||
@@ -50,6 +50,7 @@ async fn render_tag<T: TemplateCallback>(
|
||||
Some(v) => v.to_string(),
|
||||
None => "".into(),
|
||||
},
|
||||
Val::Bool { value } => value.to_string(),
|
||||
Val::Fn { name, args } => {
|
||||
let empty = "".to_string();
|
||||
let mut resolved_args: HashMap<String, String> = HashMap::new();
|
||||
|
||||
Reference in New Issue
Block a user