forked from apache/couchdb
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CoffeeScript (http://coffeescript.org/) support to the JS view se…
…rver. This allows you to write all query server functions in CoffeeScript. The implementation re-uses the JS query server and adds an additional, optional compilation step. To make the implementation easier for now, a new main-coffee.js file is generated that includes the CoffeeScript compiler, but I think we can do away with that in a future optimisation and just use a single main.js that can handle both. The patch includes basic tests for the JS test suite that I tested in Firefox and Chrome. I'm no expert in CoffeeScript, so I don't know if more complex script will break the implementation. `make distcheck` passes. Futon picks up the "coffeescript" design document lanugage as expected and view definition interaction works as usual. List functions don't deal well with the implicit return generated by CoffeeScript, but J Chris says, this will be easy to fix. The patch adds CoffeeScript 1.1.1 which is MIT licensed and updates the NOTICE, LICENSE, license.skip and .gitignore files as well as the build system accordingly. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@1129600 13f79535-47bb-0310-9956-ffa450edef68
- Loading branch information
Showing
10 changed files
with
136 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
// use this file except in compliance with the License. You may obtain a copy of | ||
// the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
// License for the specific language governing permissions and limitations under | ||
// the License. | ||
|
||
// test basic coffeescript functionality | ||
couchTests.coffee = function(debug) { | ||
var db = new CouchDB("test_suite_db", {"X-Couch-Full-Commit":"false"}); | ||
db.deleteDb(); | ||
db.createDb(); | ||
if (debug) debugger; | ||
|
||
var ddoc = { | ||
_id: "_design/coffee", | ||
language: "coffeescript", | ||
views: { | ||
myview: { | ||
map: '(doc) -> if doc.foo\n emit(doc.foo, 1)', | ||
reduce: '(keys, values, rereduce) ->\n sum = 0\n for x in values\n sum = sum + x\n sum' | ||
} | ||
}, | ||
shows: { | ||
myshow: '(doc) ->\n "Foo #{doc.foo}"' | ||
}, | ||
lists: { | ||
mylist: '(head, req) ->\n while row = getRow()\n send("Foo #{row.value}")\n return "Foo"' | ||
}, | ||
filters: { | ||
filter: "(doc) ->\n doc.foo" | ||
} | ||
}; | ||
|
||
db.save(ddoc); | ||
|
||
var docs = [ | ||
{_id:"a", foo: 100}, | ||
{foo:1}, | ||
{foo:1}, | ||
{foo:2}, | ||
{foo:2}, | ||
{bar:1}, | ||
{bar:1}, | ||
{bar:2}, | ||
{bar:2} | ||
]; | ||
|
||
db.bulkSave(docs); | ||
|
||
var res = db.view("coffee/myview"); | ||
TEquals(5, res.rows[0].value, "should sum up values"); | ||
|
||
var res = CouchDB.request("GET", "/" + db.name + "/_design/coffee/_show/myshow/a"); | ||
TEquals("Foo 100", res.responseText, "should show 100"); | ||
|
||
var res = CouchDB.request("GET", "/" + db.name + "/_design/coffee/_list/mylist/myview"); | ||
TEquals("Foo 5Foo", res.responseText, "should list"); | ||
|
||
var changes = db.changes({filter: "coffee/filter"}); | ||
TEquals(5, changes.results.length, "should have changes"); | ||
}; |