2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 15:50:56 +00:00
books/common/print.js
2018-04-18 12:18:24 +05:30

28 lines
648 B
JavaScript

const frappe = require('frappejs');
const nunjucks = require('nunjucks/browser/nunjucks');
async function getHTML(doctype, name) {
const meta = frappe.getMeta(doctype);
const printFormat = await frappe.getDoc('PrintFormat', meta.print.printFormat);
let doc = await frappe.getDoc(doctype, name);
let context = {doc: doc, frappe: frappe};
let html;
try {
html = nunjucks.renderString(printFormat.template, context);
} catch (error) {
console.log(error);
html = '';
}
return `
<div class="print-page">
${html}
</div>
`;
}
module.exports = {
getHTML
}