Reputation: 3576
I've seen that there are template parsers which transform the template into a not so human-readable form, so I thought how about sending the templates from PHP parsed already.
Some templates are quite big and have a lot of expressions. Would this improve the performance? Even if it's a negligible factor, does it save the browser from re-parsing the templates again?
If so, I've looked up the function and I tried overloading it so I can understand what is with those variables, like this:
Ractive.parse = function (a) {
var b = arguments[1]; console.log('b', b);
void 0 === b && (b = {});
var c, d, e, f, g, h; console.log('c,d,e,f,g,h', c, d, e, f, g, h);
if (c = { v: 1 }, m.test(a)) {
console.log('m', m);
for (d = a, a = ""; g = m.exec(d);) {
if (f = g[1], a += d.substr(0, g.index), d = d.substring(g.index + g[0].length), h = n.exec(d), !h || h[1] !== f)
throw new Error("Inline partials must have a closing delimiter, and cannot be nested");
(e || (e = {}))[f] = new j(d.substr(0, h.index), b).result, d = d.substring(h.index + h[0].length)
}
c.p = e
}
console.log('j',j)
return c.t = new j(a, b).result, c
}
But I failed to overload it. Either I'm dumb or it's not done this way.
I want to "port" the parse
function into PHP so I can send pre-parsed templates to the application. (and there is a big plus regarding anti-theft since others can't really change that much when they see this kind of template)
I'm wondering if there's any possibility of getting my hands on the standalone
parse function so I can port it to PHP.
Upvotes: 0
Views: 449
Reputation: 3712
The parse code is on github here
That being said, if you're going to preparse templates it usually only happens as part of the build process, not each time you serve the template. And there are multiple existing ways to preparse Ractive templates. Checkout: http://docs.ractivejs.org/latest/tips.
Most of these use node, but you could even use a build page to parse them in the browser and post them to the server.
Integrating any of those options into your build process seems infinitely easier than porting the parser to PHP, but that's up to you.
Upvotes: 2