Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

load only needed libaries from the ddoc

  • Loading branch information...
commit 1e8cfbaf587374d5dbca0859f9e6b0e6e1204370 1 parent 6a17e98
@jchris jchris authored
View
20 shows/app.js
@@ -1,21 +1,5 @@
function(doc, req) {
- // make this a commonjs module so you can inline the ddoc in the html
- // only return the parts of the app that we use
- var i, j, path, key, obj, ref, out = {}, ddoc = this,
- resources = ddoc.couchapp && ddoc.couchapp.load && ddoc.couchapp.load.app || [];
- for (i=0; i < resources.length; i++) {
- path = resources[i].split('/');
- obj = ddoc;
- ref = out;
- for (j=0; j < path.length; j++) {
- key = path[j];
- ref[key] = ref[key] || {};
- if (j < path.length - 1) {
- obj = obj[key];
- ref = ref[key];
- }
- };
- ref[key] = obj[key];
+ return {
+ json : require("vendor/couchapp/lib/code").ddoc(this)
};
- return {json : out};
};
View
1  templates/page.html
@@ -23,6 +23,7 @@
opts.db = "pages";
opts.design = "pages";
};
+ opts.code = "_show/app";
$.couch.app(function(app) {
$("#account").evently("account", app);
$("#profile").evently("profile", app);
View
14 vendor/couchapp/_attachments/jquery.couch.app.js
@@ -20,8 +20,13 @@
(function($) {
- function Design(db, name) {
+ function Design(db, name, code) {
this.doc_id = "_design/"+name;
+ if (code) {
+ this.code_path = this.doc_id + "/" + code;
+ } else {
+ this.code_path = this.doc_id;
+ }
this.view = function(view, opts) {
db.view(name+'/'+view, opts);
};
@@ -128,7 +133,7 @@
dname = opts.design || fragments[index + 4];
$.couch.urlPrefix = urlPrefix;
var db = $.couch.db(dbname),
- design = new Design(db, dname);
+ design = new Design(db, dname, opts.code);
var appExports = $.extend({
db : db,
design : design,
@@ -153,7 +158,8 @@
$.couch.app.ddoc_handlers[design.doc_id].push(handleDDoc);
} else {
$.couch.app.ddoc_handlers[design.doc_id] = [handleDDoc];
- db.openDoc(design.doc_id, {
+ // use getDbProperty to bypass %2F encoding on _show/app
+ db.getDbProperty(design.code_path, {
success : function(doc) {
$.couch.app.ddocs[design.doc_id] = doc;
$.couch.app.ddoc_handlers[design.doc_id].forEach(function(h) {
@@ -170,7 +176,7 @@
});
}
}
- };
+ };
$.couch.app.ddocs = {};
$.couch.app.ddoc_handlers = {};
// legacy support. $.CouchApp is deprecated, please use $.couch.app
View
20 vendor/couchapp/lib/code.js
@@ -0,0 +1,20 @@
+exports.ddoc = function(ddoc) {
+ // only return the parts of the app that we use
+ var i, j, path, key, obj, ref, out = {},
+ resources = ddoc.couchapp && ddoc.couchapp.load && ddoc.couchapp.load.app || [];
+ for (i=0; i < resources.length; i++) {
+ path = resources[i].split('/');
+ obj = ddoc;
+ ref = out;
+ for (j=0; j < path.length; j++) {
+ key = path[j];
+ ref[key] = ref[key] || {};
+ if (j < path.length - 1) {
+ obj = obj[key];
+ ref = ref[key];
+ }
+ };
+ ref[key] = obj[key];
+ };
+ return out;
+};
Please sign in to comment.
Something went wrong with that request. Please try again.