this.respond = function (request, reply) { var response, output, paper, templatePath; var paper = new Paper(data.context.settings, data.context.theme_settings, assembler); // Set the environment to dev data.context.in_development = true; data.context.in_production = false; paper.addDecorator(internals.makeDecorator(request, data.context)); // Plugins have the opportunity to add/modify the response by using decorators _.each(request.app.decorators, function (decorator) { paper.addDecorator(decorator); }) templatePath = internals.getTemplatePath(request, data); paper.loadTheme(templatePath, data.acceptLanguage, function () { if (request.query.debug === 'context') { return reply(data.context); } output = paper.renderTheme(templatePath, data); response = reply(output); response.code(data.statusCode); if (data.headers['set-cookie']) { response.header('set-cookie', data.headers['set-cookie']); } }); };
this.respond = function (request, reply) { var response, output, html, paper, templatePath; // Set the environment to dev data.context.in_development = true; data.context.in_production = false; paper = new Paper(assembler); paper.addDecorator(internals.makeDecorator(request, data.context)); // Plugins have the opportunity to add/modify the response by using decorators _.each(request.app.decorators, function (decorator) { paper.addDecorator(decorator); }) templatePath = internals.getTemplatePath(request, data); paper.loadTheme(templatePath, data.acceptLanguage, function () { if (request.query.debug === 'context') { return reply(data.context); } if (data.remote || _.isArray(templatePath)) { if (data.remote) { data.context = _.extend({}, data.context, data.remote_data); } if (data.template_file) { // if multiple render_with if (_.isArray(data.template_file)) { // if data.template_file is an array ( multiple templates using render_with option) // compile all the template required files into a hash table html = data.template_file.reduce(function(table, file) { table[file] = paper.render(file, data.context); return table; }, {}); } else { html = paper.render(data.template_file, data.context); } if (data.remote) { // combine the context & rendered html output = { data: data.remote_data, content: html }; } else { output = html; } } else { output = { data: data.remote_data }; } } else { output = paper.render(data.template_file, data.context); } response = reply(output); response.code(data.statusCode); if (data.headers['set-cookie']) { response.header('set-cookie', data.headers['set-cookie']); } }); };