Exemplo n.º 1
0
  return through.obj(function (file, enc, cb) {
    var ddocObj = require(file.path)
    var url = /^https?:\/\//.test(dbName) ? dbName : buildURL(dbName, opts);

    if (file.isNull()) {
      return cb(null, file)
    }

    if (file.isStream()) {
      this.emit('error', new PluginError(PLUGIN_NAME, 'Streaming not supported.'))
      return cb(null, file)
    }

    if (path.extname(file.path) !== '.js') {
      this.emit('error', new PluginError(PLUGIN_NAME, 'File extension not supported.'))
      return cb(null, file)
    }

    if (has(opts, 'attachments')) {
      var attachmentsPath = path.join(process.cwd(), path.normalize(opts.attachments))
      couchapp.loadAttachments(ddocObj, attachmentsPath)
    }

    couchapp.createApp(ddocObj, url, function (app) {
      app.push(function () {
        gutil.log(PLUGIN_NAME, 'Couchapp pushed!')
        return cb(null, file)
      })
    })
  })
Exemplo n.º 2
0
Arquivo: app.js Projeto: jhs/mikeal.js
  , path = require('path')
  ;

ddoc = { _id:'_design/app'
  , rewrites : [
        {from:"/", to:'index.html'}
      , {from:"/new", to:'index.html'}
      , {from:"/edit/*", to:'index.html'}
      , {from:"/post/*", to:'index.html'}
      , {from:"/2010/*", to:'index.html'}
      , {from:"/2009/*", to:'index.html'}
      , {from:"/2008/*", to:'index.html'}
      , {from:"/api", to:'../../'}
      , {from:"/api/*", to:'../../*'}
      , {from:"/*", to:'*'}
    ]
  }

ddoc.views = {postsByCreated: {map: function (doc) {
  if (doc.type == 'blogpost') emit(doc.created, 1);
}}}

ddoc.validate_doc_update = function (newDoc, oldDoc, userCtx) {   
  if (newDoc._deleted === true && userCtx.roles.indexOf('_admin') === -1) {     
    throw "Only admin can delete documents on this database."   
  } 
}

couchapp.loadAttachments(ddoc, path.join(__dirname, 'attachments'))

module.exports = ddoc
Exemplo n.º 3
0
ddoc = {
    _id: '_design/champ',
    views: champ_views,
    lists: {},
    shows: {},
    rewrites: [
        { "description": "Access to this database" , "from": "_db" , "to"  : "../.." },
        { "from": "_db/*" , "to"  : "../../*" },
        { "description": "Access to this design document" , "from": "_ddoc" , "to"  : "" },
        { "from": "_ddoc/*" , "to"  : "*"},
        {"from": "/", "to": "index.html"},
        {"from": "/*", "to": "*"}
    ],
    filters: {
        just_file_docs: function(doc, req) {
            if (doc._attachments && doc._attachments['file.mp3']) {
                if (req.query && req.query.doc_id && req.query.doc_id === doc._id) {
                    return true;
                }
            }
            return false;
        }
    }
  };

module.exports = ddoc;


couchapp.loadAttachments(ddoc, __dirname);
Exemplo n.º 4
0
                emit(word, stems[word]);
            }
        }
    },
    reduce: "_sum"
};


ddoc.validate_doc_update = function (newDoc, oldDoc, userCtx) {   
  if (newDoc._deleted === true && userCtx.roles.indexOf('_admin') === -1) {
    throw "Only admin can delete documents on this database.";
  } 
}

// Load normal attachments.
couchapp.loadAttachments(ddoc, path.join(__dirname, 'attachments'));

// Load templates as a single attachment.
couchapp.loadAttachments(ddoc, path.join(__dirname, 'templates'), {
    operators: [function(f, data) {
        if (path.extname(f) === '._') {
            try {
                var t= ';;'
                t+= 'templates.'+ path.basename(f, '._') + '=';
                t+= _.template(data.toString('utf8'));
                return new Buffer(t);
            }
            catch(e) {
                console.log(e);
                console.log("ERROR: failed to transform template: "+f);
            }
  }
  return false;
};
// filter type Thing, i.e. anything for now!
ddoc.filters.changesContent = function(doc) {
  // include deleted?! (in _changes)
  var type = null;
  var ix = doc._id.indexOf(':');
  if (ix > 0) {
    type = doc._id.substring(0,ix);
  }
  if (type && type !== 'taskstate' && type!=='taskconfig') {
    return true;
  }
  return false;
};

ddoc.validate_doc_update = function (newDoc, oldDoc, userCtx) {
  function user_is(role) {
    return userCtx.roles.indexOf(role) >= 0;
  }
  if (user_is('hubwriter') && newDoc && newDoc._id && newDoc._id.indexOf('_design/')==0)
    throw({forbidden : "Hubwriter "+userCtx.name+" cannot change design document: " + newDoc._id});
  if (user_is('hubreader'))
    throw({forbidden : "Hubreader "+userCtx.name+" cannot update documents: " + newDoc._id}); 
};

couchapp.loadAttachments(ddoc, path.join(__dirname, '_attachments'));
couchapp.loadAttachments(ddoc, path.join(__dirname, '../public'));

Exemplo n.º 6
0
      var gname = "";
      if(doc.name){
        gname = doc.name;
      }
      emit(null, {"rev":doc._rev, "name":gname});
    }
  }
}

ddoc.views.lastmove = {
  map: function(doc) {
    if(doc.type && doc.type == "move") {
      emit([doc.game, doc.move],
           { "done":doc.done,
             "from":doc.from,
             "to":doc.to,
             "piece":doc.piece,
             "capture":doc.capture,
             "castle":doc.castle,
             "promotion":doc.promotion
           }
          );
    }
  }
}

module.exports = ddoc;
dapath = path.join(__dirname, "_attachments");

couchapp.loadAttachments(ddoc, dapath);
Exemplo n.º 7
0
Arquivo: app.js Projeto: mikeal/reki
var ddoc = {_id:"_design/app", shows:{}, lists:{}, views:{index:{},byUser:{}},
            modules:{}, templates:{}}

ddoc.rewrites = [
  { from: "/:page", to:"_list/page/index", method: "GET", 
    query: {startkey:[":page"], endkey:[":page", null]} },
]

ddoc.views.index.map = function (doc) {
  if (doc.pageid) { emit(doc.pageid, 1) }
}

ddoc.lists.page = function (head, req) {
  start({"code": 200, "headers": {"content-type":"text/html"}})
  var row;
  var mustache = require('modules/mustache').Mustache;
  var v = {pagedoc:getRow(), pageid:req.query.startkey, pagetitle:req.query.startkey.join('/')};
  if (!v.pagedoc) { v.newPage = true } else { v.newPage = false}
  v.index = [v.pagedoc];
  while(row = getRow()) {
    v.index.push(row.value);
  }
  var p = mustache.to_html(this.templates['page.mustache'], v);
  send(p);
}

couchapp.loadModules(ddoc.modules, path.join(__dirname, 'modules'));
couchapp.loadFiles(ddoc.templates, path.join(__dirname, 'templates'));
couchapp.loadAttachments(ddoc, path.join(__dirname, 'static'));
exports.app = ddoc;
Exemplo n.º 8
0
// License for the specific language governing permissions and limitations under
// the License.

var couchapp = require('couchapp'),
    path = require('path'),
    ddoc;

ddoc = {
  _id: '_design/fauxton',
  rewrites: [
    { "from": "_db",     "to"  : "../.." },
    { "from": "_db/*",   "to"  : "../../*" },
    { "from": "_ddoc",   "to"  : "" },
    { "from": "_ddoc/*", "to"  : "*"},
    {from: '/', to: 'index.html'},
    {from: '/*', to: '*'}
  ],
  views: {},
  shows: {},
  lists: {},
  validate_doc_update: function () {
    /*if (newDoc._deleted === true && userCtx.roles.indexOf('_admin') === -1) {
      throw "Only admin can delete documents on this database.";
    }*/
  }
};


couchapp.loadAttachments(ddoc, path.join(__dirname, 'dist', 'release'));
module.exports = ddoc;
Exemplo n.º 9
0
// A short DSL for uploading attachments
function upload(dirpath, prefix) {
  couchapp.loadAttachments(ddoc, path.join(__dirname, dirpath), prefix)
}
Exemplo n.º 10
0
		"lib/base.js",
		
		"lib/bootstrap/js/bootstrap.js",
		
		"lib/app.js"
	],
	cssFiles = [
		"lib/bootstrap/css/bootstrap.css",
		"lib/bootstrap/css/bootstrap-responsive.css"
	];


/**
 * Load attachments
 */
couchapp.loadAttachments(designDocument, attachmentsPath);


/**
 * Load Templates
 */
designDocument.templates = couchapp.loadFiles(path.join(__dirname, 'templates'));


/**
 * Load components (templates)
 */
fs.readdirSync(componentsPath).forEach(function (component) {
	"use strict";
	var templatePath = path.join(componentsPath, component, 'templates');
	if (path.existsSync(templatePath)) {
Exemplo n.º 11
0
    function validateType(t, types) {
        function invalidType() {
            throw({forbidden: "Invalid type: " + t});
        }

        var fn = types[t] || invalidType;
        fn();
    }
};

// Filter that return only run requests
design.filters.run_request = function(doc, req) {
    return doc.type === "run" && !doc.hasOwnProperty("result");
};

// Filter that return only run results
design.filters.run_result = function(doc, req) {
    if (req.query.id) {
        return doc._id === req.query.id;
    }
    return doc.type === "run" && doc.hasOwnProperty("result");
};

// CryptoJS.SHA1 wrapped as a CommonJS module
design.lib.cryptojs = "module.exports.sha1 = function(input) {\n    /*\n    CryptoJS v3.1.2\n    code.google.com/p/crypto-js\n    (c) 2009-2013 by Jeff Mott. All rights reserved.\n    code.google.com/p/crypto-js/wiki/License\n    */\n    var CryptoJS=CryptoJS||function(e,m){var p={},j=p.lib={},l=function(){},f=j.Base={extend:function(a){l.prototype=this;var c=new l;a&&c.mixIn(a);c.hasOwnProperty(\"init\")||(c.init=function(){c.$super.init.apply(this,arguments)});c.init.prototype=c;c.$super=this;return c},create:function(){var a=this.extend();a.init.apply(a,arguments);return a},init:function(){},mixIn:function(a){for(var c in a)a.hasOwnProperty(c)&&(this[c]=a[c]);a.hasOwnProperty(\"toString\")&&(this.toString=a.toString)},clone:function(){return this.init.prototype.extend(this)}},\n    n=j.WordArray=f.extend({init:function(a,c){a=this.words=a||[];this.sigBytes=c!=m?c:4*a.length},toString:function(a){return(a||h).stringify(this)},concat:function(a){var c=this.words,q=a.words,d=this.sigBytes;a=a.sigBytes;this.clamp();if(d%4)for(var b=0;b<a;b++)c[d+b>>>2]|=(q[b>>>2]>>>24-8*(b%4)&255)<<24-8*((d+b)%4);else if(65535<q.length)for(b=0;b<a;b+=4)c[d+b>>>2]=q[b>>>2];else c.push.apply(c,q);this.sigBytes+=a;return this},clamp:function(){var a=this.words,c=this.sigBytes;a[c>>>2]&=4294967295<<\n    32-8*(c%4);a.length=e.ceil(c/4)},clone:function(){var a=f.clone.call(this);a.words=this.words.slice(0);return a},random:function(a){for(var c=[],b=0;b<a;b+=4)c.push(4294967296*e.random()|0);return new n.init(c,a)}}),b=p.enc={},h=b.Hex={stringify:function(a){var c=a.words;a=a.sigBytes;for(var b=[],d=0;d<a;d++){var f=c[d>>>2]>>>24-8*(d%4)&255;b.push((f>>>4).toString(16));b.push((f&15).toString(16))}return b.join(\"\")},parse:function(a){for(var c=a.length,b=[],d=0;d<c;d+=2)b[d>>>3]|=parseInt(a.substr(d,\n    2),16)<<24-4*(d%8);return new n.init(b,c/2)}},g=b.Latin1={stringify:function(a){var c=a.words;a=a.sigBytes;for(var b=[],d=0;d<a;d++)b.push(String.fromCharCode(c[d>>>2]>>>24-8*(d%4)&255));return b.join(\"\")},parse:function(a){for(var c=a.length,b=[],d=0;d<c;d++)b[d>>>2]|=(a.charCodeAt(d)&255)<<24-8*(d%4);return new n.init(b,c)}},r=b.Utf8={stringify:function(a){try{return decodeURIComponent(escape(g.stringify(a)))}catch(c){throw Error(\"Malformed UTF-8 data\");}},parse:function(a){return g.parse(unescape(encodeURIComponent(a)))}},\n    k=j.BufferedBlockAlgorithm=f.extend({reset:function(){this._data=new n.init;this._nDataBytes=0},_append:function(a){\"string\"==typeof a&&(a=r.parse(a));this._data.concat(a);this._nDataBytes+=a.sigBytes},_process:function(a){var c=this._data,b=c.words,d=c.sigBytes,f=this.blockSize,h=d/(4*f),h=a?e.ceil(h):e.max((h|0)-this._minBufferSize,0);a=h*f;d=e.min(4*a,d);if(a){for(var g=0;g<a;g+=f)this._doProcessBlock(b,g);g=b.splice(0,a);c.sigBytes-=d}return new n.init(g,d)},clone:function(){var a=f.clone.call(this);\n    a._data=this._data.clone();return a},_minBufferSize:0});j.Hasher=k.extend({cfg:f.extend(),init:function(a){this.cfg=this.cfg.extend(a);this.reset()},reset:function(){k.reset.call(this);this._doReset()},update:function(a){this._append(a);this._process();return this},finalize:function(a){a&&this._append(a);return this._doFinalize()},blockSize:16,_createHelper:function(a){return function(c,b){return(new a.init(b)).finalize(c)}},_createHmacHelper:function(a){return function(b,f){return(new s.HMAC.init(a,\n    f)).finalize(b)}}});var s=p.algo={};return p}(Math);\n    (function(){var e=CryptoJS,m=e.lib,p=m.WordArray,j=m.Hasher,l=[],m=e.algo.SHA1=j.extend({_doReset:function(){this._hash=new p.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(f,n){for(var b=this._hash.words,h=b[0],g=b[1],e=b[2],k=b[3],j=b[4],a=0;80>a;a++){if(16>a)l[a]=f[n+a]|0;else{var c=l[a-3]^l[a-8]^l[a-14]^l[a-16];l[a]=c<<1|c>>>31}c=(h<<5|h>>>27)+j+l[a];c=20>a?c+((g&e|~g&k)+1518500249):40>a?c+((g^e^k)+1859775393):60>a?c+((g&e|g&k|e&k)-1894007588):c+((g^e^\n    k)-899497514);j=k;k=e;e=g<<30|g>>>2;g=h;h=c}b[0]=b[0]+h|0;b[1]=b[1]+g|0;b[2]=b[2]+e|0;b[3]=b[3]+k|0;b[4]=b[4]+j|0},_doFinalize:function(){var f=this._data,e=f.words,b=8*this._nDataBytes,h=8*f.sigBytes;e[h>>>5]|=128<<24-h%32;e[(h+64>>>9<<4)+14]=Math.floor(b/4294967296);e[(h+64>>>9<<4)+15]=b;f.sigBytes=4*e.length;this._process();return this._hash},clone:function(){var e=j.clone.call(this);e._hash=this._hash.clone();return e}});e.SHA1=j._createHelper(m);e.HmacSHA1=j._createHmacHelper(m)})();\n\n    return CryptoJS.SHA1(input).toString();\n};\n";

couchapp.loadAttachments(design, path.join(__dirname, 'app'));

module.exports = design;