javascript - Delivering precompiled Handlebars Template on demand via JSON -


i want deliver handlebars templates ember.js application on demand via ajax-request. i'm able compile on server , i'm able deliver following output (function) string:

ember.templates["authentication"] = ember.handlebars.template(function anonymous(handlebars,depth0,helpers,partials,data) { this.compilerinfo = [2,'>= 1.0.0-rc.3']; helpers = helpers || ember.handlebars.helpers; data = data || {};   var buffer = '', stack1, hashtypes, options, helpermissing=helpers.helpermissing, escapeexpression=this.escapeexpression;     data.buffer.push("<h1>hooray! works!</h1>\r\n");   hashtypes = {};   options = {hash:{},contexts:[depth0],types:["id"],hashtypes:hashtypes,data:data};   data.buffer.push(escapeexpression(((stack1 = helpers.outlet),stack1 ? stack1.call(depth0, "main", options) : helpermissing.call(depth0, "outlet", "main", options))));   return buffer;  }); 

this string i'm able received json object. now, want add precompiled template ember.templates object this:

if(typeof data.template === 'string' && data.template != '') {                   var escapedtemplatestring =                       data.template.replace(/\\n/g, "\\n").replace(/\\r/g, "\\r").replace(/\\t/g, "\\t");                    ember.templates[templatename] = ember.handlebars.template(new function(escapedtemplatestring));                 } 

but wraps whole 'stringified' function anonymous function(){} , no template. if unpack 'stringified' function eval, template undefined...

does know how function without wrap 'stringified' function? lot time in advance ;)

nevermind... forgot declare ajax request async: false rendering process wait template loaded.

also, changed function call eval( escapedtemplatestring ) eval( "(" + escapedtemplatestring + ")" )

--> everything's working great now


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -