lib/view-lookup.js
function patchView (ExpressView, opts) {
    var proto = ExpressView.prototype;
    function View (name, options) {
        options = options || {};
        this.name = name;
        this.root = options.root;
        var engines = options.engines;
        this.defaultEngine = options.defaultEngine;
        var extensions = (typeof opts.extensions === 'function') ? opts.extensions() : opts.extensions;
        this.extensions = extensions;
        var ext = this.ext = extname(name, extensions);
        if (!ext && !this.defaultEngine) {
            throw Error('No default engine was specified and no extension was provided.');
        }
        if (!ext) {
            name += (ext = this.ext = (this.defaultEngine[0] !== '.' ? '.' : '') + this.defaultEngine);
        }
        this.engine = engines[ext] || (engines[ext] = require(ext.slice(1)).__express);
        this.path = this.lookup(name);
    }
    View.prototype = proto;

    function extname (name, extensions) {
        if (Array.isArray(extensions) && extensions.length > 0) {
            var ext;
            for (var i = 0, l = extensions.length; i < l; i += 1) {
                ext = extensions[i];
                if (typeof name === 'string' && name.indexOf(ext) !== -1) {
                    return ext;
                }
            }
        }
        return PATH.extname(name);
    }

    // replace original with new our own
    proto.lookup = createLookup(proto.lookup, opts);

    return View;
}
function patchView (ExpressView, opts) {
    var proto = ExpressView.prototype;
    function View (name, options) {
        options = options || {};
        this.name = name;
        this.root = options.root;
        var engines = options.engines;
        this.defaultEngine = options.defaultEngine;
        var extensions = (typeof opts.extensions === 'function') ? opts.extensions() : opts.extensions;
        this.extensions = extensions;
        var ext = this.ext = extname(name, extensions);
        if (!ext && !this.defaultEngine) {
            throw Error('No default engine was specified and no extension was provided.');
        }
        if (!ext) {
            name += (ext = this.ext = (this.defaultEngine[0] !== '.' ? '.' : '') + this.defaultEngine);
        }
        this.engine = engines[ext] || (engines[ext] = require(ext.slice(1)).__express);
        this.path = this.lookup(name);
    }
    View.prototype = proto;

    function extname (name, extensions) {
        if (Array.isArray(extensions) && extensions.length > 0) {
            var ext;
            for (var i = 0, l = extensions.length; i < l; i += 1) {
                ext = extensions[i];
                if (typeof name === 'string' && name.indexOf(ext) !== -1) {
                    return ext;
                }
            }
        }
        return PATH.extname(name);
    }

    // replace original with new our own
    proto.lookup = createLookup(proto.lookup, opts);

    return View;
}
function patchView ( ExpressView , opts ) { var proto = ExpressView . prototype ; function View ( name , options ) { options = options || { } ; this . name = name ; this . root = options . root ; var engines = options . engines ; this . defaultEngine = options . defaultEngine ; var extensions = ( typeof opts . extensions === 'function' ) ? opts . extensions ( ) : opts . extensions ; this . extensions = extensions ; var ext = this . ext = extname ( name , extensions ) ; if ( ! ext && ! this . defaultEngine ) { throw Error ( 'No default engine was specified and no extension was provided.' ) ; } if ( ! ext ) { name += ( ext = this . ext = ( this . defaultEngine [ 0 ] !== '.' ? '.' : '' ) + this . defaultEngine ) ; } this . engine = engines [ ext ] || ( engines [ ext ] = require ( ext . slice ( 1 ) ) . __express ) ; this . path = this . lookup ( name ) ; } View . prototype = proto ; function extname ( name , extensions ) { if ( Array . isArray ( extensions ) && extensions . length > 0 ) { var ext ; for ( var i = 0 , l = extensions . length ; i < l ; i += 1 ) { ext = extensions [ i ] ; if ( typeof name === 'string' && name . indexOf ( ext ) !== - 1 ) { return ext ; } } } return PATH . extname ( name ) ; } // replace original with new our own proto . lookup = createLookup ( proto . lookup , opts ) ; return View ; }
Patches express view to lookup in another directories
@api
@param {Function} ExpressView
@param {{path: String, extensions: String[]|Function}} opts
Patches express view to lookup in another directories