Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Massive simplification. Removing dependencies on express or any web-f…

…ramework. Using tap and underscore dependencies.
  • Loading branch information...
commit 4e2bd40df71f4b2a1ba889dc320d82ef7da4b34b 1 parent a94a76c
Dave Elkan authored
Showing with 198 additions and 727 deletions.
  1. +1 −0  .gitignore
  2. +0 −4 index.js
  3. +140 −0 layers.js
  4. +0 −43 lib/layers/Layers.Express.js
  5. +0 −128 lib/layers/Layers.Loader.js
  6. +0 −94 lib/layers/layers.js
  7. +0 −76 lib/layers/layers/views/BaseExpressView.js
  8. +0 −20 lib/layers/layers/views/ErrorView.js
  9. +0 −14 lib/layers/merger.js
  10. +19 −19 package.json
  11. +0 −226 test/ExpressLayersTest.js
  12. +20 −0 test/LayersTest.js
  13. +0 −11 test/express/layers/invalid/controllers/TestController.js
  14. +0 −7 test/express/layers/invalid/views/ErrorView.js
  15. +0 −10 test/express/layers/invalid/views/IndexView.js
  16. +0 −10 test/express/layers/invalid/views/ItemView.js
  17. +0 −5 test/express/layers/invalid/views/JsonView.js
  18. +0 −15 test/express/layers/valid/controllers/TestController.js
  19. +0 −1  test/express/layers/valid/customLayer/Custom.js
  20. +0 −7 test/express/layers/valid/views/ErrorView.js
  21. +0 −10 test/express/layers/valid/views/IndexView.js
  22. +0 −10 test/express/layers/valid/views/ItemView.js
  23. +0 −5 test/express/layers/valid/views/JsonView.js
  24. +0 −5 test/express/templates/index.jade
  25. +0 −1  test/express/templates/item.jade
  26. +0 −6 test/express/templates/layout.jade
  27. +5 −0 testLayers/controllers/AnotherTestController.js
  28. +5 −0 testLayers/controllers/TestController.js
  29. +8 −0 testLayers/services/TestService.js
1  .gitignore
View
@@ -1 +1,2 @@
.DS_Store
+node_modules
4 index.js
View
@@ -1,4 +0,0 @@
-module.exports = {
- Express: require("./lib/layers/Layers.Express"),
- BaseExpressView: require('./lib/layers/layers/views/BaseExpressView')
-};
140 layers.js
View
@@ -0,0 +1,140 @@
+var fs = require('fs'),
+ _ = require('underscore'),
+ defaults = {
+ excludePrefix: "Base",
+ rootPath: "./layers/"
+ };
+
+/**
+ * Loads the 'layers' of an application by loading their constituant
+ * files, instanciating them and adding them to the server object.
+ *
+ * @param server The server object (i.e. Express app).
+ * @param options An optional options object.
+ */
+module.exports = function(server, options) {
+ _.defaults(options, defaults);
+
+ var layers = options.layers || getLayers(options.rootPath),
+ excludePrefix = options.excludePrefix;
+
+ layers.forEach(function(layer) {
+ server[layer] = loadComponents(options.rootPath + "/" + layer, layer);
+ });
+
+ /**
+ * Returns a list of layer names.
+ *
+ * Finds the directories in the root path supplied
+ * and returns their names as the layers this application
+ * makes use of.
+ */
+ function getLayers(rootPath) {
+ var layers = getDirectoryFileListSync(rootPath),
+ directories = [],
+ hasControllers = false;
+
+ layers.forEach(function(layer) {
+ if (layer === "controllers") {
+ hasControllers = true;
+ } else {
+ var fullPathToLayerDirectory = rootPath + "/" + layer;
+ if (isDirectory(fullPathToLayerDirectory)) {
+ directories.push(layer.toLowerCase());
+ }
+ }
+ });
+
+ // Ensure handlers are always loaded last.
+ if (hasControllers) {
+ directories.push("controllers");
+ }
+
+ return directories;
+ }
+
+ /**
+ * Recursively loads and instantiates javascript files within a path
+ * adding references to them under the current layer namespace on the
+ * supplied server object.
+ */
+ function loadComponents(path, layer) {
+ var files = getDirectoryFileListSync(path),
+ components = {};
+
+ files.forEach(function(fileName) {
+ var fullPathToFile = path + "/" + fileName;
+ if (isDirectory(fullPathToFile)) {
+ loadComponents(fullPathToFile, layer);
+ } else if (fileName.indexOf(excludePrefix) != 0 && fileName.indexOf(".js") === fileName.length - 3) {
+ var name = getRequireName(fileName),
+ item = require(path + "/" + name);
+
+ if (typeof item === "function") {
+ item = item(server);
+ }
+
+ if (item) {
+ console.log("Attaching", layer + "." + getInstanceName(name));
+ components[getInstanceName(name)] = item;
+ }
+ }
+ });
+
+ return components;
+ }
+
+ /**
+ * Synchronously returns a file list from a directory.
+ */
+ function getDirectoryFileListSync(directory) {
+ var files = [];
+ if (dirExistsSync(directory) && isDirectory(directory)) {
+ files = fs.readdirSync(directory);
+ }
+
+ return files;
+ }
+
+ /**
+ * Synchronously checks to see whether a directory exists or not.
+ */
+ function dirExistsSync (directory) {
+ try {
+ fs.statSync(directory);
+ return true;
+ } catch (err) {
+ return false;
+ }
+ }
+
+ /**
+ * Synchronously checks whether the file at the path specified is a
+ * directory or not.
+ */
+ function isDirectory(file) {
+ try {
+ var stats = fs.statSync(file);
+ return stats.isDirectory();
+ } catch (err) {
+ return false;
+ }
+ }
+
+ /**
+ * Synchronously returns the name of the file sans .js suffix.
+ */
+ function getRequireName(file) {
+ return file.substr(0, file.lastIndexOf(".js"));
+ }
+
+ /**
+ * Synchronously returns the name of an instance.
+ *
+ * i.e. The name of the file with the first letter lower case.
+ */
+ function getInstanceName(name) {
+ return name[0].toLowerCase() + name.substr(1);
+ }
+};
+
43 lib/layers/Layers.Express.js
View
@@ -1,43 +0,0 @@
-var Layers = require('./Layers'),
- util = require('util');
-
-ExpressLayers = function(server, rootPath, routes, options) {
- ExpressLayers.super_.call(this, server, rootPath, routes, options);
-};
-
-util.inherits(ExpressLayers, Layers);
-
-/**
- * Sets up a route for a layered express app.
- *
- * Accepts a server along with a path and handler to map.
- *
- * @param server The Express app object.
- * @param path The path on which to listen.
- * @param handler The handler object containing the HTTP method, action to perform,
- * an optional array of middleware a map of views keyed by the
- * content-type they will respond with.
- */
-ExpressLayers.prototype.setupRoute = function(server, path, handler) {
- var self = this,
- method = handler.method.toLowerCase();
- if (typeof server[method] === "function") {
- server[method].call(server, path, handler.middleware, function(req, res, next) {
- for (var view in handler.views) {
- if (req.accepts(view)) {
- handler.action.call(server, req, res, function(error, result) {
- if (error) {
- server.views.errorView.render(req, res, error, next);
- } else {
- handler.views[view].render(req, res, result, next);
- }
- }, next);
- return;
- }
- }
- next();
- });
- }
-};
-
-module.exports = ExpressLayers;
128 lib/layers/Layers.Loader.js
View
@@ -1,128 +0,0 @@
-var fs = require('fs'),
- merger = require('./merger.js'),
- defaults = {
- excludePrefix: "Base"
- };
-
-/**
- * Loads the 'layers' of an application by loading their constituant
- * files, instanciating them and adding them to the server object.
- *
- * @param server The server object (i.e. Express app).
- * @param rootPath The path to the layers directory for this app.
- * @param options An optional options object.
- */
-function loadLayers(server, rootPath, options) {
- options = merger(defaults, options);
- getLayers(rootPath).forEach(function(layer) {
- if (!server[layer]) {
- server[layer] = {};
- }
-
- loadFiles(server, __dirname + '/layers/' + layer, layer, options);
- loadFiles(server, rootPath + "/" + layer, layer, options);
- });
-}
-
-/**
- * Returns a list of layer names.
- *
- * Finds the directories in the root path supplied
- * and returns their names as the layers this application
- * makes use of.
- */
-function getLayers(rootPath) {
- var files = getDirectoryFileListSync(rootPath),
- directories = [];
-
- files.forEach(function(fileName) {
- var fullPathToFile = rootPath + "/" + fileName;
- if (isDirectory(fullPathToFile)) {
- directories.push(fileName.toLowerCase());
- }
- });
-
- return directories;
-}
-
-/**
- * Recursively loads and instantiates javascript files within a path
- * adding references to them under the current layer namespace on the
- * supplied server object.
- */
-function loadFiles(server, path, layer, options) {
- var files = getDirectoryFileListSync(path);
-
- files.forEach(function(fileName) {
- var fullPathToFile = path + "/" + fileName;
- if (isDirectory(fullPathToFile)) {
- loadFiles(server, fullPathToFile, layer, options);
- } else if (fileName.indexOf(options.excludePrefix) != 0 && fileName.indexOf(".js") === fileName.length - 3) {
- var name = getRequireName(fileName),
- item = require(path + "/" + name);
-
- if (typeof item === "function") {
- item = item(server);
- }
-
- server[layer][getInstanceName(name)] = item;
- }
- });
-}
-
-/**
- * Synchronously returns a file list from a directory.
- */
-function getDirectoryFileListSync(directory) {
- var files = [];
- if (dirExistsSync(directory) && isDirectory(directory)) {
- files = fs.readdirSync(directory);
- }
-
- return files;
-}
-
-/**
- * Synchronously checks to see whether a directory exists or not.
- */
-function dirExistsSync (directory) {
- try {
- fs.statSync(directory);
- return true;
- } catch (err) {
- return false;
- }
-}
-
-/**
- * Synchronously checks whether the file at the path specified is a
- * directory or not.
- */
-function isDirectory(file) {
- try {
- var stats = fs.statSync(file);
- return stats.isDirectory();
- } catch (err) {
- return false;
- }
-}
-
-/**
- * Synchronously returns the name of the file sans .js suffix.
- */
-function getRequireName(file) {
- return file.substr(0, file.lastIndexOf(".js"));
-}
-
-/**
- * Synchronously returns the name of an instance.
- *
- * i.e. The name of the file with the first letter lower case.
- */
-function getInstanceName(name) {
- return name[0].toLowerCase() + name.substr(1);
-}
-
-module.exports = {
- loadLayers: loadLayers
-};
94 lib/layers/layers.js
View
@@ -1,94 +0,0 @@
-var fs = require('fs'),
- loader = require('./Layers.Loader'),
- merger = require('./merger.js'),
- defaulthandler = {
- method: "get",
- middleware: []
- };
-
-/**
- * Layers.
- *
- * A helper to create a layered application in node.js
- *
- * For more information see https://github.com/dave-elkan/node-layers
- *
- * @param server The server object (i.e. Express app).
- * @param rootPath The path to the layers directory for this app.
- * @param wiring The wiring object. See Layers#setupWiring for more information.
- * @param options An optional options object to override the defaults.
- */
-Layers = function(server, rootPath, wiring, options) {
- loader.loadLayers(server, rootPath, options);
- setupWiring.call(this, server, wiring(server));
-};
-
-/**
- * This function must be defined in a framework-specific
- * implementation of Layers to setup a route for that
- * framework.
- *
- * See Layers.Express#setupRoute if you intend of implementing this function
- * for a framework other than Express.
- *
- * @param path The path of the route to setup.
- * @param handler The handler for this current route.
- */
-Layers.prototype.setupRoute = function(path, handler) {
- throw new Error("Must implement Layers::setupRoute");
-};
-
-/**
- * Adds routes to an app and wires up the layers for each action.
- *
- * @param server The Server to add the routes to.
- * @param wiring The Wiring object.
- *
- * The wiring object is a map of arrays of route objects.
- * i.e.
- *
- * {
- * "/": [{
- * method: "get",
- * action: actionFunctionToCallForGet,
- * views: {
- * html: htmlViewForGetRequest,
- * json: jsonViewForGetRequest
- * }
- * }, {
- * method: "post",
- * action: actionFunctionToCallForPost,
- * views: {
- * json: jsonViewForPostRequest
- * }
- * }
- * ],
- *
- * "/path/of/route": [{
- * action: actionFunctionToCallForGetRequest,
- * middleware: [someMiddleware, someOtherMiddleware],
- * views: {
- * html: htmlViewForGetRequest,
- * json: jsonViewForGetRequest
- * }
- * }
- * ]
- * }
- *
- * Each path can have multiple handlers. If for any reason the handler
- * cannot respond to the request then the next is tried until all of the
- * handlers are extinguished at which point a 404 will be thrown.
- */
-function setupWiring(server, wiring) {
- var self = this;
- for (var path in wiring) {
- var handlers = wiring[path];
- if (handlers instanceof Array) {
- handlers.forEach(function(handler) {
- self.setupRoute(server, path, merger(defaulthandler, handler));
- });
- }
- }
-}
-
-module.exports = Layers;
76 lib/layers/layers/views/BaseExpressView.js
View
@@ -1,76 +0,0 @@
-BaseExpressView = function() {};
-
-/**
- * Renders a view with the result of the action.
- *
- * This function will send the result to the view's
- * format function so any last-minute formatting can be
- * performed.
- *
- * If an error occurs during the formatting an error is
- * displayed in the Error View. If no Error View is present
- * then the default Express error handler is utilised.
- *
- * @param {Object} req The request object.
- * @param {Object} res The response object.
- * @param {Object} result The object(s) being rendered.
- * @param {Function} next The next function in the middleware stack.
- */
-BaseExpressView.prototype.render = function(req, res, result, next) {
- var self = this;
- this.format(result, function(error, result) {
- if (error) {
- var errorView = self.getErrorView();
- if (!errorView) {
- next(error);
- } else {
- errorView.render(req, res, error);
- }
- } else {
- res.render(self.getTemplate(), self.getRenderParameters(result));
- }
- });
-};
-
-/**
- * Returns an error view.
- *
- * This stub returns null to enforce reverting to Express'
- * internal error handler.
- * Override this function to define your own error view.
- */
-BaseExpressView.prototype.getErrorView = function() {
- return null;
-};
-
-/**
- * Returns the name of the template file to use for this view.
- */
-BaseExpressView.prototype.getTemplate = function() {
- throw new Error("No view template specified.");
-};
-
-/**
- * Returns an Express render parameters object containing only the
- * result object.
- */
-BaseExpressView.prototype.getRenderParameters = function(result) {
- return {
- locals: {
- result: result
- }
- };
-};
-
-/**
- * Placeholder function allowing for the formatting of
- * objects to be sent to the BaseExpressView layer.
- *
- * @param {Object} result The object to format.
- * @param {Function} callback The function to call when formatting is complete.
- */
-BaseExpressView.prototype.format = function(result, callback) {
- callback(null, result);
-};
-
-module.exports = BaseExpressView;
20 lib/layers/layers/views/ErrorView.js
View
@@ -1,20 +0,0 @@
-/**
- * Renders a (very basic) Error.
- *
- * Renders an error to either text/html or application/json depending on the
- * Accept header of the request.
- *
- * @param {Object} req The request object.
- * @param {Object} res The response object.
- * @param {Object} error The error to render.
- */
-module.exports = {
- render: function(req, res, error) {
- var body = "Error";
- res.writeHead(500, {
- 'Content-Length': body.length,
- 'Content-Type': 'text/plain'
- });
- res.end(body);
- }
-};
14 lib/layers/merger.js
View
@@ -1,14 +0,0 @@
-/**
- * Simple merge function. Probably wrongish.
- */
-module.exports = function merge(base, inst) {
- var merged = {};
- for (var p in base) {
- merged[p] = base[p];
- }
- for (var p in inst || {}) {
- merged[p] = inst[p];
- }
-
- return merged;
-};
38 package.json
View
@@ -1,26 +1,26 @@
{
"name": "layers",
"description": "A package to help layered architecture for node.js",
- "version": "0.0.3",
+ "version": "1.0.0",
"repository": "git://github.com/dave-elkan/layers",
"author": "Dave Elkan <dave@edave.net> (http://www.edave.net)",
- "contributors": [{
- "name": "Dave Elkan",
- "email": "dave@edave.net"
- }
- ],
- "directories": {
- "lib": "lib"
+ "dependencies": {
+ "underscore": "1.3.1"
},
- "dependecies": {
- "expresso": "0.7.7"
- },
- "scripts": {
- "test": "expresso test/*.js"
- },
- "keywords": ["layers", "layered", "express", "connect", "web", "mvc", "architecture"],
- "main": "index",
- "engines": {
- "node": ">= 0.4.1 < 0.5.0"
- }
+ "devDependencies": {
+ "tap": "0.2.3"
+ },
+ "keywords": [
+ "layers",
+ "layered",
+ "express",
+ "connect",
+ "web",
+ "mvc",
+ "architecture"
+ ],
+ "main": "layers",
+ "scripts": {
+ "test": "node_modules/.bin/tap test"
+ }
}
226 test/ExpressLayersTest.js
View
@@ -1,226 +0,0 @@
-var assert = require('assert'),
- Layers = require('../index').Express;
-
-exports["Ensure layers are loaded as expected"] = function() {
-
- function wiring() {
- return {
- "/": [{}],
- "/index": [{}]
- };
- }
-
- var actions = [],
- layersDir = __dirname + '/express/layers/valid',
- mockServer = {
- get: function() {}
- },
- layeredApp = new Layers(mockServer, layersDir, wiring);
-
- assert.isNotNull(mockServer.views.itemView);
- assert.isNotNull(mockServer.controllers.testController);
- assert.isNotNull(mockServer.customlayer.custom);
-};
-
-exports["Ensure GET routes are installed correctly and in order"] = function() {
-
- function wiring() {
- return {
- "/": [{}],
- "/index": [{}]
- };
- }
-
- var actions = [],
- layersDir = __dirname + '/express/layers/valid',
- mockServer = {
- get: function(path, middleware, callback) {
- actions.push(path);
- }
- },
- layeredApp = new Layers(mockServer, layersDir, wiring);
-
- assert.equal(0, actions.indexOf("/"));
- assert.equal(1, actions.indexOf("/index"));
-};
-
-exports["Ensure POST routes are installed correctly and in order"] = function() {
-
- function wiring() {
- return {
- "/": [{
- method: "POST"
- }],
- "/index": [{
- method: "post"
- }]
- };
- }
-
- var actions = [],
- layersDir = __dirname + '/express/layers/valid',
- mockServer = {
- get: function(path, middleware, callback) {
- assert.ok(false, "No GET handlers initialised");
- },
- post: function(path, middleware, callback) {
- actions.push(path);
- },
- },
- layeredApp = new Layers(mockServer, layersDir, wiring);
-
- assert.equal(0, actions.indexOf("/"));
- assert.equal(1, actions.indexOf("/index"));
-};
-
-exports["Ensure mixed method routes are installed correctly and in order"] = function() {
-
- function wiring() {
- return {
- "/": [{
- method: "get"
- }],
-
- "/index": [{
- method: "POST"
- }],
-
- "/something": [{
- method: "POST"
- }]
- };
- }
-
- var actions = [],
- layersDir = __dirname + '/express/layers/valid',
- mockServer = {
- get: function(path, middleware, callback) {
- actions.push(path);
- },
- post: function(path, middleware, callback) {
- actions.push(path);
- },
- },
- layeredApp = new Layers(mockServer, layersDir, wiring);
-
- assert.equal(0, actions.indexOf("/"));
- assert.equal(1, actions.indexOf("/index"));
- assert.equal(2, actions.indexOf("/something"));
-
-};
-
-exports["Ensure multi-handler routes are installed correctly and in order"] = function() {
-
- function wiring() {
- return {
- "/": [{
- method: "get"
- }, {
- method: "post"
- }]
- };
- }
-
- var actions = [],
- gets = [],
- posts = [],
- layersDir = __dirname + '/express/layers/valid',
- mockServer = {
- get: function(path, middleware, callback) {
- actions.push(path);
- gets.push(path);
- },
- post: function(path, middleware, callback) {
- actions.push(path);
- posts.push(path);
- },
- },
- layeredApp = new Layers(mockServer, layersDir, wiring);
-
- assert.equal(0, actions.indexOf("/"), "/ get handler");
- assert.equal(1, actions.lastIndexOf("/"), "/ post handler");
- assert.equal(0, gets.indexOf("/"), "/get handler");
- assert.equal(0, posts.indexOf("/"), "/ post handler");
-};
-
-exports["Ensure mixed multi/single-handler routes are installed correctly and in order"] = function() {
-
- function wiring() {
- return {
- "/": [{
- method: "get"
- }, {
- method: "post"
- }],
-
- "/single": [{
- method: "POST"
- }]
- };
- }
-
- var actions = [],
- gets = [],
- posts = [],
- layersDir = __dirname + '/express/layers/valid',
- mockServer = {
- get: function(path, middleware, callback) {
- actions.push(path);
- gets.push(path);
- },
- post: function(path, middleware, callback) {
- actions.push(path);
- posts.push(path);
- },
- },
- layeredApp = new Layers(mockServer, layersDir, wiring);
-
- assert.equal(0, actions.indexOf("/"), "/ get handler");
- assert.equal(1, actions.lastIndexOf("/"), "/ post handler");
- assert.equal(2, actions.indexOf("/single"), "/single post handler");
-
- assert.equal(0, gets.indexOf("/"), "/get handler");
- assert.equal(0, posts.indexOf("/"), "/ post handler");
- assert.equal(1, posts.indexOf("/single"), "/single post handler");
-
-};
-
-exports["Ensure middleware is correctly initialised"] = function(a) {
-
- function srcMiddleware() {}
-
- function wiring() {
- return {
- "/": [{
- middleware: [
- srcMiddleware
- ]
- }]
- };
- }
-
- var actions = [],
- layersDir = __dirname + '/express/layers/valid',
- mockServer = {
- get: function(path, middleware, callback) {
- assert.equal(srcMiddleware, middleware[0]);
- }
- },
- layeredApp = new Layers(mockServer, layersDir, wiring);
-};
-
-exports["Test dodgy wiring - wiring is invalid (an array)"] = function () {
-
- function wiring() {
- return [{}];
- }
-
- var actions = [],
- layersDir = __dirname + '/express/layers/valid',
- mockServer = {
- get: function (path, middleware, callback) {
- assert.ok(false, "Invalid hanlder should not be installed");
- }
- },
- layeredApp = new Layers(mockServer, layersDir, wiring);
-};
20 test/LayersTest.js
View
@@ -0,0 +1,20 @@
+var test = require("tap").test;
+
+test("Ensure loader loads layers", function(t) {
+ var layers = require('../layers'),
+ server = {};
+ debugger;
+ layers(server, {
+ rootPath: __dirname + "/../testLayers"
+ });
+ t.ok(server.controllers, "Controllers stack exists");
+ t.ok(server.services, "Services stack exists");
+ t.ok(server.controllers.testController, "Test controller is present");
+ t.ok(server.controllers.testController.testControllerPresent, "Test controller property is present");
+ t.equal(server.controllers.anotherTestController.testControllerFunction(), "Hello", "Test controller function is present and returns correct value");
+
+ t.ok(server.services.testService, "Test service is present");
+ t.ok(server.services.testService.testServicePresent, "Test service property is present");
+ t.equal(server.services.testService.testServiceFunction(), "A Test value", "Test service function is present and returns correct value");
+ t.end();
+});
11 test/express/layers/invalid/controllers/TestController.js
View
@@ -1,11 +0,0 @@
-module.exports = [{
- getIndex: function(req, res, callback) {
- callback(null, [{
- _id: "test",
- name: "Test"
- }, {
- _id: "test",
- name: "Test"
- }]);
- }
-}];
7 test/express/layers/invalid/views/ErrorView.js
View
@@ -1,7 +0,0 @@
-ErrorView = function() {};
-
-ErrorView.prototype.render = function(req, res, error) {
- res.send(result);
-};
-
-module.exports = new ErrorView;
10 test/express/layers/invalid/views/IndexView.js
View
@@ -1,10 +0,0 @@
-module.exports = {
- render: function(req, res, result) {
- res.render("index.jade", {
- locals: {
- title: "Index",
- result: result
- }
- });
- }
-};
10 test/express/layers/invalid/views/ItemView.js
View
@@ -1,10 +0,0 @@
-module.exports = {
- render: function(req, res, result) {
- res.render("item.jade", {
- locals: {
- title: "Item",
- result: result
- }
- });
- }
-}
5 test/express/layers/invalid/views/JsonView.js
View
@@ -1,5 +0,0 @@
-module.exports = {
- render: function(req, res, result) {
- res.send(result);
- }
-};
15 test/express/layers/valid/controllers/TestController.js
View
@@ -1,15 +0,0 @@
-module.exports = {
- getIndex: function(req, res, callback) {
- callback(null, [{
- _id: "test",
- name: "Test"
- }, {
- _id: "test",
- name: "Test"
- }]);
- },
-
- getItemByKey: function(req, res, callback) {
- callback()
- }
-};
1  test/express/layers/valid/customLayer/Custom.js
View
@@ -1 +0,0 @@
-module.exports = {};
7 test/express/layers/valid/views/ErrorView.js
View
@@ -1,7 +0,0 @@
-ErrorView = function() {};
-
-ErrorView.prototype.render = function(req, res, error) {
- res.send(result);
-};
-
-module.exports = new ErrorView;
10 test/express/layers/valid/views/IndexView.js
View
@@ -1,10 +0,0 @@
-module.exports = {
- render: function(req, res, result) {
- res.render("index.jade", {
- locals: {
- title: "Index",
- result: result
- }
- });
- }
-};
10 test/express/layers/valid/views/ItemView.js
View
@@ -1,10 +0,0 @@
-module.exports = {
- render: function(req, res, result) {
- res.render("item.jade", {
- locals: {
- title: "Item",
- result: result
- }
- });
- }
-}
5 test/express/layers/valid/views/JsonView.js
View
@@ -1,5 +0,0 @@
-module.exports = {
- render: function(req, res, result) {
- res.send(result);
- }
-};
5 test/express/templates/index.jade
View
@@ -1,5 +0,0 @@
-h1=title
-ul
- - result.forEach(function(item) {
- li=item.name
- - })
1  test/express/templates/item.jade
View
@@ -1 +0,0 @@
-h1=result.name
6 test/express/templates/layout.jade
View
@@ -1,6 +0,0 @@
-!!!5
-html
- head
- title= "Node Layers Test - " + title
- body
- != body
5 testLayers/controllers/AnotherTestController.js
View
@@ -0,0 +1,5 @@
+module.exports = {
+ testControllerFunction: function() {
+ return "Hello"
+ }
+};
5 testLayers/controllers/TestController.js
View
@@ -0,0 +1,5 @@
+module.exports = function(app) {
+ return {
+ testControllerPresent: true
+ }
+};
8 testLayers/services/TestService.js
View
@@ -0,0 +1,8 @@
+module.exports = function(app) {
+ return {
+ testServicePresent: true,
+ testServiceFunction: function() {
+ return "A Test value";
+ }
+ }
+};
Please sign in to comment.
Something went wrong with that request. Please try again.