mikeal / node.couchapp.js

Utility for writing couchapps.
Apache License 2.0
406 stars 78 forks source link

support for !json and !code macros #33

Closed cmadsen closed 12 years ago

cmadsen commented 12 years ago

couchapp support two "macros" for doing server side includes. See http://guide.couchdb.org/draft/show.html

eg:

function(doc, req) {
  // !json templates.edit
  // !json blog
 // !code vendor/couchapp/path.js
 // !code vendor/couchapp/template.js

It would very convenient if there was support for this

max-mapper commented 12 years ago

FYI you can also use commonjs

cmadsen commented 12 years ago

Ok. I did

ddoc.sharedJS = {
    stringzone : exports.myFunc = function(){return 'plankton';}
}

ddoc.lists.mylist = function(head, req) {
    var xxx = require('sharedJS/stringzone').myFunc;
        xxx();

But this only works if I do

ddoc.sharedJS = {
    stringzone : "exports.myFunc = function(){return 'plankton';}"
}

So do I have to format my commonJS stuff as one liners to include them in app.js?

max-mapper commented 12 years ago

nope you can use loadFiles

https://github.com/maxogden/monocles/blob/master/app.js#L240

https://github.com/maxogden/monocles/blob/master/app.js#L175

lmatteis commented 12 years ago

This is fine for evaluating JavaScript CommonJS code, but what about if you simply want to access an html template that was loaded using loadFiles? Sort of what !json does.