Permalink
Browse files

refactored code, use jQuery extend, remove globalKey option, update deps

  • Loading branch information...
mgutz committed Jun 8, 2012
1 parent 7ec34eb commit 7be10ae66fa96152e5019eac38495a8844804f04
View
@@ -18,3 +18,4 @@ pids
logs
result
!.gitignore
+node_modules
View
@@ -0,0 +1,23 @@
+PATH=node-modules/mocha/bin:$PATH
+PATH=node-modules/coffee-script/bin:$PATH
+
+#. Run tests
+function test {
+ compile
+ mocha test/*Test.js
+}
+
+
+#. Compiles sources
+function compile {
+ invoke clean
+ coffee -c -o . src
+}
+
+
+#. Cleans output files
+function clean {
+ rm -rf test
+ rm -rf lib
+ rm index.js
+}
View
@@ -1,27 +0,0 @@
-ROOT_DIR ?= $(realpath .)
-SRC_DIR=src
-BUILD_DIR=$(ROOT_DIR)
-
-# compute coffee dependencies
-COFFEE := $(shell find $(SRC_DIR) -name '*.coffee')
-GEN_JS = $(COFFEE:$(SRC_DIR)/%.coffee=$(BUILD_DIR)/%.js)
-
-.PHONY: all clean
-
-all: generate
-
-generate: $(GEN_JS)
-
-test: clean generate
- @expresso test/*.test.js
-
-clean:
- @rm -f $(GEN_JS)
-
-$(BUILD_DIR)/%.js: $(SRC_DIR)/%.coffee
- @mkdir -p $(dir $@)
- @cat res/GENERATED_JS_HEADER > $@
- @echo // Original file: $< >> $@
- @coffee -b -p -c $< >> $@
-
-# vim: noexpandtab ts=4 :
View
111 README.md
@@ -6,115 +6,94 @@ Simple, hierarchical environment-based app settings.
npm install settings
-## Usage
+## Usage
-Configuration file `config/environment.js`
+Configuration file `config.js`
- exports.common = {
- storage: {
- host: 'localhost',
- database: 'server_dev',
- user: 'qirogami_user',
- password: 'password'
- }
- };
-
- // Rest of environments are deep merged over `common`.
-
- exports.development = {};
+ module.exports = {
+ common: {
+ storage: {
+ host: 'localhost',
+ database: 'server_dev',
+ user: 'qirogami_user',
+ password: 'password'
+ }
+ };
- exports.test = {
- storage: {
- database: 'server_test',
- password: 'foo'
- }
- };
+ // Rest of environments are deep merged over `common`.
- exports.production = {
+ development: {};
+ test: {
+ storage: {
+ database: 'server_test',
+ password: 'foo'
+ }
+ };
+ production: {
storage: {
- password: 'secret'
+ password: 'secret'
}
+ };
};
-Application file
+Application file `app.js`
var Settings = require('settings');
- var file = __dirname + '/config/environment.js';
- var settings = new Settings(file).getEnvironment('test');
-
+ var config = new Settings(require('./config'));
// inherited from common
- assert.equal(settings.storage.host, 'localhost');
-
+ assert.equal(config.storage.host, 'localhost');
// specific to test
- assert.equal(settings.storage.password, 'foo');
+ assert.equal(config.storage.password, 'foo');
### Environments
The environment to use is based on (highest precedence first):
-1. `forceEnv` property in settings file
-
- ## config/environment.js
- exports.forceEnv = 'production'
+1. `forceEnv` property in config file
-2. `$NODE_ENV` environment variable
+ ## config/environment.js
+ exports.forceEnv = 'production'
- NODE_ENV=production node app.js
-
-3. Environment argument passed to `Settings#getEnvironment()`
-
- # the environment argument is ignored if either of the above is set
- settings.getEnvironment('production')
-
-### Install Globally
+2. `$NODE_ENV` environment variable
-If `globalKey` option is set, the environment settings are installed
-into global space.
+ NODE_ENV=production node app.js
- var settings = new Settings(file, { globalKey: '$settings' }).
- getEnvironment();
-
- assert.equal($settings.storage.host, 'localhost');
+3. `env` option passed to constructor. `new Settings(file, {env: 'test'})`
### Application Defaults
-Property defaults may be preset in code. These defaults may be overridden
-by the app's external settings.
+Property defaults may be preset in code.
- var settings = new Settings(file, {
- globalKey: '$settings',
+ var settings = new Settings(file, {
defaults: {
framework: {
views: 'app/views'
}
}
- }).getEnvironment();
-
+ });
+ assert.equal(settings.framework.views, 'app/views');
- assert.equal($settings.framework.views, 'app/views');
+## Hacking on the source
-## Generate and Test
+To compile and test
-To generate JavaScript from CoffeeScript
-
- make
-
-To test
-
- npm install expresso
- make test
+ npm install bake-bash -g
+ npm install -d
+ bake test
## Notes
-JavaScript files are generated by Coffee and should not be edited.
+`globalKey` option has been removed. Do this instead
+
+ global.APP = new Settings(file)
## Credits
-[shimondoodkin's node-js-clone-extend](https://github.com/shimondoodkin/nodejs-clone-extend)
+jQuery library for `support/extend.js`
## License
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,8 +0,0 @@
-/*============================================================================
- Copyright(c) 2010 Mario L Gutierrez <mario@mgutz.com>
- MIT Licensed
-
- AUTO-GENERATED. DO NOT EDIT.
-============================================================================*/
-// Original file: src/lib/index.coffee
-module.exports = require('./settings');
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 7be10ae

Please sign in to comment.