
var path = require('path');

function Router(piccolo) {
  // Save presenter directory
  this.directory = piccolo.directories.presenter;
}
module.exports = Router;

Router.prototype.parse = function (filepath) {

  // Parse path
  var args = filepath.split('/');

  // Get resource and method from path
  var resource = args.splice(0, 1)[0] || '';
  var method = args.splice(0, 1)[0] || '';

  // Translate empty path to index
  if (resource === '') {
    resource = 'index';
    method = 'index';
  }

  // Translate empty method to index
  if (method === '') {
    method = 'index';
  }

  return {
    path: path.join(this.directory, resource, 'changeTable.js'),
    method: method,
    args: args
  };
};

Router.prototype.error = function (code, error) {

  return {
    filepath: path.join(this.directory, 'error', 'changeTable.js'),
    method: 'error' + code,
    args: [error]
  };
};

@@ -754,16 +754,257 @@
 ror) %7B%0A%0A
+  // Create a JSON stringify able error object%0A%09var out = %7B%7D;%0A%09for (var name in error) %7B%0A%09%09out%5Bname%5D = error%5Bname%5D;%0A%09%7D%0A%09out.message = error.message;%0A%09out.stack = error.stack;%0A%09out.type = error.type;%0A%09out.construct = error.constructor.name;%0A%0A
   return
@@ -1002,24 +1002,24 @@
 %0A  return %7B%0A
-
     filepath
@@ -1113,21 +1113,19 @@
  args: %5B
-error
+out
 %5D%0A  %7D;%0A%7D

make error objects stringify able