added feature to add print formats to reports using john resig's microtemplates

This commit is contained in:
Rushabh Mehta 2014-06-12 18:53:07 +05:30
parent 99734d82d3
commit f0b8922e28
2 changed files with 50 additions and 0 deletions

View file

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>{0}</title>
<link href="/assets/frappe/css/bootstrap.css" rel="stylesheet">
</head>
<body>
<div class="container">
{1}
</div>
</body>
</html>

View file

@ -0,0 +1,33 @@
// Simple JavaScript Templating
// Adapted from John Resig - http://ejohn.org/ - MIT Licensed
tmpl = {compiled: {}, debug:{}};
tmpl.compile = function(str) {
if(str.indexOf("'")!==-1) {
console.log("Warning: Single quotes (') may not work in templates");
}
if(!tmpl.compiled[str]) {
fn_str = "var p=[],print=function(){try{p.push.apply(p,arguments)}catch(e){console.log([p, e]);};};" +
// Introduce the data as local variables using with(){}
"with(obj){p.push('" +
// Convert the template into pure JavaScript
str
.replace(/[\r\t\n]/g, " ")
.split("{%").join("\t")
.replace(/((^|%})[^\t]*)'/g, "$1\r")
.replace(/\t=(.*?)%}/g, "',$1,'")
.split("\t").join("');")
.split("%}").join("p.push('")
.split("\r").join("\\'")
+ "');}return p.join('');";
tmpl.debug[str] = fn_str;
tmpl.compiled[str] = new Function("obj", fn_str);
}
return tmpl.compiled[str];
};
tmpl.render = function(str, data, debug) {
return tmpl.compile(str)(data);
};