Jurassic and handlebars.js

Oct 16, 2012 at 11:46 AM
Edited Oct 16, 2012 at 3:07 PM

Not sure if this is an issue of Jurassic so I'm posting it in the discussions.

I want to precompile handlebars templates so I need Jurassic to compile the handlebars script on the server side. Here is what I wrote:

var engine = new ScriptEngine();
engine.ExecuteFile(handlebars_scriptpath);
engine.Execute(@"var precompile = Handlebars.precompile;");

compiledTemplate = string.Format("<script type=\"text/javascript\">var {0} = Handlebars.template({1});</script>",
    name, engine.CallGlobalFunction("precompile", template).ToString());

It works well for a very simple handlebars (i.e. Mustache compatible) template. But I have this issue when it complicates:

If I use a handlebars construct like {{#if comments}}{{comments}}{{/if}} then I get an exception in CallGlobalFunction: System.InvalidOperationException: Unsupported object type. Of course, I tested it without Jurassic compilation and it works well with Handlebars alone.

Thanks


Oct 16, 2012 at 2:21 PM
Edited Oct 16, 2012 at 3:05 PM

On the Handlebars forums, I'm told that this is probably a Jurassic issue.

https://github.com/wycats/handlebars.js/issues/340

Jan 30, 2013 at 6:39 PM

Any update on this?  Using Jurassic with Handlebars.js is pretty much useless without a proper way to handle basic constructs and helpers.