Example #1
0
    Object.keys(routes).forEach(function(key) {
        var args = routes[key]
            , methodPath = key.split(' ')
            , methodStr = methodPath[0].toUpperCase()
            , path = methodPath[1]
            , methods = methodStr.split(',')
            ;

        if (is.isArray(args)) {
            args.unshift(path);
        } else {
            args = [path, args];
        }

        methods.forEach(function(method){
            switch (method) {
                case 'GET':
                    app.get.apply(app, args);
                    break;
                case 'POST':
                    app.post.apply(app, args);
                    break;
                case 'PUT':
                    app.put.apply(app, args);
                    break;
                case 'DELETE':
                    app.delete.apply(app, args);
                    break;
                case 'ALL':
                    app.get.apply(app, args);
                    app.post.apply(app, args);
                    app.put.apply(app, args);
                    app.delete.apply(app, args);
                    break;
                default:
                    throw new Error('Invalid HTTP method specified for route ' + path);
                    process.exit(1);
                    break;
            }
        });
    });
Example #2
0
module.exports = function(keys){
    if(is.isString(keys)){
        keys = keys.split(/ +/);
    }
    if(!is.isArray(keys)){
        throw new Error('attr array error');
        process.exit(1);
    }
    return function(files, metalsmith, done){
        Object.keys(files).forEach(function(name){
            var file = files[name];

            Object.keys(file).forEach(function(key){
                if(keys.indexOf(key) == -1){
                    delete file[key];
                }
            });
        });
        done();
    };
};