fs.readFile('views/' + req.params.page +'.pug', 'utf8', function(err, view) { if (err) { res.end( "<div>No Page Found</div>" ); } else { res.end( pug.render(view) ); } });
templateProcessor: function(filepath, ext, file, cb) { const rendered = pug.render(file, { doctype: 'html', filename: filepath, }); cb(null, rendered); },
function convertToPug(section) { var cacheKey, pugstring, md5; if (!section.markup) { return; } if (/<[a-z][\s\S]*>/i.test(section.markup)) { return; } 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); } }
var getContent = function (filepath, options) { var content = grunt.file.read(filepath); if (isPugTemplate(filepath)) { var pug = require('pug'); options.pug.filename = filepath; content = pug.render(content, options.pug); } // Process files as templates if requested. var process = options.process; if (typeof process === 'function') { content = process(content, filepath); } else if (process) { if (process === true) { process = {}; } content = grunt.template.process(content, process); } if (Object.keys(options.htmlmin).length) { try { content = minify(content, options.htmlmin); } catch (err) { grunt.warn(filepath + '\n' + err); } } // trim leading whitespace content = content.replace(/(^\s*)/g, ''); return escapeContent(content, options.quoteChar, options.indentString, options.templatePathInComment ? filepath : ''); };
parsedBody() { try { return pug.render(this.body(), {}); } catch(error) { console.log(error); return "<p>There was a problem with this blog post</p>"; } }
function(err, result) { if (err) { console.error(err); return; } var nodes = parser(pug.render(result, {pretty: true})); resolve(nodes); });
registerPreprocessor('template', 'pug', (code, {file}) => { return { code: pug.render(code, { filename: file }), map: {} } })
fs.readFile(path.resolve(__dirname, '../../components/ResumeText.vue'), (err, data) => { if (err) throw err const pugOut = data.toString().replace(/\n {4}/g, '\n').match(resumeReg)[1] const xmlOut = pug.render(pugOut, { pretty: true }).slice(1) fs.writeFileSync(path.resolve(__dirname, '../text/resume-pug.txt'), pugOut) fs.writeFileSync(path.resolve(__dirname, '../text/resume-xml.txt'), xmlOut) })
.then(function(content) { console.log(content); return pug.render(content, options, function(err, xml) { console.log(xml) if (err) { throw err; } return xml; }); })
return through.obj(function stream(file, enc, callback) { let error = null; if (file.isBuffer()) { const contents = pug.render(file.contents.toString(), opts); file.contents = new Buffer(contents); } else { error = new PluginError('gulp-pug', 'Unsupported file content'); } file.path = replaceExtension(file.path, '.html'); callback(error, file); });
fs.readFile(path.resolve(__dirname, './rss2.pug'), 'utf-8', (err, template) => { const xml = pug.render(template, { title: config.title, link: config.url + '/', feedUrl: config.url + '/feeds', language: config.language, description: '', posts: utils.render(posts, { preview: false, acceptLanguage }), renderedPosts: utils.render(posts, { preview: true, acceptLanguage }), cdata (text, options) { return '<![CDATA[' + text.replace(/\]\]>/g, ']]]]><![CDATA[>') + ']]>'; } }); resolve(xml); });
through.obj((file, encoding, callback) => { const pugContents = file.isBuffer() ? file.contents.toString(encoding) : file.contents; pug.render( pugContents, {...file.data, filename: file.path, pretty: true}, (error, htmlContents) => { if (error) { callback(error); return; } file.contents = Buffer.from(htmlContents); file.path = filename ? path.join(path.dirname(file.path), filename) : file.path.replace(/\.pug$/, ".html"); callback(null, file); }, ); });
exports.process = function (req, res, next) { if (req.specData && req.specData.renderedHtml) { if (req.specData.isJade || req.specData.isPug) { var html = req.specData.renderedHtml; var specDir = specUtils.getFullPathToSpec(req.path); var specFiles = configUtils.getContextOptions(req.path).rendering.specFiles; var specFilePath = specUtils.getSpecFromDir(specDir, specFiles); /* render jade markup */ html = pug.render(html, { pretty: true, basedir: global.app.get('user'), filename: specFilePath }); req.specData.renderedHtml = html; } } next(); };
transform: (content, path) => { return pug.render(content, { compileDebug: !isProd }, path); }
render: function(source, options) { source = renamePlugins(source, options); return pug.render(source, options); }
async function renderTemplate(pugFile) { let text = await readFile(pugFile) return pug.render(text, {filename: pugFile, basedir: templateDir}) }
renderIndexPage: function(res) { var view = fs.readFileSync('views/index.pug', 'utf8'); res.end( pug.render(view) ); }
Folder.sync("pug" , function (code, args) { var options = merge(true, this.plugins.pug, args); return pug.render(code, options); });