jehugaleahsa / mustache-sharp

An extension of the mustache text template engine for .NET.
The Unlicense
306 stars 78 forks source link

Render using a JSON.Net's JObject #26

Closed smurfpandey closed 10 years ago

smurfpandey commented 10 years ago

I am trying to render HTML from JSON string by parsing it first using JSON.Net. But following test case is failing with message:

Test method Mustache.Test.FormatCompilerTester.TestCompile_Json threw exception: 
System.Collections.Generic.KeyNotFoundException: The key Name could not be found

Test case:

[TestMethod]
        public void TestCompile_Json()
        {
            FormatCompiler compiler = new FormatCompiler();
            const string format = @"Hello, {{Name}}!!!";
            Generator generator = compiler.Compile(format);
            string json = @"{""Name"" : ""Bob""}";
            JObject o = JObject.Parse(json);
            string result = generator.Render(o);
            Assert.AreEqual("Hello, Bob!!!", result, "The wrong text was generated.");
        }

Any help would be appreciated.

jehugaleahsa commented 10 years ago

I just made a change with version 0.2.6.0 so that JObject is seen as a legitimate IDictionary. I am curious how it will handle non-string values, though.

jehugaleahsa commented 10 years ago

I just added one test case to test strings.

On Wed, Jun 25, 2014 at 11:12 AM, Neeraj notifications@github.com wrote:

Maybe adding few test cases will help?

— Reply to this email directly or view it on GitHub https://github.com/jehugaleahsa/mustache-sharp/issues/26#issuecomment-47114589 .

smurfpandey commented 10 years ago

I will test it with other datatypes and let you know how it goes :)