couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r906755 - in /couchdb/trunk/share: server/render.js www/script/test/show_documents.js
Date Fri, 05 Feb 2010 01:13:29 GMT
Author: jan
Date: Fri Feb  5 01:13:28 2010
New Revision: 906755

URL: http://svn.apache.org/viewvc?rev=906755&view=rev
Log:
add list()-API cmompatible API to _show. Symmetry FTW.

Modified:
    couchdb/trunk/share/server/render.js
    couchdb/trunk/share/www/script/test/show_documents.js

Modified: couchdb/trunk/share/server/render.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/server/render.js?rev=906755&r1=906754&r2=906755&view=diff
==============================================================================
--- couchdb/trunk/share/server/render.js (original)
+++ couchdb/trunk/share/server/render.js Fri Feb  5 01:13:28 2010
@@ -212,8 +212,20 @@
 
   function runShow(fun, ddoc, args) {
     try {
+      resetList();
       Mime.resetProvides();
-      var resp = fun.apply(ddoc, args);
+      var resp = fun.apply(ddoc, args) || {};
+
+      // handle list() style API
+      if (chunks.length && chunks.length > 0) {
+        resp = maybeWrapResponse(resp);
+        resp.headers = resp.headers || {};
+        for(var header in startResp) {
+          resp.headers[header] = startResp[header]
+        }
+        resp.body = chunks.join("") + (resp.body || "");
+        resetList();
+      }
 
       if (Mime.providesUsed) {
         resp = Mime.runProvides(args[1]);

Modified: couchdb/trunk/share/www/script/test/show_documents.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/show_documents.js?rev=906755&r1=906754&r2=906755&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/show_documents.js (original)
+++ couchdb/trunk/share/www/script/test/show_documents.js Fri Feb  5 01:13:28 2010
@@ -22,7 +22,6 @@
     shows: {
       "hello" : stringFun(function(doc, req) {
         log("hello fun");
-        log(req);
         if (doc) {
           return "Hello World";
         } else {
@@ -80,6 +79,25 @@
           "body" : "something"
         }
       }),
+      "list-api" : stringFun(function(doc, req) {
+        start({"X-Couch-Test-Header": "Yeah"});
+        send("Hey");
+      }),
+      "list-api-mix" : stringFun(function(doc, req) {
+        start({"X-Couch-Test-Header": "Yeah"});
+        send("Hey ");
+        return "Dude";
+      }),
+      "list-api-mix-with-header" : stringFun(function(doc, req) {
+        start({"X-Couch-Test-Header": "Yeah"});
+        send("Hey ");
+        return {
+          headers: {
+            "X-Couch-Test-Header-Awesome": "Oh Yeah!"
+          },
+          body: "Dude"
+        };
+      }),
       "accept-switch" : stringFun(function(doc, req) {
         if (req.headers["Accept"].match(/image/)) {
           return {
@@ -362,5 +380,18 @@
   xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/hello/nonExistingDoc");
   T(xhr.responseText == "New World");
 
+  // test list() compatible API
+  xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/list-api/foo");
+  T(xhr.responseText == "Hey");
+  TEquals("Yeah", xhr.getResponseHeader("X-Couch-Test-Header"), "header should be cool");
+
+  xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/list-api-mix/foo");
+  T(xhr.responseText == "Hey Dude");
+  TEquals("Yeah", xhr.getResponseHeader("X-Couch-Test-Header"), "header should be cool");
+
+  xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/list-api-mix-with-header/foo");
+  T(xhr.responseText == "Hey Dude");
+  TEquals("Yeah", xhr.getResponseHeader("X-Couch-Test-Header"), "header should be cool");
+  TEquals("Oh Yeah!", xhr.getResponseHeader("X-Couch-Test-Header-Awesome"), "header should
be cool");
   
 };



Mime
View raw message