Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/// pug.compileClientWithDependenciesTracked(source, ?options) https://pugjs.org/api/reference.html#pugcompileclientwithdependenciestrackedsource-options
let obj = pug.compileClientWithDependenciesTracked(source);
clientFunctionString = obj.body;
str = obj.body;
let strArray: string[] = obj.dependencies;
}
{
/// pug.compileFileClient(path, ?options) https://pugjs.org/api/reference.html#pugcompilefileclientpath-options
clientFunctionString = pug.compileFileClient(path);
str = pug.compileFileClient(path);
}
{
/// pug.render(source, ?options, ?callback) https://pugjs.org/api/reference.html#pugrendersource-options-callback
str = pug.render(source);
// test type for callback paraments
pug.render(source, {}, (err, html) => {
let e: Error = err;
str = html;
});
}
{
/// pug.renderFile(path, ?options, ?callback) https://pugjs.org/api/reference.html#pugrenderfilepath-options-callback
str = pug.renderFile(path);
// test type for callback paraments
pug.renderFile(path, {}, (err, html) => {
let e: Error = err;
str = html;
app.use('/pug', function(req, res){
if(req.url) {
var url_parts = url.parse(req.url, true);
var inj = url_parts.query.inj;
var tpl = '';
if('tpl' in url_parts.query && url_parts.query.tpl != '') {
// Keep the formatting a-la-python
tpl = url_parts.query.tpl.replace('%s', inj);
}
else {
tpl = inj;
}
res.end(randomstring.generate() + pug.render(tpl) + randomstring.generate());
}
});
function preprocessTemplate(data, type) {
let templateData = data;
switch (type) {
case "jade":
case "pug":
// Add empty require function to the context to avoid errors with webpack require inside pug
templateData = pug.render(data, {
filename: "source.html",
pretty: true,
require: function() {}
});
break;
case "vue":
//eslint-disable-next-line no-case-declarations
const vueFile = vueCompiler.parse({ compiler, source: data, needMap: false });
if (!vueFile.template) {
return "";
} // return an empty string
templateData = vueFile.template.content;
if (vueFile.template.lang) {
return preprocessTemplate(templateData, vueFile.template.lang);
}
break;
myPug: function (html, opts, url) {
return require('pug').render(html, {
pretty: true,
filename: url,
doctype: 'html'
})
}
}
}, (err, response, body) => {
t.error(err)
t.strictEqual(response.statusCode, 200)
t.strictEqual(response.headers['content-length'], '' + body.length)
t.strictEqual(response.headers['content-type'], 'text/html; charset=utf-8')
t.strictEqual(pug.render(fs.readFileSync('./templates/index.pug', 'utf8'), data), body.toString())
fastify.close()
})
})
function * genHtmlIncludes ({includes}, htmlSettings, config) {
for (const relPath of includes || []) {
const sourcePath = '../packages/' + relPath
console.log(' | ', sourcePath)
const source = fs.readFileSync(sourcePath, ENC)
if (sourcePath.endsWith('.md')) {
yield `<span data-bind="source: \"${relPath}\""></span>
${md.render(source)}`
} else if (sourcePath.endsWith('.pug')) {
yield pug.render(source, Object.assign({}, htmlSettings, config))
} else {
throw new Error(`Bad extension: ${sourcePath} (not .md or .pug)`)
}
}
}
if (is_static) {
opts = clone(config)
} else {
opts = clonePugOpts(config)
}
const output = []
let fn, body, map, keepDbg
opts.filename = id
if (is_static) {
const static_opts = assign(null, config.locals, opts)
body = `export default ${JSON.stringify(render(code, static_opts))};`
} else {
keepDbg = opts.compileDebug
if (config.sourceMap) {
opts.compileDebug = map = true
}
code = moveImports(code, output)
fn = compileClientWithDependenciesTracked(code, opts)
body = fn.body.replace('function template(', '\nexport default function(')
if (config.runtimeImport && /\bpug\./.test(body)) {
output.unshift(`import pug from '${config.runtimeImport}';`)
}
const deps = fn.dependencies
templateProcessor(path, ext, contents, cb) {
try {
const rendered = pug.render(contents, {
filename: path,
doctype: 'html'
});
setImmediate(cb, null, rendered.trim());
} catch (e) {
setImmediate(cb, e);
}
},
styleProcessor(path, ext, contents, cb) {
exports.masterDocumentToPDF = async function(masterPath, page, tempHTML, outputPath, plugins) {
var html
var t0 = performance.now()
var mixins = []
for (plugin of plugins)
/*
* Generate HTML
*/
if (masterPath.endsWith('.pug')) {
try {
var masterPug = fs.readFileSync(masterPath, 'utf8')
html = pug.render(pluginMixins + builtinMixins + '\n' + masterPug, {
filename: masterPath,
fs: fs,
cheerio: cheerio,
basedir: path.dirname(masterPath),
path: path,
performance: performance,
filters: {
katex: (text, options) => katex.renderToString(text),
scss: function(text, options) {
var file = options.filename
options = file.endsWith('scss') ? { file } : { data: text }
return sass.renderSync(options).css.toString('utf8')
}
}
})
section.markupPug = section.markup;
if (section.reference) {
parentref = section.reference;
cacheKey = section.reference;
} else {
cacheKey = parentref + ' - ' + section.name;
}
pugstring = bemtoinclude + section.markup;
md5 = crypto.createHash('md5').update(pugstring).digest('hex');
if (pugCache.getItem(cacheKey) && pugCache.getItem(cacheKey).key === md5) {
section.markup = pugCache.getItem(cacheKey).value;
} else {
section.markup = pug.render(pugstring, pugOptions);
pugCache.setItem(cacheKey, {
key: md5,
value: section.markup
});
}
if (section.modifiers) {
_.each(section.modifiers, convertToPug);
}
}
}