Permalink
Browse files

readme, test, exmaple, etc

  • Loading branch information...
1 parent fb4fddc commit d77f449e3c09fae678c8571d0ca3d365d2c27121 @jwerle committed Dec 31, 2012
Showing with 186 additions and 2 deletions.
  1. +2 −0 .gitignore
  2. +1 −0 .npmignore
  3. +4 −0 .travis.yml
  4. +19 −0 Makefile
  5. +50 −0 README.md
  6. +6 −0 exmaples/index.js
  7. +3 −0 exmaples/things/Thing.js
  8. +1 −1 lib/Loader.js
  9. +54 −0 lib/utils.js
  10. +4 −1 package.json
  11. +31 −0 test/loaderTest.js
  12. +5 −0 test/module/module1.js
  13. +3 −0 test/module/module2.js
  14. +3 −0 test/module/module3.json
View
@@ -0,0 +1,2 @@
+node_modules/
+npm-debug.log
View
@@ -0,0 +1 @@
+node_modules/
View
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+ - 0.8
+ - 0.6
View
@@ -0,0 +1,19 @@
+#
+#
+#
+NAME = "node-auto-loader"
+
+all: clean install test
+
+test: ;@node ./test/loaderTest.js
+
+install: ;@echo "Installing ${NAME}....."; \
+ npm install
+
+update: ;@echo "Updating ${NAME}....."; \
+ git pull --rebase; \
+ npm install
+
+clean: ;rm -rf node_modules
+
+.PHONY: test install update clean
View
@@ -0,0 +1,50 @@
+node-auto-loader
+===============
+[![Build Status](https://travis-ci.org/jwerle/node-auto-loader.png?branch=master)](https://travis-ci.org/jwerle/node-auto-loader)
+
+A simple auto loader for nodejs
+
+### Install
+```
+$ sudo npm install auto-loader
+```
+
+### Usage
+You can use the loader by simply passing it a directory path. Assume you have a directory structure like this:
+```
+```
+
+You could then load this module structure like this:
+```js
+var loader, Loader, things, thing
+
+Loader = require('auto-loader').Loader
+loader = new Loader(__dirname + '/things');
+things = loader.load().things;
+thing = new things.Thing("db thing");
+```
+
+### Issues
+Found a bug?
+[Email](joseph.werle@gmail.com) or [submit](https://github.com/jwerle/node-auto-loader/issues) all issues
+
+Copyright and license
+---------------------
+
+Copyright 2012
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this work except in compliance with the License.
+You may obtain a copy of the License in the LICENSE file, or at:
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+- - -
+node-auto-loader copyright 2012
+moovatom - joseph.werle@gmail.com
View
@@ -0,0 +1,6 @@
+var loader, Loader, things, thing
+
+Loader = require('../').Loader
+loader = new Loader(__dirname + '/things');
+things = loader.load().things;
+thing = new things.Thing("db thing");
@@ -0,0 +1,3 @@
+module.exports = function Thing(thing){
+ this.thing = thing;
+}
View
@@ -1,7 +1,7 @@
var utils = require('utilities')
, fs = require('fs')
, path = require('path')
- , stat = require('./stat')
+ , stat = require('./utils').stat
var loader = {};
View
@@ -0,0 +1,54 @@
+var fs = require('fs')
+ , utils = require('utilities')
+
+/**
+ @namespace u
+**/
+var u = {};
+
+u.stat = function stat() {
+ try {
+ return fs.statSync.apply(fs, arguments);
+ }
+ catch(e) {
+ return false;
+ }
+}
+
+u.inherit = function inherit() {
+ var i
+ , args = [].splice.call(arguments, 0)
+ , Heir
+ , Inherited
+
+ if (args.length > 2) {
+ Heir = args.pop();
+
+ for (i = 0; i < args.length; i++) {
+ Heir = inherit(args[i], Heir);
+ }
+ }
+ else {
+ Inherited = args.shift();
+ Heir = args.shift();
+ Heir = utils.mixin(Heir, Inherited);
+ Heir.prototype = Inherited.prototype;
+ Heir.prototype.constructor = Heir;
+
+ Heir.super = Heir.prototype.super = function() {
+ var args = [].splice.call(arguments, 0)
+ , heir = args.shift();
+
+
+ if (typeof heir === 'object') {
+ Inherited.apply(heir, args);
+ }
+ else {
+ return Inherited.call(this);
+ }
+ };
+ }
+
+ return Heir;
+};
+module.exports = u;
View
@@ -1,6 +1,6 @@
{
"name": "auto-loader",
- "version": "0.2.3",
+ "version": "0.0.1",
"description": "",
"keywords": [
"node",
@@ -10,6 +10,9 @@
"scripts" : {
"test" : "make test"
},
+ "dependencies": {
+ "utilities" : "0.0.x"
+ },
"repository": {
"type": "git",
"url": "git://github.com/jwerle/node-auto-loader.git"
View
@@ -0,0 +1,31 @@
+var path = require('path')
+ , Loader = require('../lib/Loader').Loader
+ , directory = path.join(__dirname, 'module')
+ , assert = require('assert')
+ , loaded
+
+console.log("Auto loading modules from" + __dirname);
+loader = new Loader(directory, ['.js', '.json']);
+
+console.log("Modules using namespace 'module'");
+loaded = loader.load().module;
+
+assert.ok(loaded['module1'], "Module1 not loaded");
+assert.ok(loaded['module2'], "Module2 not loaded");
+assert.ok(loaded['module3'], "Module3 not loaded");
+
+assert.ok(typeof loaded['module1'] === 'object' &&
+ typeof loaded['module1'].func === 'function',
+ "Module1 was not loaded properly, expecting module1.func to be a function");
+console.log("module1", loaded['module1']);
+
+assert.ok(typeof loaded['module2'] === 'function' &&
+ "Module2 was not loaded properly, expecting module2 to be a function");
+console.log("module2", loaded['module2']);
+
+assert.ok(typeof loaded['module3'] === 'object' &&
+ typeof loaded['module3'].property === 'string',
+ "Module3 was not loaded properly, expecting module3 to be an object");
+console.log("module3", loaded['module3']);
+
+console.log("Test all good")
@@ -0,0 +1,5 @@
+module.exports = {
+ func : function(){
+ return "Test function for module1";
+ }
+};
@@ -0,0 +1,3 @@
+module.exports = function(){
+ return "Module2 is a function";
+};
@@ -0,0 +1,3 @@
+{
+ "property" : "Single property on a JSON document for module3"
+}

0 comments on commit d77f449

Please sign in to comment.