var Q = require("q"); // TODO negotiate text/html vs text/html+fragment (or other mime type) /** * @param {Request} request * @param {String} path * @param {String} contentType * @returns {Response} */ exports.HandleHtmlFragmentResponses = function (app, handleHtmlFragmentResponse) { handleHtmlFragmentResponse = handleHtmlFragmentResponse || exports.handleHtmlFragmentResponse; return function (request) { request.handleHtmlFragmentResponse = handleHtmlFragmentResponse; return Q.fcall(app, request) .then(function (response) { if (response.htmlFragment) { return Q.fcall(handleHtmlFragmentResponse, response); } else { return response; } }); }; }; exports.handleHtmlFragmentResponse = function (response) { var htmlFragment = response.htmlFragment; delete response.htmlFragment; response.headers["content-type"] = "text/html; charset=utf-8"; response.body = { forEach: function (write) { write("\n"); write("\n"); write("
\n"); if (response.htmlTitle !== void 0) { write("