Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* @license New BSD License (see LICENSE file for details).
*/
var express = require('express'),
DB = require('./db'),
sconfig = require("./config"),
log = require('logule').init(module),
path = require('path'),
ejs = require('ejs'),
ursa = require('ursa'),
fs = require('fs'),
util = require('./util'),
//constants
HTTP_SERVER_ERROR = 500;
ejs.open = '{{';
ejs.close = '}}';
/* Globals */
global.obj = require('./lib/obj');
global.arrays = require('./lib/arrays');
global.ClientError = require('./lib/clienterror');
global.ROOT = path.dirname(process.mainModule.filename);
/**
* Mount a new Survana module
* @param app
* @param name
* @param mconf
* @return {Object}
*/
function addModule(app,name,mconf)
'For example: ');
return;
}
// Extract the bindings
conf.bindings = {};
var queryScripts = document.querySelectorAll('script[type="text/prismic-query"]');
for(var i=0; i
function renderTemplate(content, ctx) {
// The vm context sandbox is kept separate from the template context to work around an issue
// in earlier versions of node (pre v0.11.7) where escape() is added to the template context.
if (!ctx._sandbox) {
ctx._sandbox = vm.createContext(ctx);
}
ejs.open = '[%';
ejs.close = '%]';
ctx._sandbox.__render__ = function render() {
delete ctx._sandbox.__render__;
return ejs.render(content, ctx);
};
return vm.runInContext("__render__()", ctx._sandbox);
}
var ejs = require('ejs')
ejs.open = '{{'
ejs.close = '}}'
var express = require('express')
var app = express()
var http = require('http')
var server = http.createServer(app)
var ws = new (require('websocket').server)({httpServer: server, port: 3030})
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
// intercept OPTIONS method
if ('OPTIONS' == req.method) {
res.send(200);
}
* Module dependencies.
*/
var fs = require('fs');
var path = require('path');
var http = require('http');
var ejs = require('ejs');
var filters = require('./filters');
var settings = {
root: __dirname + '/views',
cache: true,
layout: 'layout.html',
viewExt: '', // view default extname
_filters: {},
open: ejs.open || "<%",
close: ejs.close || "%>"
};
for (var k in filters) {
settings._filters[k] = filters[k];
}
var cache = {};
function _render_tpl(fn, options, callback) {
var str;
try {
str = options.scope ? fn.call(options.scope, options) : fn(options);
} catch (err) {
return callback(err);
}
exports.generate = function(docfiles, options, callback) {
if (typeof options === 'function') {
callback = options;
options = {};
}
callback = callback || function() {};
options = options || {};
options = u.defaults(options, {
template: exports.defaultTemplate
, encoding: 'utf-8'
});
ejs.open = '';
fs.readFile(options.template, options.encoding, function(err, data){
if (err) {
callback(err);
}
// Remove indentation
data = data.replace(/\n */g, '\n');
var output = ejs.render(data, {
docfiles: docfiles,
escape: function(html) {
return String(html);
}
});
/**
* 初始化页面
*
* Created by zhaoxiaoqiang on 15/10/19.
*/
var fs = require('fs');
var config = require('./config.js');
var ejs = require('ejs');
// 当和 init-site 集成使用时需要重置配置
ejs.open = '<%';
ejs.close = '%>';
function initPage(articleArr) {
// 首页
var indexPageTemplatePath = config.rootPath + config.indexPageTemplatePath;
var indexTemplate = fs.readFileSync(indexPageTemplatePath, config.encoding);
var indexHtml = ejs.render(
indexTemplate,
{
articleArr: articleArr
}
);
var indexPagePath = config.rootPath + config.indexPagePath;
fs.writeFileSync(indexPagePath, indexHtml, config.encoding);
}
function ViewScaffolder(){
ejs.open = '{{';
ejs.close = '}}';
};
this.render = function() {
var ejs = require('ejs');
ejs.open = '{{';
ejs.close = '}}';
var opts = utils.merge(self.locals, self.fn);
self.output = ejs.render(self.output, opts);
self.res.end(self.output, 'utf-8');
self.output = '';
}
Utils.prototype.writeTemplateFileSync = function(destinationFile, templatePath, model, ejsOpenTag, ejsCloseTag) {
ejs.open = '{{';
ejs.close = '}}';
this.writeFileSync(destinationFile, templatePath, model);
};