Merge branch 'helper_not_equals' into dust_helpers
This commit is contained in:
commit
ed7b1f5b3e
10
js/test_cases/helpers_ne/README.md
Normal file
10
js/test_cases/helpers_ne/README.md
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
Without a key parameter, neither the main block nor the else block is rendered.
|
||||||
|
|
||||||
|
Literal values work in both keys and values.
|
||||||
|
|
||||||
|
Can't Walk Theory
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
Assuming a missing value = cantwalk and a non-existent key = cantwalk then their equality makes sense.
|
||||||
|
|
||||||
|
The null tests have proven that absent parameters and missing values do not equal null and therefore it is not just making all falsey values equal.
|
7
js/test_cases/helpers_ne/input1.json
Normal file
7
js/test_cases/helpers_ne/input1.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"str": "master",
|
||||||
|
"int": 7,
|
||||||
|
"alpha": 21,
|
||||||
|
"beta": "21",
|
||||||
|
"null": null
|
||||||
|
}
|
18
js/test_cases/helpers_ne/main.dust
Normal file
18
js/test_cases/helpers_ne/main.dust
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
Testing helpers:{~n}
|
||||||
|
str is {str}{~n}
|
||||||
|
int is {int}{~n}
|
||||||
|
alpha is {alpha}{~n}
|
||||||
|
beta is {beta}{~n}
|
||||||
|
{@ne key=str value="master"}str does not equal "master"{:else}str is equal to "master"{/ne}{~n}
|
||||||
|
{@ne key=str value="7"}str does not equal "7"{:else}str is equal to "7"{/ne}{~n}
|
||||||
|
{@ne key=int value="7"}int does not equal "7"{:else}int is equal to "7"{/ne}{~n}
|
||||||
|
{@ne key=int value=7}int does not equal 7{:else}int is equal to 7{/ne}{~n}
|
||||||
|
{@ne key=alpha value=beta}alpha does not equal beta{:else}alpha is equal to beta{/ne}{~n}
|
||||||
|
{@ne value=beta}missing key is true{:else}missing key is false{/ne}{~n}
|
||||||
|
{@ne value=gamma}missing key and non-existent value is true{:else}missing key and non-existent value is false{/ne}{~n}
|
||||||
|
{@ne key=alpha}missing value is true{:else}missing value is false{/ne}{~n}
|
||||||
|
{@ne key=gamma}missing value and non-existent key is true{:else}missing value and non-existent key is false{/ne}{~n}
|
||||||
|
{@ne key="master" value="master"}"master" does not equal "master"{:else}"master" is equal to "master"{/ne}{~n}
|
||||||
|
{@ne key=null}null does not equal a missing value{:else}null equals a missing value{/ne}{~n}
|
||||||
|
{@ne key=null value=gamma}null does not equal non-existent value{:else}null equals a non-existent value{/ne}{~n}
|
||||||
|
{@ne}no parameters is true{:else}no parameters if false{/ne}{~n}
|
@ -265,6 +265,47 @@ impl<'a> DustRenderer<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
DustTag::DTHelperNotEquals(parameterized_block) => {
|
||||||
|
let param_map: HashMap<&str, &RValue<'a>> = parameterized_block
|
||||||
|
.params
|
||||||
|
.iter()
|
||||||
|
.map(|pair: &KVPair<'a>| (pair.key, &pair.value))
|
||||||
|
.collect();
|
||||||
|
let left_side: Result<&dyn ContextElement, WalkError> = match param_map.get("key") {
|
||||||
|
None => return Ok("".to_owned()),
|
||||||
|
Some(rval) => match rval {
|
||||||
|
RValue::RVString(text) => Ok(text),
|
||||||
|
RValue::RVPath(path) => walk_path(breadcrumbs, &path.keys),
|
||||||
|
RValue::RVPositiveInteger(num) => Ok(num),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
let right_side: Result<&dyn ContextElement, WalkError> =
|
||||||
|
match param_map.get("value") {
|
||||||
|
None => Err(WalkError::CantWalk),
|
||||||
|
Some(rval) => match rval {
|
||||||
|
RValue::RVString(text) => Ok(text),
|
||||||
|
RValue::RVPath(path) => walk_path(breadcrumbs, &path.keys),
|
||||||
|
RValue::RVPositiveInteger(num) => Ok(num),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
if left_side != right_side {
|
||||||
|
match ¶meterized_block.contents {
|
||||||
|
None => return Ok("".to_owned()),
|
||||||
|
Some(body) => {
|
||||||
|
let rendered_content = self.render_body(body, breadcrumbs, blocks)?;
|
||||||
|
return Ok(rendered_content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
match ¶meterized_block.else_contents {
|
||||||
|
None => return Ok("".to_owned()),
|
||||||
|
Some(body) => {
|
||||||
|
let rendered_content = self.render_body(body, breadcrumbs, blocks)?;
|
||||||
|
return Ok(rendered_content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => (), // TODO: Implement the rest
|
_ => (), // TODO: Implement the rest
|
||||||
}
|
}
|
||||||
Ok("".to_owned())
|
Ok("".to_owned())
|
||||||
|
Loading…
Reference in New Issue
Block a user