Send headers to outputter

HTML outputter with links
This commit is contained in:
Meutel 2014-01-23 20:48:33 +01:00
parent 676df6f36b
commit 1ab39a1abc
2 changed files with 16 additions and 3 deletions

View File

@ -15,6 +15,7 @@ function Outputter() {
* Output stream.
*/
this.out = null;
this.headers = {};
};
Outputter.prototype = {
//
@ -48,7 +49,8 @@ Outputter.prototype = {
/**
* Set target stream and start outputting.
*/
outputTo: function(stream) {
outputTo: function(headers, stream) {
this.headers = headers;
this.out = stream;
}
@ -130,7 +132,7 @@ HtmlOutputter.prototype = Object.create(Outputter.prototype, {
} else {
this.buffer.push(resource);
if (!this.colStarted) {
this.out.write('<table><tr>');
this.out.write('<h1>Data</h1><table><tr>');
this.colStarted = true;
} else
this.out.write('</tr>');
@ -161,6 +163,17 @@ HtmlOutputter.prototype = Object.create(Outputter.prototype, {
//end collection
this.out.write('</table>');
}
// links
var links = this.headers.Link;
if (links) {
this.out.write('<h1>Links</h1><ul>')
var re = /<([^>]*)>; rel=([^,$]*)/g;
var match;
while ((match = re.exec(links)) != null) {
this.out.write('<li><a href=\"'+match[1]+'\">'+match[2]+'</a></li>');
}
this.out.write('</ul>')
}
this.out.write('</html>');
logger.debug('Action ended');
this.out.end();

View File

@ -134,7 +134,7 @@ Router.prototype = {
});
// start outputter
outputter.outputTo(resp);
outputter.outputTo(headers, resp);
// start action
action.doAction();