public void IsOnlyEmbbedPasses() { var embbedTemplate = TextTemplateEngine.Create(); embbedTemplate.TemplateText = "$Word$! $Word$!."; embbedTemplate.AddKeyword("Word", "Apple"); var templateEngine = TextTemplateEngine.Create(); templateEngine.DoShareKaywords = true; templateEngine.IsSingleKeywordPairMode = true; templateEngine.IsOnlyEmbbed = true; templateEngine.TemplateText = "This $Item$ is $Condition$. %Yell%"; templateEngine.AddKeyword("Item"); templateEngine.AddKeyword("Condition"); templateEngine.AddKeyword("Word"); templateEngine.AddSingleKeywordPair("", "", "Good"); templateEngine.AddSingleKeywordPair("", "", "Nice"); templateEngine.AddEmbbed("Yell", embbedTemplate); var newline = templateEngine.NewLineStr; Assert.AreEqual($"This $Item$ is $Condition$. Good! Good!." + newline + "Nice! Nice!.", templateEngine.Generate()); }
public void DoShareKeywordsPasses() { var childEmbbedTemplate = TextTemplateEngine.Create(); childEmbbedTemplate.TemplateText = "?$Key$?"; childEmbbedTemplate.AddKeyword("Key", "Apple"); var embbedTemplate = TextTemplateEngine.Create(); embbedTemplate.TemplateText = "$Item$=>$Condition$! $NotExpanded$!. %Yell%;"; embbedTemplate.AddKeyword("Item", "Cat"); embbedTemplate.AddKeyword("Condition", "Sleep"); embbedTemplate.AddKeyword("NotExpanded", "Apple"); // <- これは使用されない embbedTemplate.AddEmbbed("Yell", childEmbbedTemplate); // <- embbedTemplate.DoShareKaywords=falseの時はこちらは使用される。 var templateEngine = TextTemplateEngine.Create(); templateEngine.TemplateText = "This $Item$ is $Condition$. %Yell%"; templateEngine.AddKeyword("Item", "Pen", "Grass"); templateEngine.AddKeyword("Condition", "Good", "Nice"); templateEngine.AddIgnorePair(("Item", "Grass"), ("Condition", "Good")); templateEngine.AddIgnorePair(("Item", "Pen"), ("Condition", "Nice")); templateEngine.AddEmbbed("Yell", embbedTemplate); templateEngine.DoShareKaywords = true; var newline = templateEngine.NewLineStr; var expanedText = $"Pen=>Good! $NotExpanded$!. ?Apple?;{newline}Grass=>Nice! $NotExpanded$!. ?Apple?;"; Assert.AreEqual( $"This Pen is Good. {expanedText}" + newline + $"This Grass is Nice. {expanedText}", templateEngine.Generate()); }
public void UseOtherTextTemplatePasses() { var embbedTemplate = TextTemplateEngine.Create(); embbedTemplate.TemplateText = "$Word$! $Word$! $Word$!."; embbedTemplate.AddKeyword("Word", "Apple"); var templateEngine = TextTemplateEngine.Create(); templateEngine.TemplateText = "This $Item$ is $Condition$. %Yell%"; templateEngine.AddKeyword("Item", "Pen", "Grass"); templateEngine.AddKeyword("Condition", "Good", "Nice"); templateEngine.AddIgnorePair(("Item", "Grass"), ("Condition", "Good")); templateEngine.AddEmbbed("Yell", embbedTemplate); var otherTemplateEngine = TextTemplateEngine.Create(); otherTemplateEngine.TemplateText = ""; otherTemplateEngine.AddKeyword("Item", "Kumi", "Tom"); otherTemplateEngine.AddKeyword("Condition", "Hot", "Cool"); otherTemplateEngine.AddIgnorePair(("Item", "Tom"), ("Condition", "Hot")); var newline = templateEngine.NewLineStr; Assert.AreEqual("This Kumi is Hot. Apple! Apple! Apple!." + newline + "This Kumi is Cool. Apple! Apple! Apple!." + newline + "This Tom is Cool. Apple! Apple! Apple!.", templateEngine.Generate(otherTemplateEngine)); }
public void SimpleUsagePasses() { var templateEngine = TextTemplateEngine.Create(); templateEngine.TemplateText = @"This $Item$ is $Condition$."; Assert.AreEqual("This $Item$ is $Condition$.", templateEngine.Generate(), "To not matched keyword do nothing."); templateEngine.AddKeyword("Item", "Pen"); templateEngine.AddKeyword("Condition", "Good"); Assert.AreEqual("This Pen is Good.", templateEngine.Generate(), "Matched keywords replace it's value."); }
public void KeywordWithMultipleValueUsagePasses() { var templateEngine = TextTemplateEngine.Create(); templateEngine.TemplateText = @"This $Item$ is $Condition$."; templateEngine.AddKeyword("Item", "Pen", "Grass"); templateEngine.AddKeyword("Condition", "Good", "Nice"); var generatedText = templateEngine.Generate(); var newline = templateEngine.NewLineStr; Assert.AreEqual("This Pen is Good." + newline + "This Pen is Nice." + newline + "This Grass is Good." + newline + "This Grass is Nice.", generatedText); }
public void EmptyIgnorePairPasses() { var templateEngine = TextTemplateEngine.Create(); templateEngine.TemplateText = @"This $Item$ is $Condition$."; templateEngine.AddKeyword("Item", "Pen", "Grass"); templateEngine.AddKeyword("Condition", "Good", "Nice"); templateEngine.AddIgnorePair(("Item", "Grass"), ("Condition", "Good")); templateEngine.AddIgnorePair(("", "Grass"), ("Condition", "")); var generatedText = templateEngine.Generate(); var newline = templateEngine.NewLineStr; Assert.AreEqual("This $Item$ is $Condition$.", generatedText); }
static void RunTemplates() { var asm = typeof(Program).Assembly; string dir = Path.GetDirectoryName(asm.Location); foreach (var type in asm.GetTypes()) { var attr = ReflectionHelper.GetAttribute <TemplateAttribute>(type, false); if (attr != null) { var ci = type.GetConstructor(Type.EmptyTypes); var context = ci.Invoke(null) as ITextTemplateContext; string text = ResourceHelper.GetText(asm, attr.Resource); text = TextTemplateEngine.Replace(text, context); string fullpath = Path.Combine(dir, attr.Path); File.WriteAllText(fullpath, text); } } }
public void ReplacemenetParamPasses() { var template = TextTemplateEngine.Create(); template.TemplateText = "$Item1$ is $Item2$. %Embbed%"; template.IsSingleKeywordPairMode = true; template.DoShareKaywords = true; template.AddKeyword("Item1"); template.AddKeyword("Item2"); template.AddSingleKeywordPair("Apple", "Good"); template.AddSingleKeywordPair("Grape", "Nice"); var embbedTemplate = TextTemplateEngine.Create(); embbedTemplate.TemplateText = "$Item1$-$Item1$"; template.AddEmbbed("Embbed", embbedTemplate); // initialize use Parameter! var replaceParam = TextTemplateEngine.Create(); replaceParam.AddKeyword("Item1", "Banana", "Orange"); replaceParam.AddKeyword("Item2", "yellow", "orange"); replaceParam.AddKeyword("notMatch", "A", "B"); Assert.IsFalse(template.ContainsReplacementKeywords); template.ReplacemenetKeywords = replaceParam; Assert.IsTrue(template.ContainsReplacementKeywords); Assert.AreSame(replaceParam, template.ReplacemenetKeywords); var newline = template.NewLineStr; Assert.AreEqual( "Banana is yellow. Banana-Banana" + newline + "Orange-Orange" + newline + "Banana is orange. Banana-Banana" + newline + "Orange-Orange" + newline + "Orange is yellow. Banana-Banana" + newline + "Orange-Orange" + newline + "Orange is orange. Banana-Banana" + newline + "Orange-Orange" , template.Generate()); }
public void EmbbedTemplatePasses() { var embbedTemplate = TextTemplateEngine.Create(); embbedTemplate.TemplateText = "$Word$! $Word$! $Word$!."; embbedTemplate.AddKeyword("Word", "Apple"); var templateEngine = TextTemplateEngine.Create(); templateEngine.TemplateText = "This $Item$ is $Condition$. %Yell%"; templateEngine.AddKeyword("Item", "Pen", "Grass"); templateEngine.AddKeyword("Condition", "Good", "Nice"); templateEngine.AddIgnorePair(("Item", "Grass"), ("Condition", "Good")); templateEngine.AddEmbbed("Yell", embbedTemplate); var newline = templateEngine.NewLineStr; Assert.AreEqual("This Pen is Good. Apple! Apple! Apple!." + newline + "This Pen is Nice. Apple! Apple! Apple!." + newline + "This Grass is Nice. Apple! Apple! Apple!.", templateEngine.Generate()); }
public void IsSingleKeywordPairPasses() { var templateEngine = TextTemplateEngine.Create(); templateEngine.TemplateText = "This $Item$ is $Condition$."; templateEngine.AddKeyword("Item"); templateEngine.AddKeyword("Condition"); templateEngine.AddSingleKeywordPair("Apple", "Fruits"); templateEngine.AddSingleKeywordPair("Cat", "Animals"); //これらは設定していても使用されない templateEngine.AddIgnorePair(("Item", "Grass"), ("Condition", "Good")); templateEngine.AddIgnorePair(("Item", "Pen"), ("Condition", "Nice")); // templateEngine.IsSingleKeywordPairMode = true; var newline = templateEngine.NewLineStr; Assert.AreEqual( $"This Apple is Fruits." + newline + $"This Cat is Animals.", templateEngine.Generate()); }
public static string LoadString(string assetId) { string text = CurrentPack?.GetText(assetId) ?? "<null>"; return(Application.isPlaying ? TextTemplateEngine.Process(text) : text); }