Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function render() {
try {
let view = riot.render(options.mainTag, options.tagOpts);
let regex = new RegExp('<' + options.mainTag + '.*<\/' + options.mainTag + '>');
// Loading HTML file
let content = await Q.denodeify(FS.readFile)(filePath);
let rendered = content.toString().replace(regex, view);
return callback(null, rendered);
}
catch (e) {
console.log("App engine error: ", e, " Filepath: ", filePath, " Callback: ", callback);
console.log(e.stack);
return;
}
}
exports.sendRiot = function ( api, template, res ) {
if ( api[ 0 ] === 'undefined' || api[ 0 ] == null ) {
return res.status( 404 )
.send( "not found" )
} else {
var riot = require( 'riot' ), // riot has to be called before postview
postView = require( template ),
Entities = require( 'html-entities' )
.XmlEntities,
entities = new Entities(),
html = riot.render( postView, {
posts: api[ 0 ]
} );
html = entities.decode( html )
res.send( "" + html );
}
};
// log render start
let renderStart = options.routeEnd;
// do try/catch
try {
// render page
let page = '';
page += '';
page += '';
page += '';
page += '<title>' + (options.pagetitle ? options.pagetitle + ' | ' : '') + options.title + '</title>';
page += '';
page += options.head || '';
page += '';
page += '';
page += riot.render (options.mount.layout, options);
// delete server
delete options.cdn;
delete options.server;
// set before
let before = options.beforeScript || '';
let after = options.afterScript || '';
// delete post-render options
delete options.beforeScript;
delete options.afterScript;
// do script section of page
page += '
function createRouteWithTagName(tagName) {
var tag = '<' + tagName + ' class="route-' + tagName + '">';
unmountCurrRoute();
$appRoot.innerHTML = tag;
var mountedTag;
try {
if (typeof window === 'undefined') {
$appRoot.innerHTML = riot.render(tagName, routeParams);
} else {
mountedTag = riot.mount(tagName + '.route-' + tagName, routeParams);
}
} catch (e) {
setTimeout(function () {
throw e;
}, 0);
}
if (!mountedTag || mountedTag.length === 0) {
self.trigger('tagNotFound', tagName);
if (self.opts['onTagnotfound'] && self.opts['onTagnotfound'] instanceof Function) {
self.opts['onTagnotfound'](tagName);
}
} else {
self.trigger('routeChanged', tagName);
var riot = require('riot');
var appRouteTag = require('./app-route.js');
console.log(riot.render('app-route', {location: '/user/profile/john'}));
return function render (context, renderOpts) {
var layoutFilePath, layoutFileName, content, View, compiledFileRoute;
var mergedOpts = Object.assign({}, baseOpts, renderOpts);
var riotTag = template.split('>')[0].slice(1);
loadTags(mergedOpts.filename);
compiledFileRoute = mergedOpts.compiledFileRoute || '/bundle.js';
View = require(mergedOpts.filename); //eslint-disable-line
content = Riot.render(View, context)
+ '\n'
+ '\n'
+ '\n'
;
if (mergedOpts.layout) {
layoutFileName = mergedOpts.layout === true
? 'layout.html'
: mergedOpts.layout
;
layoutFilePath = Path.join(mergedOpts.layoutPath, layoutFileName);
content = loadLayout(layoutFilePath).replace('<<>>', content);
}
/*
getMessages(function (messagesFromRedis) {
var messageStore = messagesFromRedis.map(JSON.parse);
var renderedHTML = riot.render(message, {messageStore: messageStore});
reply.view('index', {messages: renderedHTML } );
});
}
app.get('/',function(req,res){
var startingName = 'Susan'
var tagOutput = riot.render(hello,{firstName:startingName})
res.render('index',{tagContent:tagOutput,firstName:startingName})
})
app.use((req, res) => {
var store = createStore(reducers, req.state);
var html = riot.render(riotApp, {isClient: false, routes: routes, store: store, state: store.getState()});
res.render('base', {
html: html,
state: req.state
});
});
.then(function(data) {
data.gateway = gateway
data.user = new User()
res.render('base', {
initialData: JSON.stringify(data),
body: render('app', data)
})
})
})