Вход Регистрация
Файл: error-kitty/node_modules/express/lib/view.js
Строк: 108
<?php
/**
 * Module dependencies.
 */

var path = require('path');
var 
fs = require('fs');
var 
utils = require('./utils');
var 
dirname path.dirname;
var 
basename path.basename;
var 
extname path.extname;
var 
exists fs.existsSync || path.existsSync;
var 
join path.join;

/**
 * Expose `View`.
 */

module.exports View;

/**
 * Initialize a new `View` with the given `name`.
 *
 * Options:
 *
 *   - `defaultEngine` the default template engine name
 *   - `engines` template engine require() cache
 *   - `root` root path for view lookup
 *
 * @param {String} name
 * @param {Object} options
 * @api private
 */

function View(nameoptions) {
  
options options || {};
  
this.name name;
  
this.root options.root;
  var 
engines options.engines;
  
this.defaultEngine options.defaultEngine;
  var 
ext this.ext extname(name);
  if (!
ext && !this.defaultEngine) throw new Error('No default engine was specified and no extension was provided.');
  if (!
extname += (ext this.ext = ('.' != this.defaultEngine[0] ? '.' '') + this.defaultEngine);
  
this.engine engines[ext] || (engines[ext] = require(ext.slice(1)).__express);
  
this.path this.lookup(name);
}

/**
 * Lookup view by the given `path`
 *
 * @param {String} path
 * @return {String}
 * @api private
 */

View.prototype.lookup = function(path){
  var 
ext this.ext;

  
// <path>.<engine>
  
if (!utils.isAbsolute(path)) path join(this.rootpath);
  if (
exists(path)) return path;

  
// <path>/index.<engine>
  
path join(dirname(path), basename(pathext), 'index' ext);
  if (
exists(path)) return path;
};

/**
 * Render with the given `options` and callback `fn(err, str)`.
 *
 * @param {Object} options
 * @param {Function} fn
 * @api private
 */

View.prototype.render = function(optionsfn){
  
this.engine(this.pathoptionsfn);
};
?>
Онлайн: 4
Реклама