diff options
| author | Teddy Wing | 2013-04-27 19:25:40 -0400 | 
|---|---|---|
| committer | Teddy Wing | 2013-04-27 19:25:56 -0400 | 
| commit | 512e8b2da71de59132a29e80d7359ac843d62f07 (patch) | |
| tree | 3f5024a4f75072eda45713dcd429a0b58bf969b9 /node_modules/ejs/lib | |
| parent | 4b14305623d5ddc59f435fc5e35c54c0def1d392 (diff) | |
| download | Who-am-I-512e8b2da71de59132a29e80d7359ac843d62f07.tar.bz2 | |
Untrack ./node_modules
Sorry, my bad for not ignoring it initially.
Diffstat (limited to 'node_modules/ejs/lib')
| -rw-r--r-- | node_modules/ejs/lib/ejs.js | 342 | ||||
| -rw-r--r-- | node_modules/ejs/lib/filters.js | 198 | ||||
| -rw-r--r-- | node_modules/ejs/lib/utils.js | 23 | 
3 files changed, 0 insertions, 563 deletions
| diff --git a/node_modules/ejs/lib/ejs.js b/node_modules/ejs/lib/ejs.js deleted file mode 100644 index a7a5d0d..0000000 --- a/node_modules/ejs/lib/ejs.js +++ /dev/null @@ -1,342 +0,0 @@ - -/*! - * EJS - * Copyright(c) 2012 TJ Holowaychuk <tj@vision-media.ca> - * MIT Licensed - */ - -/** - * Module dependencies. - */ - -var utils = require('./utils') -  , path = require('path') -  , basename = path.basename -  , dirname = path.dirname -  , extname = path.extname -  , join = path.join -  , fs = require('fs') -  , read = fs.readFileSync; - -/** - * Filters. - *  - * @type Object - */ - -var filters = exports.filters = require('./filters'); - -/** - * Intermediate js cache. - *  - * @type Object - */ - -var cache = {}; - -/** - * Clear intermediate js cache. - * - * @api public - */ - -exports.clearCache = function(){ -  cache = {}; -}; - -/** - * Translate filtered code into function calls. - * - * @param {String} js - * @return {String} - * @api private - */ - -function filtered(js) { -  return js.substr(1).split('|').reduce(function(js, filter){ -    var parts = filter.split(':') -      , name = parts.shift() -      , args = parts.shift() || ''; -    if (args) args = ', ' + args; -    return 'filters.' + name + '(' + js + args + ')'; -  }); -}; - -/** - * Re-throw the given `err` in context to the - * `str` of ejs, `filename`, and `lineno`. - * - * @param {Error} err - * @param {String} str - * @param {String} filename - * @param {String} lineno - * @api private - */ - -function rethrow(err, str, filename, lineno){ -  var lines = str.split('\n') -    , start = Math.max(lineno - 3, 0) -    , end = Math.min(lines.length, lineno + 3); - -  // Error context -  var context = lines.slice(start, end).map(function(line, i){ -    var curr = i + start + 1; -    return (curr == lineno ? ' >> ' : '    ') -      + curr -      + '| ' -      + line; -  }).join('\n'); - -  // Alter exception message -  err.path = filename; -  err.message = (filename || 'ejs') + ':'  -    + lineno + '\n'  -    + context + '\n\n'  -    + err.message; -   -  throw err; -} - -/** - * Parse the given `str` of ejs, returning the function body. - * - * @param {String} str - * @return {String} - * @api public - */ - -var parse = exports.parse = function(str, options){ -  var options = options || {} -    , open = options.open || exports.open || '<%' -    , close = options.close || exports.close || '%>' -    , filename = options.filename -    , compileDebug = options.compileDebug !== false -    , buf = []; - -  buf.push('var buf = [];'); -  if (false !== options._with) buf.push('\nwith (locals || {}) {'); -  buf.push('\n buf.push(\''); - -  var lineno = 1; - -  var consumeEOL = false; -  for (var i = 0, len = str.length; i < len; ++i) { -    if (str.slice(i, open.length + i) == open) { -      i += open.length -   -      var prefix, postfix, line = (compileDebug ? '__stack.lineno=' : '') + lineno; -      switch (str.substr(i, 1)) { -        case '=': -          prefix = "', escape((" + line + ', '; -          postfix = ")), '"; -          ++i; -          break; -        case '-': -          prefix = "', (" + line + ', '; -          postfix = "), '"; -          ++i; -          break; -        default: -          prefix = "');" + line + ';'; -          postfix = "; buf.push('"; -      } - -      var end = str.indexOf(close, i) -        , js = str.substring(i, end) -        , start = i -        , include = null -        , n = 0; - -      if ('-' == js[js.length-1]){ -        js = js.substring(0, js.length - 2); -        consumeEOL = true; -      } - -      if (0 == js.trim().indexOf('include')) { -        var name = js.trim().slice(7).trim(); -        if (!filename) throw new Error('filename option is required for includes'); -        var path = resolveInclude(name, filename); -        include = read(path, 'utf8'); -        include = exports.parse(include, { filename: path, _with: false, open: open, close: close }); -        buf.push("' + (function(){" + include + "})() + '"); -        js = ''; -      } - -      while (~(n = js.indexOf("\n", n))) n++, lineno++; -      if (js.substr(0, 1) == ':') js = filtered(js); -      if (js) { -        if (js.lastIndexOf('//') > js.lastIndexOf('\n')) js += '\n'; -        buf.push(prefix, js, postfix); -      } -      i += end - start + close.length - 1; - -    } else if (str.substr(i, 1) == "\\") { -      buf.push("\\\\"); -    } else if (str.substr(i, 1) == "'") { -      buf.push("\\'"); -    } else if (str.substr(i, 1) == "\r") { -      buf.push(" "); -    } else if (str.substr(i, 1) == "\n") { -      if (consumeEOL) { -        consumeEOL = false; -      } else { -        buf.push("\\n"); -        lineno++; -      } -    } else { -      buf.push(str.substr(i, 1)); -    } -  } - -  if (false !== options._with) buf.push("');\n}\nreturn buf.join('');") -  else buf.push("');\nreturn buf.join('');"); - -  return buf.join(''); -}; - -/** - * Compile the given `str` of ejs into a `Function`. - * - * @param {String} str - * @param {Object} options - * @return {Function} - * @api public - */ - -var compile = exports.compile = function(str, options){ -  options = options || {}; -   -  var input = JSON.stringify(str) -    , compileDebug = options.compileDebug !== false -    , client = options.client -    , filename = options.filename -        ? JSON.stringify(options.filename) -        : 'undefined'; -   -  if (compileDebug) { -    // Adds the fancy stack trace meta info -    str = [ -      'var __stack = { lineno: 1, input: ' + input + ', filename: ' + filename + ' };', -      rethrow.toString(), -      'try {', -      exports.parse(str, options), -      '} catch (err) {', -      '  rethrow(err, __stack.input, __stack.filename, __stack.lineno);', -      '}' -    ].join("\n"); -  } else { -    str = exports.parse(str, options); -  } -   -  if (options.debug) console.log(str); -  if (client) str = 'escape = escape || ' + utils.escape.toString() + ';\n' + str; - -  var fn = new Function('locals, filters, escape', str); - -  if (client) return fn; - -  return function(locals){ -    return fn.call(this, locals, filters, utils.escape); -  } -}; - -/** - * Render the given `str` of ejs. - * - * Options: - * - *   - `locals`          Local variables object - *   - `cache`           Compiled functions are cached, requires `filename` - *   - `filename`        Used by `cache` to key caches - *   - `scope`           Function execution context - *   - `debug`           Output generated function body - *   - `open`            Open tag, defaulting to "<%" - *   - `close`           Closing tag, defaulting to "%>" - * - * @param {String} str - * @param {Object} options - * @return {String} - * @api public - */ - -exports.render = function(str, options){ -  var fn -    , options = options || {}; - -  if (options.cache) { -    if (options.filename) { -      fn = cache[options.filename] || (cache[options.filename] = compile(str, options)); -    } else { -      throw new Error('"cache" option requires "filename".'); -    } -  } else { -    fn = compile(str, options); -  } - -  options.__proto__ = options.locals; -  return fn.call(options.scope, options); -}; - -/** - * Render an EJS file at the given `path` and callback `fn(err, str)`. - * - * @param {String} path - * @param {Object|Function} options or callback - * @param {Function} fn - * @api public - */ - -exports.renderFile = function(path, options, fn){ -  var key = path + ':string'; - -  if ('function' == typeof options) { -    fn = options, options = {}; -  } - -  options.filename = path; - -  try { -    var str = options.cache -      ? cache[key] || (cache[key] = read(path, 'utf8')) -      : read(path, 'utf8'); - -    fn(null, exports.render(str, options)); -  } catch (err) { -    fn(err); -  } -}; - -/** - * Resolve include `name` relative to `filename`. - * - * @param {String} name - * @param {String} filename - * @return {String} - * @api private - */ - -function resolveInclude(name, filename) { -  var path = join(dirname(filename), name); -  var ext = extname(name); -  if (!ext) path += '.ejs'; -  return path; -} - -// express support - -exports.__express = exports.renderFile; - -/** - * Expose to require(). - */ - -if (require.extensions) { -  require.extensions['.ejs'] = function(module, filename) { -    source = require('fs').readFileSync(filename, 'utf-8'); -    module._compile(compile(source, {}), filename); -  }; -} else if (require.registerExtension) { -  require.registerExtension('.ejs', function(src) { -    return compile(src, {}); -  }); -} diff --git a/node_modules/ejs/lib/filters.js b/node_modules/ejs/lib/filters.js deleted file mode 100644 index d425c8d..0000000 --- a/node_modules/ejs/lib/filters.js +++ /dev/null @@ -1,198 +0,0 @@ - -/*! - * EJS - Filters - * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca> - * MIT Licensed - */ - -/** - * First element of the target `obj`. - */ - -exports.first = function(obj) { -  return obj[0]; -}; - -/** - * Last element of the target `obj`. - */ - -exports.last = function(obj) { -  return obj[obj.length - 1]; -}; - -/** - * Capitalize the first letter of the target `str`. - */ - -exports.capitalize = function(str){ -  str = String(str); -  return str[0].toUpperCase() + str.substr(1, str.length); -}; - -/** - * Downcase the target `str`. - */ - -exports.downcase = function(str){ -  return String(str).toLowerCase(); -}; - -/** - * Uppercase the target `str`. - */ - -exports.upcase = function(str){ -  return String(str).toUpperCase(); -}; - -/** - * Sort the target `obj`. - */ - -exports.sort = function(obj){ -  return Object.create(obj).sort(); -}; - -/** - * Sort the target `obj` by the given `prop` ascending. - */ - -exports.sort_by = function(obj, prop){ -  return Object.create(obj).sort(function(a, b){ -    a = a[prop], b = b[prop]; -    if (a > b) return 1; -    if (a < b) return -1; -    return 0; -  }); -}; - -/** - * Size or length of the target `obj`. - */ - -exports.size = exports.length = function(obj) { -  return obj.length; -}; - -/** - * Add `a` and `b`. - */ - -exports.plus = function(a, b){ -  return Number(a) + Number(b); -}; - -/** - * Subtract `b` from `a`. - */ - -exports.minus = function(a, b){ -  return Number(a) - Number(b); -}; - -/** - * Multiply `a` by `b`. - */ - -exports.times = function(a, b){ -  return Number(a) * Number(b); -}; - -/** - * Divide `a` by `b`. - */ - -exports.divided_by = function(a, b){ -  return Number(a) / Number(b); -}; - -/** - * Join `obj` with the given `str`. - */ - -exports.join = function(obj, str){ -  return obj.join(str || ', '); -}; - -/** - * Truncate `str` to `len`. - */ - -exports.truncate = function(str, len){ -  str = String(str); -  return str.substr(0, len); -}; - -/** - * Truncate `str` to `n` words. - */ - -exports.truncate_words = function(str, n){ -  var str = String(str) -    , words = str.split(/ +/); -  return words.slice(0, n).join(' '); -}; - -/** - * Replace `pattern` with `substitution` in `str`. - */ - -exports.replace = function(str, pattern, substitution){ -  return String(str).replace(pattern, substitution || ''); -}; - -/** - * Prepend `val` to `obj`. - */ - -exports.prepend = function(obj, val){ -  return Array.isArray(obj) -    ? [val].concat(obj) -    : val + obj; -}; - -/** - * Append `val` to `obj`. - */ - -exports.append = function(obj, val){ -  return Array.isArray(obj) -    ? obj.concat(val) -    : obj + val; -}; - -/** - * Map the given `prop`. - */ - -exports.map = function(arr, prop){ -  return arr.map(function(obj){ -    return obj[prop]; -  }); -}; - -/** - * Reverse the given `obj`. - */ - -exports.reverse = function(obj){ -  return Array.isArray(obj) -    ? obj.reverse() -    : String(obj).split('').reverse().join(''); -}; - -/** - * Get `prop` of the given `obj`. - */ - -exports.get = function(obj, prop){ -  return obj[prop]; -}; - -/** - * Packs the given `obj` into json string - */ -exports.json = function(obj){ -  return JSON.stringify(obj); -};
\ No newline at end of file diff --git a/node_modules/ejs/lib/utils.js b/node_modules/ejs/lib/utils.js deleted file mode 100644 index 8d569d6..0000000 --- a/node_modules/ejs/lib/utils.js +++ /dev/null @@ -1,23 +0,0 @@ - -/*! - * EJS - * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca> - * MIT Licensed - */ - -/** - * Escape the given string of `html`. - * - * @param {String} html - * @return {String} - * @api private - */ - -exports.escape = function(html){ -  return String(html) -    .replace(/&(?!\w+;)/g, '&') -    .replace(/</g, '<') -    .replace(/>/g, '>') -    .replace(/"/g, '"'); -}; - 
\ No newline at end of file | 
