/**
 * Magical pixie dust for finding Models, Views and Controllers and making them available to the Turnpike.invoke()
 * family of methods without the caller needing to know exact file locations.
 *
 * AutoLoader looks in your app first, then inside the Turnpike framework before giving up.
 */

@@ -71,16 +71,19 @@
 d making
+%0A *
  them av
@@ -114,19 +114,16 @@
 invoke()
-%0A *
  family 
@@ -144,16 +144,19 @@
 hout the
+%0A *
  caller 
@@ -214,86 +214,2550 @@
 der 
-looks in your app first, then inside the Turnpike framework before giving up.%0A */
+picks up all the default models, views and controllers from the%0A * framework first. External, NPM-installed packages can then register a%0A * Turnpike callback to get their stuff added, which may override Turnpike%0A * core. Finally, Autoload then scans the app itself for its models, views and%0A * controllers. Again, anything from Core, as well as externally packaged%0A * overrides, can be overridden here.%0A */%0A%0Avar _           = require('underscore');%0Avar models      = new Array();%0Avar views       = new Array();%0Avar controllers = new Array();%0A%0A//The interface:%0Avar AutoLoader = %7B%0A  invoke: function(name) %7B%0A    return AutoLoader.invokeController(name) %7C%7C AutoLoader.invokeView(name);%0A  %7D,%0A%0A  invokeController: function(name) %7B%0A    return _(controllers).findWhere(%7B'name':name%7D).construct;%0A  %7D,%0A%0A  invokeView: function(name) %7B%0A    //TODO: We need to write a master wrapping controller that can execute any dangling view.%0A    return _(views).findWhere(%7B'name':name%7D);%0A  %7D,%0A%0A  invokeModel: function(name) %7B%0A    return _(models).findWhere(%7B'name':name%7D).construct;%0A  %7D,%0A%0A  // Exports a copy of the full list of controllers and views detected.%0A  list: function() %7B%0A    return _.union(_(views).pluck('name'), _(controllers).pluck('name'));%0A  %7D%0A%0A  //TODO: Add methods for external modules to register items with the AutoLoader.%0A%7D;%0A%0Amodule.exports = AutoLoader;%0A%0A//The setup:%0A(_.once(function()%7B%0A  var path    = require('path');%0A  var fs      = require('fs-extra');%0A  var libdir  = path.dirname(module.filename);%0A  var cwd = process.cwd();%0A  var dir;%0A  var pattern = /%5E%5Cw*%5C.js$/;%0A%0A  //Start with views (why not).%0A  dir = path.join(libdir, 'api', 'views');%0A  _(fs.readdirSync(dir)).each(function(name) %7B%0A    //TODO: Implement the view constructor so we can call it here%0A    console.log(name);%0A  %7D);%0A%0A  dir = path.join(cwd, 'api', 'views');%0A  _(fs.readdirSync(dir)).each(function(name) %7B%0A    //TODO: Implement the view constructor so we can call it here too%0A    console.log(name);%0A  %7D);%0A%0A  //Controllers%0A  dir = path.join(libdir, 'api', 'controllers');%0A  _(fs.readdirSync(dir)).each(function(name) %7B%0A    if (pattern.test(name)) %7B%0A      controllers.unshift(%7B%0A        'name':      name.replace(/%5C.js/, ''),%0A        'construct': require(path.join(dir, name))%0A      %7D);%0A    %7D%0A  %7D);%0A%0A  dir = path.join(cwd, 'api', 'controllers');%0A  _(fs.readdirSync(dir)).each(function(name) %7B%0A    if (pattern.test(name)) %7B%0A      controllers.unshift(%7B%0A        'name':      name.replace(/%5C.js/, ''),%0A        'construct': require(path.join(dir, name))%0A      %7D);%0A    %7D%0A  %7D);%0A%7D))();
 %0A

Implement the Autoloader for Controllers.