Permalink
Browse files

Added configuration API

  • Loading branch information...
1 parent b5b83f2 commit 1196662f5831cd711ca1e814b7800f12de3524b7 @chetan51 committed Nov 20, 2010
Showing with 29 additions and 3 deletions.
  1. +1 −1 example/app.js
  2. +1 −1 example/controllers/home.js
  3. +27 −1 lib/ni.js
View
2 example/app.js
@@ -23,7 +23,7 @@ var Connect = require('connect'),
*/
Ni.setRoot(__dirname); // Tells Ni where to look for the folders
-Ni.config.location = 'world'; // Sets a custom configuration variable to use
+Ni.config('location', "world"); // Sets a custom configuration variable to use
// later, anywhere
Ni.boot(function() { // Boots Ni and loads everything
View
2 example/controllers/home.js
@@ -17,7 +17,7 @@ var Ni = require('../../lib/ni');
var HomeController = function() {
this.index = function(req, res, next) {
- res.ok('Hello ' + Ni.config.location + '!');
+ res.ok('Hello ' + Ni.config('location') + '!');
}
};
View
28 lib/ni.js
@@ -23,11 +23,37 @@ var Ni = function() {
var Ni = this;
/*
- * Registry for custom configuration variables.
+ * Registry for Ni and custom configuration variables.
*/
this.config = {};
+
+ /*
+ * Getter and setter for configuration variables.
+ */
+
+ this.config = function(name, value) {
+
+ if (typeof(name) != 'undefined' && typeof(value) != 'undefined') {
+ // This is a setter
+ this.config[name] = value;
+
+ return true;
+ }
+ else if (typeof(name) != 'undefined') {
+ // This is a getter
+ return this.config[name];
+ }
+ else {
+ return null;
+ }
+
+ }
+ /*
+ * Default configuration settings
+ */
+
this.automatic_views = false;
/*

0 comments on commit 1196662

Please sign in to comment.