couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jan Lehnardt (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (COUCHDB-817) Natively support coffeescript
Date Sat, 28 May 2011 19:08:47 GMT

    [ https://issues.apache.org/jira/browse/COUCHDB-817?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13040660#comment-13040660
] 

Jan Lehnardt commented on COUCHDB-817:
--------------------------------------

@paul

make distcheck succeeds, as noted in the commit message.

I'm undecided on the main splittage, the main change is fairly minimal, so I am inclined to
merge it into one.

diff --git a/share/server/util.js b/share/server/util.js
index 053732d..99fb1ed 100644
--- a/share/server/util.js
+++ b/share/server/util.js
@@ -63,6 +63,19 @@ var Couch = {
   },
   compileFunction : function(source, ddoc) {    
     if (!source) throw(["error","not_found","missing function"]);
+
+    var evaluate_function_source = function(source, evalFunction, sandbox) {
+      sandbox = sandbox || {};
+      if(typeof CoffeeScript === "undefined") {
+        return evalFunction(source, sandbox);
+      } else {
+        coffee = CoffeeScript.compile(source);
+        coffee = coffee.substr(17, coffee.length - 1); // get rid of the preamble
+        coffee = coffee.substr(0, coffee.length - 18); // get rid of the postamble
+        return evalFunction(coffee, sandbox);
+      }
+    }
+
     try {
       if (sandbox) {
         if (ddoc) {
@@ -91,9 +104,9 @@ var Couch = {
           };
           sandbox.require = require;
         }
-        var functionObject = evalcx(source, sandbox);
+        var functionObject = evaluate_function_source(source, evalcx, sandbox)
       } else {
-        var functionObject = eval(source);
+        var functionObject = evaluate_function_source(source, eval)
       }
     } catch (err) {
       throw(["error", "compilation_error", err.toSource() + " (" + source + ")"]);


> Natively support coffeescript
> -----------------------------
>
>                 Key: COUCHDB-817
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-817
>             Project: CouchDB
>          Issue Type: New Feature
>            Reporter: Matt Parker
>            Assignee: Jan Lehnardt
>             Fix For: 1.2
>
>
> i'd love to be able to put coffeescript map and reduce function/files directly into my
ddoc, instead of having to compile them first.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message