diff --git a/Deployment/NuGet.exe b/Deployment/NuGet.exe index 9f8781d..6bb79fe 100644 Binary files a/Deployment/NuGet.exe and b/Deployment/NuGet.exe differ diff --git a/Deployment/publish-mustache-sharp.bat b/Deployment/publish-mustache-sharp.bat index d7385f2..5aeec9a 100644 --- a/Deployment/publish-mustache-sharp.bat +++ b/Deployment/publish-mustache-sharp.bat @@ -1,4 +1,4 @@ "C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" ../mustache-sharp.sln /p:Configuration=Release nuget pack ../mustache-sharp/mustache-sharp.csproj -Properties Configuration=Release -nuget push *.nupkg +nuget push *.nupkg -Source https://www.nuget.org/api/v2/package del *.nupkg \ No newline at end of file diff --git a/mustache-sharp.test/FormatCompilerTester.cs b/mustache-sharp.test/FormatCompilerTester.cs index 35ba44b..98e8b63 100644 --- a/mustache-sharp.test/FormatCompilerTester.cs +++ b/mustache-sharp.test/FormatCompilerTester.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Web; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Mustache.Test @@ -1690,60 +1691,11 @@ Odd #endregion - #region ValueIntemplateTests - [TestMethod] - public void TestCompile_CanUseStringValueInEquals() { - FormatCompiler compiler = new FormatCompiler(); - const string format = @"{{#eq Value _Yesterday}}Yes!{{/eq}}"; - Generator generator = compiler.Compile(format); - - string actual = generator.Render(new { Value = "Yesterday" }); - string expected = "Yes!"; - Assert.AreEqual(expected, actual, "Value field didn't work"); - } + #region Custom Tags [TestMethod] - public void TestCompile_CanUseNumericValueInEquals() { - FormatCompiler compiler = new FormatCompiler(); - const string format = @"{{#eq Value _123.3231}}Yes!{{/eq}}"; - Generator generator = compiler.Compile(format); - - - string actual = generator.Render(new { Value = "123.3231" }); - string expected = "Yes!"; - Assert.AreEqual(expected, actual, "Value field didn't work"); - } - - [TestMethod] - public void TestCompile_NonEqualNumericValue() { - FormatCompiler compiler = new FormatCompiler(); - const string format = @"{{#eq Value _123.3232}}Yes!{{/eq}}"; - Generator generator = compiler.Compile(format); - - - string actual = generator.Render(new { Value = "123.3231" }); - string expected = ""; - Assert.AreEqual(expected, actual, "Value field didn't work"); - } - - - #endregion - - #region UrlDecodeEncode - [TestMethod] - public void TestCompile_UrlEncode() { - FormatCompiler compiler = new FormatCompiler(); - compiler.RegisterTag(new UrlEncodeTagDefinition(), true); - const string format = @"{{#urlencode}}https://google.com{{/urlencode}}"; - Generator generator = compiler.Compile(format); - - string actual = generator.Render(new { }); - string expected = "https%3a%2f%2fgoogle.com"; - Assert.AreEqual(expected, actual, "Value field didn't work"); - } - - [TestMethod] - public void TestCompile_UrlEncodeVariableText() { + public void TestCompile_NestedContext_ConsolidatesWriter() + { FormatCompiler compiler = new FormatCompiler(); compiler.RegisterTag(new UrlEncodeTagDefinition(), true); @@ -1751,24 +1703,39 @@ Odd Generator generator = compiler.Compile(format); string actual = generator.Render(new { url = "https://google.com" }); - string expected = "https%3a%2f%2fgoogle.com"; + string expected = HttpUtility.UrlEncode("https://google.com"); Assert.AreEqual(expected, actual, "Value field didn't work"); } - [TestMethod] - public void TestCompile_UrlDecode() { - FormatCompiler compiler = new FormatCompiler(); - - const string format = @"{{#urldecode}}https%3a%2f%2fgoogle.com{{/urldecode}}"; - Generator generator = compiler.Compile(format); + public class UrlEncodeTagDefinition : ContentTagDefinition + { + public UrlEncodeTagDefinition() + : base("urlencode") + { + } - string actual = generator.Render(new { }); - string expected = "https://google.com"; - Assert.AreEqual(expected, actual, "Value field didn't work"); + public override IEnumerable GetChildContext(TextWriter writer, Scope keyScope, Dictionary arguments, Scope contextScope) + { + NestedContext context = new NestedContext() + { + KeyScope = keyScope, + Writer = new StringWriter(), + WriterNeedsConsidated = true, + }; + yield return context; + } + + public override IEnumerable GetChildContextParameters() + { + return new TagParameter[] { new TagParameter("collection") }; + } + + public override string ConsolidateWriter(TextWriter writer, Dictionary arguments) + { + return HttpUtility.UrlEncode(writer.ToString()); + } } - #endregion - } } diff --git a/mustache-sharp.test/mustache-sharp.test.csproj b/mustache-sharp.test/mustache-sharp.test.csproj index 0d2e9e3..4fed361 100644 --- a/mustache-sharp.test/mustache-sharp.test.csproj +++ b/mustache-sharp.test/mustache-sharp.test.csproj @@ -42,6 +42,7 @@ + diff --git a/mustache-sharp/CompoundGenerator.cs b/mustache-sharp/CompoundGenerator.cs index a2a9f9d..a9dc10e 100644 --- a/mustache-sharp/CompoundGenerator.cs +++ b/mustache-sharp/CompoundGenerator.cs @@ -81,10 +81,10 @@ namespace Mustache foreach (IGenerator generator in generators) { generator.GetText(context.Writer ?? writer, context.KeyScope ?? keyScope, context.ContextScope, postProcessor); - if (context.WriterNeedsConsidated) - { - writer.Write(_definition.ConsolidateWriter(context.Writer ?? writer, arguments)); - } + } + if (context.WriterNeedsConsidated) + { + writer.Write(_definition.ConsolidateWriter(context.Writer ?? writer, arguments)); } } } diff --git a/mustache-sharp/Properties/AssemblyInfo.cs b/mustache-sharp/Properties/AssemblyInfo.cs index 2d907ce..bc6cf78 100644 --- a/mustache-sharp/Properties/AssemblyInfo.cs +++ b/mustache-sharp/Properties/AssemblyInfo.cs @@ -14,6 +14,6 @@ using System.Runtime.InteropServices; [assembly: CLSCompliant(true)] [assembly: ComVisible(false)] [assembly: Guid("e5a4263d-d450-4d85-a4d5-44c0a2822668")] -[assembly: AssemblyVersion("0.2.9.0")] -[assembly: AssemblyFileVersion("0.2.9.0")] +[assembly: AssemblyVersion("0.2.10.0")] +[assembly: AssemblyFileVersion("0.2.10.0")] [assembly: InternalsVisibleTo("mustache-sharp.test,PublicKey=0024000004800000940000000602000000240000525341310004000001000100755df5a2b24c568812aae0eb194d08a4e3cba960673bcc07a7d446acf52f3f56ae2155b37b8d547bc5d8c562823bd592d1312bef9ad4740a8bb503d0095c31419f9d190882a2fa46090412bf15b13ca0057ba533c85a853333132ec8b70cf19655ef961b06d1c3fc35b3f68680420562be741456cb7a18bd5ab0fa779f8d47b1")] \ No newline at end of file