Name: js-handler/node_modules/nodeunit/deps/ejs/ejs.js 
1:
// CommonJS require()
2:
 
3:
function require(p){
4:
    var path = require.resolve(p)
5:
      , mod = require.modules[path];
6:
    if (!mod) throw new Error('failed to require "' + p + '"');
7:
    if (!mod.exports) {
8:
      mod.exports = {};
9:
      mod.call(mod.exports, mod, mod.exports, require.relative(path));
10:
    }
11:
    return mod.exports;
12:
  }
13:
 
14:
require.modules = {};
15:
 
16:
require.resolve = function (path){
17:
    var orig = path
18:
      , reg = path + '.js'
19:
      , index = path + '/index.js';
20:
    return require.modules[reg] && reg
21:
      || require.modules[index] && index
22:
      || orig;
23:
  };
24:
 
25:
require.register = function (path, fn){
26:
    require.modules[path] = fn;
27:
  };
28:
 
29:
require.relative = function (parent) {
30:
    return function(p){
31:
      if ('.' != p[0]) return require(p);
32:
      
33:
      var path = parent.split('/')
34:
        , segs = p.split('/');
35:
      path.pop();
36:
      
37:
      for (var i = 0; i < segs.length; i++) {
38:
        var seg = segs[i];
39:
        if ('..' == seg) path.pop();
40:
        else if ('.' != seg) path.push(seg);
41:
      }
42:
 
43:
      return require(path.join('/'));
44:
    };
45:
  };
46:
 
47:
 
48:
require.register("ejs.js", function(module, exports, require){
49:
 
50:
/*!
51:
 * EJS
52:
 * Copyright(c) 2010 TJ Holowaychuk <[email protected]>
53:
 * MIT Licensed
54:
 */
55:
 
56:
/**
57:
 * Module dependencies.
58:
 */
59:
 
60:
var utils = require('./utils');
61:
 
62:
/**
63:
 * Library version.
64:
 */
65:
 
66:
exports.version = '0.4.2';
67:
 
68:
/**
69:
 * Filters.
70:
 *
71:
 * @type Object
72:
 */
73:
 
74:
var filters = exports.filters = require('./filters');
75:
 
76:
/**
77:
 * Intermediate js cache.
78:
 *
79:
 * @type Object
80:
 */
81:
 
82:
var cache = {};
83:
 
84:
/**
85:
 * Clear intermediate js cache.
86:
 *
87:
 * @api public
88:
 */
89:
 
90:
exports.clearCache = function(){
91:
  cache = {};
92:
};
93:
 
94:
/**
95:
 * Translate filtered code into function calls.
96:
 *
97:
 * @param {String} js
98:
 * @return {String}
99:
 * @api private
100:
 */
101:
 
102:
function filtered(js) {
103:
  return js.substr(1).split('|').reduce(function(js, filter){
104:
    var parts = filter.split(':')
105:
      , name = parts.shift()
106:
      , args = parts.shift() || '';
107:
    if (args) args = ', ' + args;
108:
    return 'filters.' + name + '(' + js + args + ')';
109:
  });
110:
};
111:
 
112:
/**
113:
 * Re-throw the given `err` in context to the
114:
 * `str` of ejs, `filename`, and `lineno`.
115:
 *
116:
 * @param {Error} err
117:
 * @param {String} str
118:
 * @param {String} filename
119:
 * @param {String} lineno
120:
 * @api private
121:
 */
122:
 
123:
function rethrow(err, str, filename, lineno){
124:
  var lines = str.split('\n')
125:
    , start = Math.max(lineno - 3, 0)
126:
    , end = Math.min(lines.length, lineno + 3);
127:
 
128:
  // Error context
129:
  var context = lines.slice(start, end).map(function(line, i){
130:
    var curr = i + start + 1;
131:
    return (curr == lineno ? ' >> ' : '    ')
132:
      + curr
133:
      + '| '
134:
      + line;
135:
  }).join('\n');
136:
 
137:
  // Alter exception message
138:
  err.path = filename;
139:
  err.message = (filename || 'ejs') + ':'
140:
    + lineno + '\n'
141:
    + context + '\n\n'
142:
    + err.message;
143:
  
144:
  throw err;
145:
}
146:
 
147:
/**
148:
 * Parse the given `str` of ejs, returning the function body.
149:
 *
150:
 * @param {String} str
151:
 * @return {String}
152:
 * @api public
153:
 */
154:
 
155:
var parse = exports.parse = function(str, options){
156:
  var options = options || {}
157:
    , open = options.open || exports.open || '<%'
158:
    , close = options.close || exports.close || '%>';
159:
 
160:
  var buf = [
161:
      "var buf = [];"
162:
    , "\nwith (locals) {"
163:
    , "\n  buf.push('"
164:
  ];
165:
  
166:
  var lineno = 1;
167:
 
168:
  for (var i = 0, len = str.length; i < len; ++i) {
169:
    if (str.slice(i, open.length + i) == open) {
170:
      i += open.length
171:
  
172:
      var prefix, postfix, line = '__stack.lineno=' + lineno;
173:
      switch (str[i]) {
174:
        case '=':
175:
          prefix = "', escape((" + line + ', ';
176:
          postfix = ")), '";
177:
          ++i;
178:
          break;
179:
        case '-':
180:
          prefix = "', (" + line + ', ';
181:
          postfix = "), '";
182:
          ++i;
183:
          break;
184:
        default:
185:
          prefix = "');" + line + ';';
186:
          postfix = "; buf.push('";
187:
      }
188:
 
189:
      var start = i;
190:
      var end = str.indexOf(close, i);
191:
      var js = str.substring(i, end);
192:
      var n = 0;
193:
      while ((n = js.indexOf("\n", n)) > -1) {
194:
        n++;
195:
        lineno++;
196:
      }
197:
      if (js[0] == ':') js = filtered(js);
198:
      buf.push(prefix, js, postfix);
199:
      i += end - start + close.length - 1;
200:
 
201:
    } else if (str[i] == "\\") {
202:
      buf.push("\\\\");
203:
    } else if (str[i] == "'") {
204:
      buf.push("\\'");
205:
    } else if (str[i] == "\r") {
206:
      buf.push(" ");
207:
    } else if (str[i] == "\n") {
208:
      buf.push("\\n");
209:
      lineno++;
210:
    } else {
211:
      buf.push(str[i]);
212:
    }
213:
  }
214:
 
215:
  buf.push("');\n}\nreturn buf.join('');");
216:
  return buf.join('');
217:
};
218:
 
219:
/**
220:
 * Compile the given `str` of ejs into a `Function`.
221:
 *
222:
 * @param {String} str
223:
 * @param {Object} options
224:
 * @return {Function}
225:
 * @api public
226:
 */
227:
 
228:
var compile = exports.compile = function(str, options){
229:
  options = options || {};
230:
  
231:
  var input = JSON.stringify(str)
232:
    , filename = options.filename
233:
        ? JSON.stringify(options.filename)
234:
        : 'undefined';
235:
  
236:
  // Adds the fancy stack trace meta info
237:
  str = [
238:
    'var __stack = { lineno: 1, input: ' + input + ', filename: ' + filename + ' };',
239:
    rethrow.toString(),
240:
    'try {',
241:
    exports.parse(str, options),
242:
    '} catch (err) {',
243:
    '  rethrow(err, __stack.input, __stack.filename, __stack.lineno);',
244:
    '}'
245:
  ].join("\n");
246:
  
247:
  if (options.debug) console.log(str);
248:
  var fn = new Function('locals, filters, escape', str);
249:
  return function(locals){
250:
    return fn.call(this, locals, filters, utils.escape);
251:
  }
252:
};
253:
 
254:
/**
255:
 * Render the given `str` of ejs.
256:
 *
257:
 * Options:
258:
 *
259:
 *   - `locals`          Local variables object
260:
 *   - `cache`           Compiled functions are cached, requires `filename`
261:
 *   - `filename`        Used by `cache` to key caches
262:
 *   - `scope`           Function execution context
263:
 *   - `debug`           Output generated function body
264:
 *   - `open`            Open tag, defaulting to "<%"
265:
 *   - `close`           Closing tag, defaulting to "%>"
266:
 *
267:
 * @param {String} str
268:
 * @param {Object} options
269:
 * @return {String}
270:
 * @api public
271:
 */
272:
 
273:
exports.render = function(str, options){
274:
  var fn
275:
    , options = options || {};
276:
  if (options.cache) {
277:
    if (options.filename) {
278:
      fn = cache[options.filename] || (cache[options.filename] = compile(str, options));
279:
    } else {
280:
      throw new Error('"cache" option requires "filename".');
281:
    }
282:
  } else {
283:
    fn = compile(str, options);
284:
  }
285:
  return fn.call(options.scope, options.locals || {});
286:
};
287:
 
288:
/**
289:
 * Expose to require().
290:
 */
291:
 
292:
if (require.extensions) {
293:
  require.extensions['.ejs'] = function(module, filename) {
294:
    source = require('fs').readFileSync(filename, 'utf-8');
295:
    module._compile(compile(source, {}), filename);
296:
   };
297:
} else if (require.registerExtension) {
298:
  require.registerExtension('.ejs', function(src) {
299:
    return compile(src, {});
300:
  });
301:
}
302:
 
303:
}); // module: ejs.js
304:
 
305:
require.register("filters.js", function(module, exports, require){
306:
 
307:
/*!
308:
 * EJS - Filters
309:
 * Copyright(c) 2010 TJ Holowaychuk <[email protected]>
310:
 * MIT Licensed
311:
 */
312:
 
313:
/**
314:
 * First element of the target `obj`.
315:
 */
316:
 
317:
exports.first = function(obj) {
318:
  return obj[0];
319:
};
320:
 
321:
/**
322:
 * Last element of the target `obj`.
323:
 */
324:
 
325:
exports.last = function(obj) {
326:
  return obj[obj.length - 1];
327:
};
328:
 
329:
/**
330:
 * Capitalize the first letter of the target `str`.
331:
 */
332:
 
333:
exports.capitalize = function(str){
334:
  str = String(str);
335:
  return str[0].toUpperCase() + str.substr(1, str.length);
336:
};
337:
 
338:
/**
339:
 * Downcase the target `str`.
340:
 */
341:
 
342:
exports.downcase = function(str){
343:
  return String(str).toLowerCase();
344:
};
345:
 
346:
/**
347:
 * Uppercase the target `str`.
348:
 */
349:
 
350:
exports.upcase = function(str){
351:
  return String(str).toUpperCase();
352:
};
353:
 
354:
/**
355:
 * Sort the target `obj`.
356:
 */
357:
 
358:
exports.sort = function(obj){
359:
  return Object.create(obj).sort();
360:
};
361:
 
362:
/**
363:
 * Sort the target `obj` by the given `prop` ascending.
364:
 */
365:
 
366:
exports.sort_by = function(obj, prop){
367:
  return Object.create(obj).sort(function(a, b){
368:
    a = a[prop], b = b[prop];
369:
    if (a > b) return 1;
370:
    if (a < b) return -1;
371:
    return 0;
372:
  });
373:
};
374:
 
375:
/**
376:
 * Size or length of the target `obj`.
377:
 */
378:
 
379:
exports.size = exports.length = function(obj) {
380:
  return obj.length;
381:
};
382:
 
383:
/**
384:
 * Add `a` and `b`.
385:
 */
386:
 
387:
exports.plus = function(a, b){
388:
  return Number(a) + Number(b);
389:
};
390:
 
391:
/**
392:
 * Subtract `b` from `a`.
393:
 */
394:
 
395:
exports.minus = function(a, b){
396:
  return Number(a) - Number(b);
397:
};
398:
 
399:
/**
400:
 * Multiply `a` by `b`.
401:
 */
402:
 
403:
exports.times = function(a, b){
404:
  return Number(a) * Number(b);
405:
};
406:
 
407:
/**
408:
 * Divide `a` by `b`.
409:
 */
410:
 
411:
exports.divided_by = function(a, b){
412:
  return Number(a) / Number(b);
413:
};
414:
 
415:
/**
416:
 * Join `obj` with the given `str`.
417:
 */
418:
 
419:
exports.join = function(obj, str){
420:
  return obj.join(str || ', ');
421:
};
422:
 
423:
/**
424:
 * Truncate `str` to `len`.
425:
 */
426:
 
427:
exports.truncate = function(str, len){
428:
  str = String(str);
429:
  return str.substr(0, len);
430:
};
431:
 
432:
/**
433:
 * Truncate `str` to `n` words.
434:
 */
435:
 
436:
exports.truncate_words = function(str, n){
437:
  var str = String(str)
438:
    , words = str.split(/ +/);
439:
  return words.slice(0, n).join(' ');
440:
};
441:
 
442:
/**
443:
 * Replace `pattern` with `substitution` in `str`.
444:
 */
445:
 
446:
exports.replace = function(str, pattern, substitution){
447:
  return String(str).replace(pattern, substitution || '');
448:
};
449:
 
450:
/**
451:
 * Prepend `val` to `obj`.
452:
 */
453:
 
454:
exports.prepend = function(obj, val){
455:
  return Array.isArray(obj)
456:
    ? [val].concat(obj)
457:
    : val + obj;
458:
};
459:
 
460:
/**
461:
 * Append `val` to `obj`.
462:
 */
463:
 
464:
exports.append = function(obj, val){
465:
  return Array.isArray(obj)
466:
    ? obj.concat(val)
467:
    : obj + val;
468:
};
469:
 
470:
/**
471:
 * Map the given `prop`.
472:
 */
473:
 
474:
exports.map = function(arr, prop){
475:
  return arr.map(function(obj){
476:
    return obj[prop];
477:
  });
478:
};
479:
 
480:
/**
481:
 * Reverse the given `obj`.
482:
 */
483:
 
484:
exports.reverse = function(obj){
485:
  return Array.isArray(obj)
486:
    ? obj.reverse()
487:
    : String(obj).split('').reverse().join('');
488:
};
489:
 
490:
/**
491:
 * Get `prop` of the given `obj`.
492:
 */
493:
 
494:
exports.get = function(obj, prop){
495:
  return obj[prop];
496:
};
497:
 
498:
/**
499:
 * Packs the given `obj` into json string
500:
 */
501:
exports.json = function(obj){
502:
  return JSON.stringify(obj);
503:
};
504:
}); // module: filters.js
505:
 
506:
require.register("utils.js", function(module, exports, require){
507:
 
508:
/*!
509:
 * EJS
510:
 * Copyright(c) 2010 TJ Holowaychuk <[email protected]>
511:
 * MIT Licensed
512:
 */
513:
 
514:
/**
515:
 * Escape the given string of `html`.
516:
 *
517:
 * @param {String} html
518:
 * @return {String}
519:
 * @api private
520:
 */
521:
 
522:
exports.escape = function(html){
523:
  return String(html)
524:
    .replace(/&(?!\w+;)/g, '&')
525:
    .replace(/</g, '<')
526:
    .replace(/>/g, '>')
527:
    .replace(/"/g, '"');
528:
};
529:
 
530:
}); // module: utils.js