Browse files

ddoc is embedded in the html

  • Loading branch information...
1 parent 1e8cfba commit db1860143cfd7d3ff85a97a0d5058c90ae9ea09f @jchris jchris committed Aug 23, 2010
Showing with 12 additions and 2 deletions.
  1. +5 −0 shows/page.js
  2. +1 −1 templates/page.html
  3. +6 −1 vendor/couchapp/_attachments/jquery.couch.app.js
View
5 shows/page.js
@@ -1,8 +1,13 @@
function(doc, req) {
+ var code = require("vendor/couchapp/lib/code").ddoc(this),
+ ddoc_code = JSON.stringify(code);
+ // top two lines have to come first or else parent references in the ddoc
+ // which are created by calls to require will break JSON.stringify.
var name, stub, ddoc = this,
mustache = require("vendor/couchapp/lib/mustache"),
wiki = require("lib/wiki"),
data = {
+ ddoc : ddoc_code,
docid : JSON.stringify(req.id),
id : req.id,
path : "../page/"+req.id,
View
2 templates/page.html
@@ -23,7 +23,7 @@
opts.db = "pages";
opts.design = "pages";
};
- opts.code = "_show/app";
+ opts.ddoc = {{{ddoc}}};
$.couch.app(function(app) {
$("#account").evently("account", app);
$("#profile").evently("profile", app);
View
7 vendor/couchapp/_attachments/jquery.couch.app.js
@@ -133,7 +133,7 @@
dname = opts.design || fragments[index + 4];
$.couch.urlPrefix = urlPrefix;
var db = $.couch.db(dbname),
- design = new Design(db, dname, opts.code);
+ design = new Design(db, dname, opts.load_path);
var appExports = $.extend({
db : db,
design : design,
@@ -149,6 +149,11 @@
}
appFun.apply(appExports, [appExports]);
}
+ if (opts.ddoc) {
+ // allow the ddoc to be embedded in the html
+ // to avoid a second http request
+ $.couch.app.ddocs[design.doc_id] = opts.ddoc;
+ }
if ($.couch.app.ddocs[design.doc_id]) {
$(function() {handleDDoc($.couch.app.ddocs[design.doc_id])});
} else {

0 comments on commit db18601

Please sign in to comment.