Getting the left and right sides.
This commit is contained in:
		
							parent
							
								
									012028b0bc
								
							
						
					
					
						commit
						7a8247f38a
					
				
							
								
								
									
										5
									
								
								js/test_cases/helpers_eq/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								js/test_cases/helpers_eq/README.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,5 @@ | ||||
| Without a key parameter, neither the main block nor the else block is rendered. | ||||
| 
 | ||||
| Without a value parameter, it probably uses "null" but I haven't yet confirmed that with additional testing. Potentially could also just be making all falsey values equal. | ||||
| 
 | ||||
| Literal values work in both keys and values. | ||||
| @ -8,3 +8,8 @@ beta is {beta}{~n} | ||||
| {@eq key=int value="7"}int is equal to "7"{:else}int does not equal "7"{/eq}{~n} | ||||
| {@eq key=int value=7}int is equal to 7{:else}int does not equal 7{/eq}{~n} | ||||
| {@eq key=alpha value=beta}alpha is equal to beta{:else}alpha does not equal beta{/eq}{~n} | ||||
| {@eq value=beta}missing key is true{:else}missing key is false{/eq}{~n} | ||||
| {@eq value=gamma}missing key and non-existent value is true{:else}missing key and non-existent value is false{/eq}{~n} | ||||
| {@eq key=alpha}missing value is true{:else}missing value is false{/eq}{~n} | ||||
| {@eq key=gamma}missing value and non-existent key is true{:else}missing value and non-existent key is false{/eq}{~n} | ||||
| {@eq key="master" value="master"}"master" is equal to "master"{:else}"master" does not equal "master"{/eq}{~n} | ||||
|  | ||||
| @ -106,10 +106,10 @@ pub struct NamedBlock<'a> { | ||||
| 
 | ||||
| #[derive(Clone, Debug, PartialEq)] | ||||
| pub struct ParameterizedBlock<'a> { | ||||
|     name: &'a str, | ||||
|     params: Vec<KVPair<'a>>, | ||||
|     contents: Option<Body<'a>>, | ||||
|     else_contents: Option<Body<'a>>, | ||||
|     pub name: &'a str, | ||||
|     pub params: Vec<KVPair<'a>>, | ||||
|     pub contents: Option<Body<'a>>, | ||||
|     pub else_contents: Option<Body<'a>>, | ||||
| } | ||||
| 
 | ||||
| #[derive(Clone, Debug, PartialEq)] | ||||
|  | ||||
| @ -1,6 +1,8 @@ | ||||
| use crate::parser::template; | ||||
| use crate::parser::Body; | ||||
| use crate::parser::DustTag; | ||||
| use crate::parser::KVPair; | ||||
| use crate::parser::RValue; | ||||
| use crate::parser::Special; | ||||
| use crate::parser::Template; | ||||
| use crate::parser::TemplateElement; | ||||
| @ -222,6 +224,28 @@ impl<'a> DustRenderer<'a> { | ||||
|                     }, | ||||
|                 }; | ||||
|             } | ||||
|             DustTag::DTHelperEquals(parameterized_block) => { | ||||
|                 let param_map: HashMap<&'a str, &'a 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), | ||||
|                     }, | ||||
|                 }; | ||||
|                 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), | ||||
|                         }, | ||||
|                     }; | ||||
|             } | ||||
|             _ => (), // TODO: Implement the rest
 | ||||
|         } | ||||
|         Ok("".to_owned()) | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander