ember.js - Handlebars - Decompile handlebars compiled code to handlebars template -


is possible decompile handlebars precompiled code handlebars template?

possibly convert this:

function program2(depth0, data) { var buffer = '', stack1; data.buffer.push('<div '); ...... data.buffer.push('</div></div>'); return buffer; }

to

<div>{{name}}</div> 

unfortunately, there no built-in way so.

one solution write function traverses compiled code, html being pushed , put html (reverse engineer function, essentially).

there's 1 drawback: compiled templates use depth0 variable store passed in model/object. can see , other objects being passed in parameters each compiled template being instantiated, ie::

app.templates = function (handlebars, depth0, helpers, partials, data) { ... } 

so have follow how each piece of html rendered , find variable names correspond expressions pushed in stack variables. you'd need name of variable used can add attribute of each handlebars block in template (ie: {{mydata}}) expression used (and if block expression).

say have simple template:

{{#if stuff}}     <div id="general" class="content-section">     <p>{{mydata}}</p>     </div> {{/if}} 

the depth0 object contain stuff , mydata. they're being used inside of template (this not working example, edited template show it'd like):

buffer += "\r\n\r\n<div id=\"general\" class=\"content-section\">\r\n"     + escapeexpression(((stack1 = ((stack1 = (depth0 && depth0.stuff)),     stack1 == null || stack1 === false ? stack1 : stack1.mydata)),      typeof stack1 === functiontype ? stack1.apply(depth0) : stack1)) 

hopefully helps bit - doable if want put work in.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -