@@ -24,10 +24,17 @@ public static class GavinsAlgorithim
2424 if ( property . IsPropertyValueConditionPassed ( ifCondition . IfConditionValue , ifCondition . IfConditionType ) )
2525 {
2626 //Condition Passed
27- TemplatedContent templatedIfContent = GenerateTemplateFromFileContents ( ifCondition . IfConditionTemplate , options ) ;
27+ TemplatedContent templatedIfContent = GenerateTemplateFromFileContents ( ifCondition . IfConditionTrueTemplate , options ) ;
2828 string templatedIfContentMapped = GenerateFromTemplate ( record , templatedIfContent , parameterKeyValues , options ) ;
2929 clonedTemplate . Template = ReplaceFirstOccurrence ( clonedTemplate . Template , ifCondition . ReplaceRef , templatedIfContentMapped ) ;
3030 }
31+ else if ( ! string . IsNullOrEmpty ( ifCondition . IfConditionFalseTemplate ) )
32+ {
33+ //If Else Condition Block
34+ TemplatedContent templatedIfContent = GenerateTemplateFromFileContents ( ifCondition . IfConditionFalseTemplate , options ) ;
35+ string templatedIfElseContentMapped = GenerateFromTemplate ( record , templatedIfContent , parameterKeyValues , options ) ;
36+ clonedTemplate . Template = ReplaceFirstOccurrence ( clonedTemplate . Template , ifCondition . ReplaceRef , templatedIfElseContentMapped ) ;
37+ }
3138 else
3239 clonedTemplate . Template = ReplaceFirstOccurrence ( clonedTemplate . Template , ifCondition . ReplaceRef , string . Empty ) ;
3340 }
@@ -99,14 +106,17 @@ internal static TemplatedContent GenerateTemplateFromFileContents(string fileCon
99106 string subBlock = templatedContent . Template . GetSubstringByIndexStartAndEnd ( regexIfConditionMatch . Index + regexIfConditionMatch . Length , regexIfConditionMatchEnd . Index - 1 ) ;
100107 //#Replace Template Block with unique Code
101108 templatedContent . Template = templatedContent . Template . ReplaceByIndexStartAndEnd ( regexIfConditionMatch . Index , ( regexIfConditionMatchEnd . Index - 1 ) + regexIfConditionMatchEnd . Length , _replaceCode ) ;
109+ //Determine if subBlock has Else Condition
110+ string [ ] elseIfSplits = Regex . Split ( subBlock , @"{{\s*else-if\s*}}" , RegexOptions . IgnoreCase ) ;
102111 //#Append Condition Code
103112 templatedContent . ReplaceIfConditionCodes . Add ( new ReplaceIfConditionCode
104113 {
105114 ReplaceRef = _replaceCode ,
106- IfPropertyName = ( regexIfConditionMatch . Groups . Count >= 1 ) ? regexIfConditionMatch . Groups [ 1 ] . Value ? . Trim ( ) ? . ToString ( ) ? . ToLower ( ) ? . Replace ( " " , string . Empty ) : "unspecified" ,
107- IfConditionType = ( regexIfConditionMatch . Groups . Count >= 2 ) ? regexIfConditionMatch . Groups [ 2 ] . Value ? . Trim ( ) ? . ToString ( ) ? . ToLower ( ) ? . Replace ( " " , string . Empty ) : "unspecified" ,
108- IfConditionValue = ( regexIfConditionMatch . Groups . Count >= 3 ) ? regexIfConditionMatch . Groups [ 3 ] . Value ? . Trim ( ) ? . ToString ( ) ? . ToLower ( ) : "unspecified" ,
109- IfConditionTemplate = subBlock
115+ IfPropertyName = ( regexIfConditionMatch . Groups . Count >= 1 ) ? regexIfConditionMatch . Groups [ 1 ] . Value ? . ToString ( ) . Trim ( ) . ToLower ( ) ? . Replace ( " " , string . Empty ) : "unspecified" ,
116+ IfConditionType = ( regexIfConditionMatch . Groups . Count >= 2 ) ? regexIfConditionMatch . Groups [ 2 ] . Value ? . ToString ( ) . Trim ( ) . ToLower ( ) ? . Replace ( " " , string . Empty ) : "unspecified" ,
117+ IfConditionValue = ( regexIfConditionMatch . Groups . Count >= 3 ) ? regexIfConditionMatch . Groups [ 3 ] . Value ? . ToString ( ) ? . Trim ( ) . ToLower ( ) : "unspecified" ,
118+ IfConditionTrueTemplate = ( elseIfSplits ? . Length >= 2 ) ? elseIfSplits [ 0 ] : subBlock ,
119+ IfConditionFalseTemplate = ( elseIfSplits ? . Length >= 2 ) ? elseIfSplits [ 1 ] : string . Empty
110120 } ) ;
111121 //Move Next (Both)
112122 regexIfConditionMatch = regexIfConditionMatch . NextMatch ( ) ;
0 commit comments