Skip to content

Commit

Permalink
Adding a text/plain renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Sep 11, 2017
1 parent 90d4c7f commit 9a818b1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/renderers.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ renderers.set("text/html", (arg, req, headers, tpl) => {
.replace("class=\"headers", req.server.config.renderHeaders === false ? "class=\"headers dr-hidden" : "class=\"headers");
});

renderers.set("text/plain", arg => arg.error || arg.data);

renderers.set("application/javascript", (arg, req, headers) => {
req.headers.accept = "application/javascript";
headers["content-type"] = "application/javascript";
Expand Down
16 changes: 15 additions & 1 deletion test/renderers_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("Renderers", function () {

this.timeout(timeout);
this.tenso = tenso({port: port, routes: routes, logging: {level: "error"}, security: {csrf: false}});
this.tenso.renderer("custom", arg => arg, "application/json");
this.tenso.renderer("custom", arg => arg);

it("GET CSV (header)", function () {
return tinyhttptest({url: "http://localhost:" + port, headers: {accept: "text/csv"}})
Expand Down Expand Up @@ -120,4 +120,18 @@ describe("Renderers", function () {
.expectHeader("content-type", "application/json")
.end();
});

it("GET Plain Text (header)", function () {
return tinyhttptest({url: "http://localhost:" + port, headers: {accept: "text/plain"}})
.expectStatus(200)
.expectHeader("content-type", "application/json")
.end();
});

it("GET Plain Text (query string)", function () {
return tinyhttptest({url: "http://localhost:" + port + "/?format=text/plain"})
.expectStatus(200)
.expectHeader("content-type", "application/json")
.end();
});
});

0 comments on commit 9a818b1

Please sign in to comment.