10 examples of 'ejs renderfile' in JavaScript

Every line of 'ejs renderfile' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
8function partial(file, data) {
9 var partial = fs.readFileSync(path.resolve(dir, file) +'.ejs', 'utf8');
10
11 data.partial = partial;
12
13 partial = ejs.render(partial, data);
14 return partial;
15}
10function renderTemplate (file, data) {
11 return ejs.render(templates[file], data);
12}
14function ejs2html(ejsName, ejsFolder) {
15 var htmlPath = '/public/',
16 ejsPath = __dirname + ejsFolder + ejsName;
17 i18n.setLocale('ch');
18 htmlPath = __dirname + htmlPath;
19 if(!fs.existsSync(htmlPath)) {
20 fs.mkdirSync(htmlPath);
21 }
22 ejs.renderFile(ejsPath, {
23 url: url,
24 cdnUrl: cdnUrl
25 }, function (err, result) {
26 if(!err) {
27 var htmlName = ejsName.replace('.ejs', '.html');
28 fs.writeFile(htmlPath + htmlName, result, function () {});
29 } else {
30 /*eslint no-console: ["error", { allow: ["log"] }] */
31 console.log(err);
32 }
33 });
34}
6function ejsRenderer(data, locals) {
7 return ejs.render(data.text, assign({filename: data.path}, locals));
8}
169function render(path, options, callback) {
170 var layoutPath,
171 str;
172
173 try {
174 str = jqtpl.render(path, options);
175 } catch(err) {
176 if (callback) {
177 return callback(err);
178 }
179
180 throw err;
181 }
182
183 if (!options.__isLayout && !options.__isPartial) {
184 layoutPath = findLayout(options);
185 if (layoutPath) {
186 options.__parent = _.clone(options);
187 options.__isLayout = true;
188 options.body = str;
189 return exports.render(layoutPath, options, callback);
190 }
191 }
192
193 if (callback) {
194 callback(null, str);
195 } else {
196 return str;
197 }
198}
66function renderFile(file,data){
67 return swig.render(fs.readFileSync(file).toString(),{
68 filename: file,
69 autoescape: false,
70 locals: data
71 })
72}
5export function render(templateName, options) {
6 // TODO: add cache for templates and read files async
7 const template = readFileSync(
8 path.join(__dirname, `/templates/${templateName}.md`),
9 {
10 encoding: 'utf8',
11 },
12 );
13
14 return (
15 ejs
16 .render(template, options)
17 // trip line break at the beginning
18 .replace(/^\n+/g, '')
19 // make sure that you have only one line break at the end
20 .replace(/\n+$/g, '\n')
21 // replace more then 2 line break for 2
22 .replace(/[\n]{2,}/g, '\n\n')
23 );
24}
107function render(file, data, outputDir) {
108 outputDir = outputDir || null
109 env.render(file, data, function(err, res) {
110 if (err) return console.error(chalk.red(err))
111 var outputFile = file.replace(/\.\w+$/, '') + '.html'
112 if (outputDir) {
113 outputFile = path.resolve(outputDir, outputFile);
114 mkdirp.sync(path.dirname(outputFile))
115 }
116 console.log(chalk.blue('Rendering: ' + file))
117 fs.writeFileSync(outputFile, res)
118 })
119}
77function renderJs(rawScript, render) {
78 const { matches, script } = findInjectionPosition(rawScript);
79
80 if (matches && matches.length) {
81 let renderScript = `module.exports={\n render: ${render.render},\n\n staticRenderFns: ${render.staticRenderFns}, \n`;
82
83 return script
84 .split(matches[1])
85 .join(
86 renderScript.replace('module.exports={', matches[1]).replace(/\}$/, '')
87 );
88 }
89
90 throw new Error(`cannot find 'export defaults'.`);
91}
51function less(file) {
52 return _less.render(file.content, {
53 filename: file.src,
54 sourceMap: {},
55 paths: [file.dir]
56 }).then(function (result) {
57 return {
58 content: result.css.toString(),
59 map: result.map,
60 mapImports: result.imports
61 };
62 });
63}

Related snippets